示例#1
0
 public bStatusUpdate(bStatus status, bool beatmapUpdate, string statusText, string songChecksum, Mods mods)
 {
     this.status        = status;
     this.beatmapUpdate = beatmapUpdate;
     beatmapChecksum    = songChecksum;
     this.statusText    = statusText;
     currentMods        = mods;
 }
示例#2
0
 // Token: 0x06000E12 RID: 3602
 // RVA: 0x0000EA0A File Offset: 0x0000CC0A
 public Class12(bStatus bStatus_1, bool bool_0, string string_2, string string_3, int int_1, Mods mods_1, PlayModes playModes_1)
 {
     this.bStatus_0 = bStatus_1;
     this.string_0 = string_3;
     this.string_1 = string_2;
     this.mods_0 = mods_1;
     this.playModes_0 = playModes_1;
     this.int_0 = int_1;
 }
示例#3
0
 public bStatusUpdate(bStatus status, bool beatmapUpdate, string statusText, string songChecksum, int beatmapId, Mods mods,
                      PlayModes playMode)
 {
     this.status     = status;
     beatmapChecksum = songChecksum;
     this.statusText = statusText;
     currentMods     = mods;
     this.playMode   = playMode;
     this.beatmapId  = beatmapId;
 }
示例#4
0
 public bUserStatus(bStatus status, string beatmapHash, string beatmap, Mods mods, PlayModes playMode,
                    int beatmapId)
 {
     this.status      = status;
     this.beatmap     = beatmap;
     this.beatmapHash = beatmapHash;
     this.mods        = mods;
     this.playMode    = playMode;
     this.beatmapId   = beatmapId;
 }
示例#5
0
        public bStatusUpdate(Stream s)
        {
            SerializationReader sr = new SerializationReader(s);

            status        = (bStatus)sr.ReadByte();
            beatmapUpdate = sr.ReadBoolean();

            if (beatmapUpdate)
            {
                statusText      = sr.ReadString();
                beatmapChecksum = sr.ReadString();
                currentMods     = (Mods)sr.ReadUInt16();
            }
        }
示例#6
0
 public bStatusUpdate(SerializationReader sr)
 {
     status          = (bStatus)sr.ReadByte();
     statusText      = sr.ReadString();
     beatmapChecksum = sr.ReadString();
     if (OsuCommon.ProtocolVersion > 10)
     {
         currentMods = (Mods)sr.ReadUInt32();
     }
     else
     {
         currentMods = (Mods)sr.ReadInt16();
     }
     playMode  = (PlayModes)Math.Max((byte)0, Math.Min((byte)3, sr.ReadByte()));
     beatmapId = sr.ReadInt32();
 }
示例#7
0
 // Token: 0x06000E13 RID: 3603
 // RVA: 0x0004DAD0 File Offset: 0x0004BCD0
 public Class12(Class32 class32_0)
 {
     this.bStatus_0 = (bStatus)class32_0.ReadByte();
     this.string_1 = class32_0.ReadString();
     this.string_0 = class32_0.ReadString();
     if (Class213.int_0 > 10)
     {
         this.mods_0 = (Mods)class32_0.ReadUInt32();
     }
     else
     {
         this.mods_0 = (Mods)class32_0.ReadInt16();
     }
     this.playModes_0 = (PlayModes)Math.Max(0, Math.Min(3, class32_0.ReadByte()));
     this.int_0 = class32_0.ReadInt32();
 }
示例#8
0
 public bUserStatus(SerializationReader reader)
 {
     status      = (bStatus)reader.ReadByte();
     beatmapHash = reader.ReadString();
     beatmap     = reader.ReadString();
     if (Bancho.Protocol > 10)
     {
         mods = (Mods)reader.ReadUInt32();
     }
     else
     {
         mods = (Mods)reader.ReadInt16();
     }
     playMode  = (PlayModes)Math.Max((byte)0, Math.Min((byte)3, reader.ReadByte()));
     beatmapId = reader.ReadInt32();
 }
示例#9
0
        private static void CheckAfk()
        {
            bool isAfk = GameBase.Time - lastActivityTime > 150000;

            if (isAfk != (bStatus.Afk == Status))
            {
                if (isAfk)
                {
                    StatusBeforeAfk = Status;
                    UpdateStatus(bStatus.Afk);
                }
                else
                {
                    UpdateStatus(StatusBeforeAfk);
                }
            }
        }
示例#10
0
        internal void ReceiveUserStats(bUserStats bus)
        {
#if ARCADE
            //Don't support online play yet.
            return;
#endif

            StatsLoaded = true;

            long   oldRankedScore = RankedScore;
            double oldAccuracy    = Accuracy;
            short  oldPp          = PerformancePoints;
            int    oldRank        = Rank;

            long addedScore = 0;
            int  i          = 0;
            while (addedScore + toNextLevel[i] < bus.totalScore)
            {
                addedScore += toNextLevel[i];
                i++;
            }

            Level = i + 1 + (float)(bus.totalScore - addedScore) / toNextLevel[i];

            RankedScore       = bus.rankedScore;
            Accuracy          = Math.Round(bus.accuracy * 100, 2);
            PlayCount         = bus.playcount;
            PerformancePoints = bus.performance;
            Rank = bus.rank;

            bool playModeChanged = PlayMode != bus.status.playMode;
            PlayMode = bus.status.playMode;

            if (Sprites != null && !firstReceived && (!extended || spriteBackground.IsVisible) && !playModeChanged)
            {
                if (RankedScore != oldRankedScore)
                {
                    bool  increase = oldRankedScore < RankedScore;
                    pText p        =
                        new pText(
                            (increase ? @"+" : @"") +
                            (RankedScore - oldRankedScore).ToString(@"0,0", GameBase.nfi), 10,
                            spriteInfo.Position + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                            Vector2.Zero, 0.98F, false,
                            Color.YellowGreen, true);
                    p.AggressiveCleanup = true;
                    p.Tag = this;
                    p.MoveTo(spriteInfo.Position + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                             EasingTypes.Out);
                    p.FadeOut(6000);
                    spriteManager.Add(p);
                    statUpdateSprite = p;
                }
                if (Accuracy != oldAccuracy)
                {
                    bool  increase = oldAccuracy < Accuracy;
                    pText p        =
                        new pText(
                            "\n" + (increase ? @"+" : string.Empty) +
                            String.Format(@"{0:n}%", Math.Round(Accuracy - oldAccuracy, 2)), 10,
                            spriteInfo.Position + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                            Vector2.Zero, 0.98F, false,
                            (increase ? Color.YellowGreen : Color.OrangeRed), true);
                    p.AggressiveCleanup = true;
                    p.MoveTo(spriteInfo.Position + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                             EasingTypes.Out);
                    p.Tag = this;
                    p.FadeOut(6000);
                    spriteManager.Add(p);
                    statUpdateSprite = p;
                }
                if (Rank != oldRank)
                {
                    bool  increase = oldRank > Rank;
                    pText p        =
                        new pText((increase ? @"+" : string.Empty) + (-Rank + oldRank), 30,
                                  spriteRank.Position, Vector2.Zero, 0.976F, true,
                                  Color.White, false);
                    p.AggressiveCleanup = true;
                    p.Origin            = Origins.TopRight;
                    p.MoveToRelative(new Vector2(0, -19), 1000, EasingTypes.Out);
                    p.Tag = this;
                    p.FadeOut(4000);
                    spriteManager.Add(p);
                    statUpdateSprite = p;
                }
            }

            BeatmapName            = bus.status.statusText;
            BeatmapId              = bus.status.beatmapId;
            CurrentBeatmapChecksum = bus.status.beatmapChecksum;
            CurrentMods            = bus.status.currentMods;
            Status = bus.status.status;

            if (modeStatus != null && (modeStatus.Texture == null || playModeChanged))
            {
                modeStatus.Texture = getModeTexture();
            }

            string beatmapName = string.Empty;

            switch (bus.status.status)
            {
            case bStatus.Playing:
            case bStatus.Paused:
                backgroundColour = new Color(140, 160, 160);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Editing:
                backgroundColour = new Color(160, 60, 60);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Modding:
                backgroundColour = new Color(60, 160, 60);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Watching:
                backgroundColour = new Color(60, 60, 160);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Testing:
                backgroundColour = new Color(160, 60, 160);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Multiplayer:
            case bStatus.Lobby:
                backgroundColour = new Color(164, 108, 28);
                break;

            case bStatus.Multiplaying:
                backgroundColour = new Color(221, 190, 0);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Submitting:
                backgroundColour = new Color(139, 238, 180);
                beatmapName      = @" " + BeatmapName;
                break;

            case bStatus.Afk:
                backgroundColour = new Color(10, 10, 10);
                break;

            default:
                backgroundColour = new Color(10, 29, 75);
                break;
            }

            if (!extended)
            {
                backgroundColour = new Color(1, 1, 1);
            }

            string newStatus = string.Format("{1:HH:mm} @ {3}\n{0} {4}", Status,
                                             DateTime.UtcNow.AddHours(Timezone),
                                             (Timezone >= 0 ? @"+" : string.Empty) + Timezone, Location, BeatmapName);
            bool showTemp = newStatus != StatusText;
            StatusText = newStatus;
            if (showTemp)
            {
                ShowStatusTemporarily();
            }

            firstReceived = false;

            UpdateColour();

            UpdateTextFields();

            StatsLoading = false;
        }
示例#11
0
        internal void bancho_StatsReceived(object sender, bUserStats bus)
        {
            try
            {
                StatsLoaded = true;

                long   oldRankedScore = RankedScore;
                double oldAccuracy    = Accuracy;
                int    oldRank        = Rank;

                RankedScore = bus.rankedScore;
                Accuracy    = Math.Round(bus.accuracy * 100, 2);
                Rank        = bus.rank;

                AvatarFilename = bus.avatarFilename;

                if (bus.status.status == bStatus.StatsUpdate)
                {
                    if (Sprites != null && !firstReceived && (!extended || spriteBackground.IsVisible))
                    {
                        if (RankedScore != oldRankedScore)
                        {
                            bool  increase = oldRankedScore < RankedScore;
                            pText p        =
                                new pText(
                                    (increase ? "+" : "") +
                                    (RankedScore - oldRankedScore).ToString("0,0", GameBase.nfi), 10,
                                    spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                                    Vector2.Zero, 0.98F, false,
                                    Color.YellowGreen, true);
                            p.Tag = this;
                            p.MoveTo(spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                                     EasingTypes.In);
                            p.FadeOut(6000);
                            spriteManager.Add(p);
                        }
                        if (Accuracy != oldAccuracy)
                        {
                            bool  increase = oldAccuracy < Accuracy;
                            pText p        =
                                new pText(
                                    "\n" + (increase ? "+" : "") +
                                    String.Format("{0:0.00}%", Math.Round(Accuracy - oldAccuracy, 2)), 10,
                                    spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                                    Vector2.Zero, 0.98F, false,
                                    (increase ? Color.YellowGreen : Color.OrangeRed), true);
                            p.MoveTo(spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                                     EasingTypes.In);
                            p.Tag = this;
                            p.FadeOut(6000);
                            spriteManager.Add(p);
                        }
                        if (Rank != oldRank)
                        {
                            bool  increase = oldRank > Rank;
                            pText p        =
                                new pText((increase ? "+" : "") + (-Rank + oldRank).ToString(), 30,
                                          spriteRank.CurrentPosition, Vector2.Zero, 0.976F, true,
                                          Color.White, false);
                            p.OriginType = OriginTypes.TopRight;
                            p.MoveToRelative(new Vector2(0, -19), 1000, EasingTypes.In);
                            p.Tag = this;
                            p.FadeOut(4000);
                            spriteManager.Add(p);
                        }
                    }

                    firstReceived = false;
                }
                else
                {
                    beatmapName = bus.status.statusText;
                    string newStatus =
                        string.Format("{1:HH:mm} (GMT{2}) @ {3}\n{0} {4}", bus.status.status,
                                      DateTime.UtcNow.AddHours(bus.timezone),
                                      (bus.timezone >= 0 ? "+" : "") + bus.timezone, bus.location, beatmapName);
                    if (StatusText != newStatus)
                    {
                        StatusText = newStatus;

                        if (spriteStatus != null)
                        {
                            spriteStatus.Text = StatusText;
                            ShowStatusTemporarily();
                        }
                    }

                    CurrentBeatmapChecksum = bus.status.beatmapChecksum;
                    CurrentMods            = bus.status.currentMods;
                    Status = bus.status.status;

                    switch (bus.status.status)
                    {
                    case bStatus.Playing:
                        backgroundColour = new Color(140, 160, 160);
                        break;

                    case bStatus.Editing:
                        backgroundColour = new Color(160, 60, 60);
                        break;

                    case bStatus.Modding:
                        backgroundColour = new Color(60, 160, 60);
                        break;

                    case bStatus.Watching:
                        backgroundColour = new Color(60, 60, 160);
                        break;

                    case bStatus.Testing:
                        backgroundColour = new Color(160, 60, 160);
                        break;

                    default:
                        backgroundColour = new Color(10, 29, 75);
                        break;
                    }
                }

                PlayCount = bus.playcount;

                UpdateColour();

/*                if (bus.status.status == bStatus.Playing)
 *                  if (StreamingManager.CurrentlySpectating == this)
 *                      StreamingManager.HandleSongChange(true);*/


                if (Path.GetExtension(AvatarFilename) == ".gif")
                {
                    AvatarFilename = "";
                }

                InfoText =
                    string.Format(GameBase.nfi, "Score:{0:0,0}\nAccuracy:{1:0.00}%\nPlay Count: {2}", RankedScore,
                                  Accuracy, bus.playcount);
                RankText = "#" + Rank;

                if (Sprites != null)
                {
                    spriteInfo.Text = InfoText;
                    spriteName.Text = Name;
                    spriteRank.Text = RankText;
                }

                StatsLoading = false;

                if (StatsUpdate != null)
                {
                    StatsUpdate(this, null);
                }

                CheckAvatar();
            }
            catch (Exception)
            {
                if (spriteInfo != null)
                {
                    spriteInfo.Text = "An error occurred.";
                }
            }
        }
示例#12
0
        internal void bancho_StatsReceived(object sender, bUserStats bus)
        {
            try
            {
                StatsLoaded = true;

                if (bus.completeness > Completeness.StatusOnly)
                {
                    long   oldRankedScore = RankedScore;
                    double oldAccuracy    = Accuracy;
                    int    oldRank        = Rank;

                    long addedScore = 0;
                    int  i          = 0;
                    while (addedScore + toNextLevel[i] < bus.totalScore)
                    {
                        addedScore += toNextLevel[i];
                        i++;
                    }

                    Level = i + 1 + (float)(bus.totalScore - addedScore) / toNextLevel[i + 1];

                    RankedScore = bus.rankedScore;
                    Accuracy    = Math.Round(bus.accuracy * 100, 2);
                    PlayCount   = bus.playcount;
                    Rank        = bus.rank;

                    if (bus.avatarFilename != null)
                    {
                        AvatarFilename = bus.avatarFilename;
                    }

                    if (Sprites != null && !firstReceived && (!extended || spriteBackground.IsVisible))
                    {
                        if (RankedScore != oldRankedScore)
                        {
                            bool  increase = oldRankedScore < RankedScore;
                            pText p        =
                                new pText(
                                    (increase ? "+" : "") +
                                    (RankedScore - oldRankedScore).ToString("0,0", GameBase.nfi), 10,
                                    spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                                    Vector2.Zero, 0.98F, false,
                                    Color.YellowGreen, true);
                            p.Tag = this;
                            p.MoveTo(spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                                     EasingTypes.In);
                            p.FadeOut(6000);
                            spriteManager.Add(p);
                        }
                        if (Accuracy != oldAccuracy)
                        {
                            bool  increase = oldAccuracy < Accuracy;
                            pText p        =
                                new pText(
                                    "\n" + (increase ? "+" : "") +
                                    String.Format("{0:0.00}%", Math.Round(Accuracy - oldAccuracy, 2)), 10,
                                    spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X, 0) / 2,
                                    Vector2.Zero, 0.98F, false,
                                    (increase ? Color.YellowGreen : Color.OrangeRed), true);
                            p.MoveTo(spriteInfo.CurrentPosition + new Vector2(spriteInfo.MeasureText().X + 2, 0), 1000,
                                     EasingTypes.In);
                            p.Tag = this;
                            p.FadeOut(6000);
                            spriteManager.Add(p);
                        }
                        if (Rank != oldRank)
                        {
                            bool  increase = oldRank > Rank;
                            pText p        =
                                new pText((increase ? "+" : "") + (-Rank + oldRank), 30,
                                          spriteRank.CurrentPosition, Vector2.Zero, 0.976F, true,
                                          Color.White, false);
                            p.OriginType = OriginTypes.TopRight;
                            p.MoveToRelative(new Vector2(0, -19), 1000, EasingTypes.In);
                            p.Tag = this;
                            p.FadeOut(4000);
                            spriteManager.Add(p);
                        }
                    }
                }

                if (bus.completeness == Completeness.Full)
                {
                    Name           = bus.username;
                    Timezone       = bus.timezone;
                    Location       = bus.location;
                    AvatarFilename = bus.avatarFilename;
                    if (Path.GetExtension(AvatarFilename) == ".gif")
                    {
                        AvatarFilename = "";
                    }
                    CheckAvatar();
                }

                if (bus.status.beatmapUpdate)
                {
                    BeatmapName            = bus.status.statusText;
                    CurrentBeatmapChecksum = bus.status.beatmapChecksum;
                    CurrentMods            = bus.status.currentMods;
                }
                else
                {
                    BeatmapName            = "";
                    CurrentBeatmapChecksum = "";
                }

                Status = bus.status.status;

                string newStatus =
                    string.Format("{1:HH:mm} (GMT{2}) @ {3}\n{0} {4}", Status,
                                  DateTime.UtcNow.AddHours(Timezone),
                                  (Timezone >= 0 ? "+" : "") + Timezone, Location, BeatmapName);
                bool showTemp = newStatus != StatusText;
                StatusText = newStatus;
                if (showTemp)
                {
                    ShowStatusTemporarily();
                }

                switch (bus.status.status)
                {
                case bStatus.Playing:
                    backgroundColour = new Color(140, 160, 160);
                    break;

                case bStatus.Editing:
                    backgroundColour = new Color(160, 60, 60);
                    break;

                case bStatus.Modding:
                    backgroundColour = new Color(60, 160, 60);
                    break;

                case bStatus.Watching:
                    backgroundColour = new Color(60, 60, 160);
                    break;

                case bStatus.Testing:
                    backgroundColour = new Color(160, 60, 160);
                    break;

                case bStatus.Multiplayer:
                case bStatus.Lobby:
                    backgroundColour = new Color(164, 108, 28);
                    break;

                case bStatus.Multiplaying:
                    backgroundColour = new Color(232, 221, 39);
                    break;

                case bStatus.Submitting:
                    backgroundColour = new Color(139, 238, 180);
                    break;

                case bStatus.Afk:
                    backgroundColour = new Color(10, 10, 10);
                    break;

                default:
                    backgroundColour = new Color(10, 29, 75);
                    break;
                }

                firstReceived = false;

                UpdateColour();

                InfoText =
                    string.Format(GameBase.nfi, "Score:{0:0,0}\nAccuracy:{1:0.00}%\n" + (extended ? "Play Count: {2} (Lv{3:0})" : "Lv{3}"), RankedScore,
                                  Accuracy, PlayCount, (int)Level);
                RankText = "#" + Rank;

                if (Sprites != null)
                {
                    spriteInfo.Text = InfoText;
                    spriteName.Text = Name;
                    if (spriteStatus != null)
                    {
                        spriteStatus.Text = StatusText;
                    }
                    if (levelBarForeground != null)
                    {
                        levelBarForeground.DrawWidth = (int)(198 * (Level - (int)Level));
                    }
                    spriteRank.Text = RankText;
                }

                StatsLoading = false;

                if (StatsUpdate != null)
                {
                    StatsUpdate(this, null);
                }
            }
            catch (Exception)
            {
                if (spriteInfo != null)
                {
                    spriteInfo.Text = "An error occurred.";
                }
            }
        }
示例#13
0
        internal static void UpdateStatus(bStatus status)
        {
            string text     = "";
            string checksum = "";
            Mods   mods     = Mods.None;

            bool sendSong = false;

            if (status == bStatus.Unknown)
            {
                if (BeatmapManager.Current != null)
                {
                    text = (InputManager.ReplayMode
                                ? (StreamingManager.CurrentlySpectating != null
                                       ? StreamingManager.CurrentlySpectating.Name
                                       : InputManager.ReplayScore.playerName) + " play "
                                : "") + BeatmapManager.Current.DisplayTitle;
                    checksum = BeatmapManager.Current.BeatmapChecksum;
                    mods     = ModManager.ModStatus;
                }

                status = bStatus.Idle;

                switch (GameBase.Mode)
                {
                case Modes.Edit:
                    if (BeatmapManager.Current.Creator == ConfigManager.sUsername ||
                        BeatmapManager.Current.Creator.Length == 0)
                    {
                        status = bStatus.Editing;
                    }
                    else
                    {
                        status = bStatus.Modding;
                    }
                    sendSong = true;
                    break;

                case Modes.Play:
                    if (Player.Paused)
                    {
                        status = bStatus.Paused;
                    }
                    else if (InputManager.ReplayMode)
                    {
                        status = bStatus.Watching;
                    }
                    else if (GameBase.TestMode)
                    {
                        status = bStatus.Testing;
                    }
                    else if (Lobby.Status == LobbyStatus.Play)
                    {
                        status = bStatus.Multiplaying;
                    }
                    else
                    {
                        status = bStatus.Playing;
                    }
                    sendSong = true;
                    break;

                case Modes.Lobby:
                case Modes.MatchSetup:
                case Modes.SelectMulti:
                    status = bStatus.Multiplayer;
                    break;

                default:
                    text     = "";
                    checksum = "";
                    break;
                }
            }

            if (status == Status)
            {
                return;
            }
            Status = status;

            SendRequest(RequestType.Osu_SendUserStatus,
                        new bStatusUpdate(Status, sendSong, text, checksum, mods));
        }
示例#14
0
        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);
            }
        }