コード例 #1
0
        internal static void LeaveLobby(bool changeMode)
        {
            if (!Joined)
            {
                return;
            }
            Joined = false;

            Matches.Clear();
            BanchoClient.SendRequest(RequestType.Osu_LobbyPart, null);

            if (Status == LobbyStatus.Idle)
            {
                ChatEngine.RemoveChannel(@"#lobby");

                if (!chatOpenOnStart)
                {
                    ChatEngine.HideChat();
                }

                Status = LobbyStatus.NotJoined;
            }

            if (changeMode)
            {
                AudioEngine.PlaySamplePositional(@"menuback");
                Status = LobbyStatus.NotJoined;
                GameBase.ChangeMode(OsuModes.Menu);
            }
        }
コード例 #2
0
        void pb_OnClick(pText p, pText pname)
        {
            string attemptJoin = p.Tag.ToString();

            Channel c = ChatEngine.channels.Find(s => s.Name == attemptJoin);

            if (c == null)
            {
                NotificationManager.ShowMessageMassive(LocalisationManager.GetString(OsuString.ChannelListDialog_CantRejoinThisChannel), 1500);
                return;
            }

            if (InputManager.rightButtonLast == ButtonState.Pressed)
            {
                if (!c.Joined || !c.Closeable)
                {
                    return;
                }
                ChatEngine.RemoveChannel(c);
                NotificationManager.ShowMessageMassive(string.Format(LocalisationManager.GetString(OsuString.ChannelListDialog_Left), c.Name), 1500);
                p.FadeColour(SkinManager.NEW_SKIN_COLOUR_SECONDARY, 300);
                pname.FadeColour(SkinManager.NEW_SKIN_COLOUR_SECONDARY, 300);
            }
            else
            {
                if (!c.Joined)
                {
                    Channel chan = null;

                    try
                    {
                        chan = ChatEngine.AddChannel(attemptJoin, false, true);
                        if (chan == null)
                        {
                            NotificationManager.ShowMessageMassive(string.Format(LocalisationManager.GetString(OsuString.ChannelListDialog_JoiningTooFast), attemptJoin), 1500);
                            return;
                        }

                        ChatEngine.channelTabs.SetSelected(chan);
                        NotificationManager.ShowMessageMassive(string.Format(LocalisationManager.GetString(OsuString.ChannelListDialog_Joined), chan.Name), 1500);
                        p.FadeColour(SkinManager.NEW_SKIN_COLOUR_MAIN, 300);
                        pname.FadeColour(SkinManager.NEW_SKIN_COLOUR_MAIN, 300);
                    }
                    catch
                    {
                    }
                }
                else
                {
                    NotificationManager.ShowMessageMassive(LocalisationManager.GetString(OsuString.ChannelListDialog_AlreadyJoined), 1500);
                }
            }

            Update();
        }
コード例 #3
0
        public static void StopSpectating(bool ExitPlayMode = true)
        {
            if (GameBase.TourneySpectatorName != null)
            {
                GameBase.TourneySpectatorName.Text = string.Empty;
            }

            if (ExitPlayMode && (GameBase.Mode == OsuModes.Play || (GameBase.Mode != OsuModes.Menu && GameBase.Tournament)))
            {
                InputManager.ReplayMode = false;
                if (CurrentlySpectating == null)
                {
                    GameBase.ChangeMode(OsuModes.SelectPlay, true);
                }
                else
                {
                    GameBase.ChangeMode(OsuModes.Menu, true);
                }
            }

            if (CurrentlySpectating != null)
            {
                lock (LockReplayScore)
                {
                    BanchoClient.SendRequest(RequestType.Osu_StopSpectating, null);
                    NotificationManager.ShowMessage("Stopped spectating " + CurrentlySpectating.Name, Color.Tomato, 3000);
                    CurrentlySpectating          = null;
                    InputManager.ReplayStreaming = false;
                }
                if (ChatEngine.channels.Exists(s => s.Name == "#spectator"))
                {
                    ChatEngine.RemoveChannel(ChatEngine.channels.Find(s => s.Name == "#spectator"), false, true);
                }

                InputManager.ReplayStartTime = 0;
            }

            FellowSpectators.Clear();
            ReplayQueue.Clear();
            GameBase.SetTitle();
        }
コード例 #4
0
ファイル: BanchoClient.cs プロジェクト: Crystallinqq/osu-2005
        private static void Run()
        {
            Connect();
            while (true)
            {
                if (GameBase.Time - lastPingTime > pingTimeout)
                {
                    Connect();
                    Thread.Sleep(20);
                    continue;
                }

                if (client != null && client.Connected)
                {
                    try
                    {
                        //Send any waiting requests.
                        if (Requests.Count > 0 && stream.CanWrite && Authenticated)
                        {
                            Requests.Dequeue().Send(stream);
                            sendSequence = (sendSequence + 1) % ushort.MaxValue;
                        }

                        while (Connected && stream != null && stream.DataAvailable)
                        {
                            lastPingTime = GameBase.Time;

                            readBytes += stream.Read(readByteArray, readBytes, readByteArray.Length - readBytes);

                            //Read header data
                            if (readBytes == readByteArray.Length && readingHeader)
                            {
                                readType    = (RequestType)BitConverter.ToUInt16(readByteArray, 0);
                                compression = readByteArray[2] == 1;
                                uint length = BitConverter.ToUInt32(readByteArray, 3);

                                Console.WriteLine("R" + length + ": " + readType);

                                ResetReadArray(false);
                                readByteArray = new byte[length];
                            }

                            //Read payload data
                            if (readBytes != readByteArray.Length)
                            {
                                continue;
                            }

                            switch (readType)
                            {
                            /* CONNECTION MANAGEMENT */

                            case RequestType.Bancho_LoginReply:
                                GameBase.User.Id = new bInt(readStream).number;
                                switch (GameBase.User.Id)
                                {
                                case -1:
                                    GameBase.ShowMessage(
                                        "Bancho authentication failed.  Please check your username/password by clicking the user pane on the main menu.",
                                        Color.Red, 4400);
                                    Authenticated = false;
                                    Disconnect(true);
                                    if (LoginResult != null)
                                    {
                                        LoginResult(false, null);
                                    }
                                    break;

                                case -2:
                                    GameBase.ShowMessage(
                                        "Bancho connection failed: Version mismatch",
                                        Color.Red, 4400);
                                    GameBase.CheckForUpdates();
                                    Authenticated = false;
                                    Disconnect(true);
                                    return;

                                default:
                                    Console.WriteLine("login success userid:" + GameBase.User.Id);

                                    ChatEngine.BanchoConnected();
                                    GameBase.ShowMessage("Welcome to osu!Bancho.", Color.SlateBlue, 4400);

                                    Status = bStatus.Idle;
                                    UpdateStatus();

                                    Authenticated = true;
                                    if (OnConnect != null)
                                    {
                                        OnConnect();
                                    }
                                    if (LoginResult != null)
                                    {
                                        LoginResult(true, null);
                                    }
                                    break;
                                }
                                break;

                            case RequestType.Bancho_Ping:
                                SendRequest(RequestType.Osu_Pong, null);
                                break;

                            case RequestType.Bancho_VersionUpdate:
                                GameBase.CheckForUpdates();
                                break;

                            /* CHAT and MESSAGING */

                            case RequestType.Bancho_SendIrcMessage:
                                ChatEngine.HandleMessage(new bMessage(readStream), false);
                                break;

                            case RequestType.Bancho_HandleIrcChangeUsername:
                                string message = new bString(readStream).text;
                                string oldname = message.Substring(0, message.IndexOf(">>>>"));
                                string newname = message.Remove(0, message.IndexOf(">>>>") + 4);
                                ChatEngine.HandleChangeUsername(oldname, newname);
                                break;

                            case RequestType.Bancho_HandleIrcQuit:
                                ChatEngine.HandleQuit("#osu", new bString(readStream).text);
                                break;

                            case RequestType.Bancho_HandleIrcJoin:
                                ChatEngine.HandleJoin("#osu", new bString(readStream).text);
                                break;

                            case RequestType.Bancho_HandleOsuQuit:
                                ChatEngine.HandleUserQuit(new bInt(readStream).number);
                                break;

                            /* STATISTICS */

                            case RequestType.Bancho_HandleOsuUpdate:
                                if (readStream == null)
                                {
                                    break;
                                }
                                bUserStats stats = new bUserStats(readStream);
                                ChatEngine.HandleUserUpdate(stats);
                                if (stats.userId == GameBase.User.Id)
                                {
                                    if (stats.username != null)
                                    {
                                        ConfigManager.sUsername = stats.username;
                                    }
                                    GameBase.User.bancho_StatsReceived(null, stats);
                                }
                                break;

                            /* SPECTATING */
                            case RequestType.Bancho_FellowSpectatorJoined:
                                lock (StreamingManager.Spectators)
                                {
                                    User u = GetUserById(new bInt(readStream).number);
                                    StreamingManager.HasSpectators = true;
                                    if (!StreamingManager.FellowSpectators.Contains(u))
                                    {
                                        StreamingManager.FellowSpectators.Add(u);
                                    }
                                    StreamingManager.FellowSpectators.Sort();
                                }
                                break;

                            case RequestType.Bancho_FellowSpectatorLeft:
                                lock (StreamingManager.Spectators)
                                {
                                    User u = GetUserById(new bInt(readStream).number);
                                    StreamingManager.FellowSpectators.Remove(u);
                                    if (StreamingManager.Spectators.Count == 0)
                                    {
                                        StreamingManager.HasSpectators = false;
                                    }
                                }
                                break;

                            case RequestType.Bancho_SpectatorJoined:
                                //Start sending spectator frames.
                                lock (StreamingManager.Spectators)
                                {
                                    User u = GetUserById(new bInt(readStream).number);
                                    u.CantSpectate = false;
                                    if (!StreamingManager.Spectators.Contains(u))
                                    {
                                        StreamingManager.Spectators.Add(u);
                                    }
                                    StreamingManager.HasSpectators = true;
                                    StreamingManager.Spectators.Sort();
                                }
                                break;

                            case RequestType.Bancho_SpectatorCantSpectate:
                                GetUserById(new bInt(readStream).number).CantSpectate = true;
                                break;

                            case RequestType.Bancho_SpectatorLeft:
                                //Stop sending spectator frames.
                                lock (StreamingManager.Spectators)
                                {
                                    User u = GetUserById(new bInt(readStream).number);
                                    u.CantSpectate = false;
                                    StreamingManager.Spectators.Remove(u);
                                    if (StreamingManager.Spectators.Count == 0)
                                    {
                                        StreamingManager.HasSpectators = false;
                                    }
                                }
                                break;

                            case RequestType.Bancho_SpectateFrames:
                                StreamingManager.HandleFrames(new bReplayFrameBundle(readStream));
                                //Received some spectator frames.
                                break;

                            case RequestType.Bancho_GetAttention:
                                ChatEngine.PendingShow = true;
                                break;

                            case RequestType.Bancho_Announce:
                                GameBase.ShowMessage(new bString(readStream).text.Replace("\\n", "\n"), Color.DarkMagenta, 10000);
                                break;

                            case RequestType.Bancho_MatchUpdate:
                            case RequestType.Bancho_MatchNew:
                                Lobby.IncomingMatch(new bMatch(readStream));
                                break;

                            case RequestType.Bancho_MatchStart:
                                MatchSetup.MatchStart(new bMatch(readStream));
                                break;

                            case RequestType.Bancho_MatchDisband:
                                Lobby.DisbandedMatch(new bInt(readStream).number);
                                break;

                            case RequestType.Bancho_LobbyJoin:
                            case RequestType.Bancho_LobbyPart:
                                User f = GetUserById(new bInt(readStream).number);
                                if (f != null)
                                {
                                    f.InLobby = readType == RequestType.Bancho_LobbyJoin;
                                }
                                Lobby.LobbyUpdatePending = true;
                                break;

                            case RequestType.Bancho_MatchJoinFail:
                                Lobby.OnJoinFail();
                                break;

                            case RequestType.Bancho_MatchJoinSuccess:
                                MatchSetup.Match = new bMatch(readStream);
                                Lobby.OnJoinSuccess();
                                break;

                            case RequestType.Bancho_MatchScoreUpdate:
                                if (GameBase.Mode == Modes.Play && Lobby.Status == LobbyStatus.Play)
                                {
                                    PlayerVs.MatchScoreUpdate(new bScoreFrame(readStream));
                                }
                                break;

                            case RequestType.Bancho_MatchTransferHost:
                                MatchSetup.MatchTransferHost();
                                break;

                            case RequestType.Bancho_MatchAllPlayersLoaded:
                                if (GameBase.Mode == Modes.Play && Lobby.Status == LobbyStatus.Play)
                                {
                                    PlayerVs.AllPlayersLoaded = true;
                                }
                                break;

                            case RequestType.Bancho_MatchPlayerFailed:
                                if (GameBase.Mode == Modes.Play && Lobby.Status == LobbyStatus.Play)
                                {
                                    PlayerVs.MatchPlayerFailed(new bInt(readStream).number);
                                }
                                break;

                            case RequestType.Bancho_MatchComplete:
                                if (GameBase.Mode == Modes.Play && Lobby.Status == LobbyStatus.Play)
                                {
                                    PlayerVs.MatchComplete();
                                }
                                break;

                            case RequestType.Bancho_MatchSkip:
                                if (GameBase.Mode == Modes.Play && Lobby.Status == LobbyStatus.Play)
                                {
                                    Player.QueueSkip();
                                }
                                break;

                            case RequestType.Bancho_Unauthorised:

                                break;

                            case RequestType.Bancho_ChannelJoinSuccess:
                                string  match   = new bString(readStream).text;
                                Channel channel = ChatEngine.channels.Find(ch => ch.name == match);
                                if (channel != null)
                                {
                                    channel.HandleJoinSuccess();
                                }
                                break;

                            case RequestType.Bancho_ChannelAvailable:
                                ChatEngine.AddChannel(new bString(readStream).text, false);
                                break;

                            case RequestType.Bancho_ChannelAvailableAutojoin:
                                ChatEngine.AddChannel(new bString(readStream).text, true);
                                break;

                            case RequestType.Bancho_ChannelRevoked:
                                ChatEngine.RemoveChannel(new bString(readStream).text);
                                break;

                            case RequestType.Bancho_BeatmapInfoReply:
                                BeatmapManager.IncomingBeatmapInfoReply(new bBeatmapInfoReply(readStream));
                                break;
                            }
                            ResetReadArray(true);
                        }
                    }
                    catch (Exception e)
                    {
                        if (firstError)
                        {
                            firstError = false;
                            if (Connected)
                            {
                                StringBuilder report = new StringBuilder();
                                report.AppendLine("----------------------BANCHO--------------------------------");
                                report.AppendLine("Bancho error from " + ConfigManager.sUsername + " at " +
                                                  DateTime.UtcNow.ToString(GameBase.nfi));
                                report.AppendLine();
                                report.AppendLine("Mode: " + GameBase.Mode);
                                report.AppendLine();
                                report.Append(e + "\n");
                                report.AppendLine();
                                report.AppendLine("------------------------------------------------------------");
                                try
                                {
                                    new RequestGeneric(RequestType.Osu_ErrorReport, new bString(report.ToString())).Send
                                        (stream);
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                        FailConnection("An error occurred somewhere in bancho comms.  Reconnecting!", errorRetry);
                        errorRetry = (int)(errorRetry * 1.5);
                    }
                }

                if (Connected)
                {
                    CheckAfk();
                }

                Thread.Sleep(20);
            }
        }