private void Display() { pDialog dialog = new pDialog(null, false); dialog.spriteManager.HandleOverlayInput = true; dialog.ButtonOffset = new Vector2(50, 60); ChatEngine.RequestUserStats(new List <User>() { User }, true); bool isSelf = User.Name == GameBase.User.Name; dialog.Closed += delegate { ActiveProfiles.Remove(this); }; if (User.IsOsu && !isSelf) { if (GameBase.Mode != OsuModes.Edit && (GameBase.Mode != OsuModes.Play || !GameBase.TestMode)) { dialog.AddOption(User == StreamingManager.CurrentlySpectating ? LocalisationManager.GetString(OsuString.UserProfile_StopSpectating) : LocalisationManager.GetString(OsuString.UserProfile_StartSpectating), Color.YellowGreen, delegate { if (Lobby.Status != LobbyStatus.NotJoined) { NotificationManager.ShowMessage( LocalisationManager.GetString(OsuString.UserProfile_CantSpectate)); return; } if (GameBase.Mode == OsuModes.Play && !InputManager.ReplayMode) { NotificationManager.ShowMessage( LocalisationManager.GetString(OsuString.UserProfile_CantSpectate)); return; } if (User.Name == ConfigManager.sUsername || User == StreamingManager.CurrentlySpectating) { StreamingManager.StopSpectating(true); } else { StreamingManager.StartSpectating(User); } }); } } dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_ViewProfile), new Color(58, 110, 165), delegate { GameBase.ProcessStart(User.Id == 0 ? @"https://osu.ppy.sh/wiki/BanchoBot" : String.Format(Urls.USER_PROFILE, User.Id)); }); if (isSelf) { if (GameBase.Mode == OsuModes.Menu && BanchoClient.AllowUserSwitching) { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_SignOut), Color.Orange, delegate { GameBase.Options.PerformLogout(); if (!GameBase.Options.Expanded) { GameBase.ShowLogin(); } }); } dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_ChangeAvatar), Color.Orange, delegate { GameBase.ProcessStart(Urls.USER_SET_AVATAR); }); } else { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_StartChat), Color.MediumPurple, delegate { ChatEngine.StartChat(User); }); if (User.IsOsu) { if (MatchSetup.Match != null) { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_Invitetogame), Color.Yellow, delegate { BanchoClient.SendRequest(new Request(RequestType.Osu_Invite, new bInt(User.Id))); NotificationManager.ShowMessageMassive(string.Format(LocalisationManager.GetString(OsuString.ChatEngine_UserInvited), User.Name)); }); } } dialog.AddOption(User.IsFriend ? LocalisationManager.GetString(OsuString.UserProfile_CancelFriendship) : LocalisationManager.GetString(OsuString.UserProfile_AddFriend), Color.Pink, delegate { ChatEngine.ToggleFriend(User, !User.IsFriend); }); if (ShowExtraOptions && User.Id > 0) { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_ReportUser), Color.Red, delegate { UserReportDialog report = new UserReportDialog(User, ChatEngine.activeChannel); GameBase.ShowDialog(report); }); if (ChatEngine.CheckIgnore(User)) { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_UnignoreUser), Color.Gray, delegate { ChatEngine.UnignoreUser(User); }); } else { dialog.AddOption(LocalisationManager.GetString(OsuString.UserProfile_IgnoreUser), Color.Gray, delegate { ChatEngine.IgnoreUser(User); }); } } } dialog.AddOption(LocalisationManager.GetString(OsuString.General_Close), Color.DarkGray, null); if (DisplayedUser.DrawAt(new Vector2(5, 5), true, 0)) { dialog.spriteManager.Add(DisplayedUser.Sprites); } GameBase.ShowDialog(dialog); /*if (User.Id != 0) * { * GameBase.Scheduler.Add(delegate * { * if (!dialog.IsDisplayed) return; * * if (browser == null) * { * GameBase.OnResolutionChange += GameBase_OnResolutionChange; * browser = new pBrowser(null, Vector2.Zero, new Vector2(220, GameBase.WindowManager.Height - 48 * GameBase.WindowManager.Ratio), 0.911f, Color.White); * browser.Disposable = false; * browser.OnLoaded += delegate * { * browser.FadeIn(500); * browser.MoveToRelative(new Vector2(88, 0), 500, EasingTypes.In); * }; * } * * browser.Transformations.Clear(); * browser.CurrentAlpha = 0; * browser.AlwaysDraw = true; * browser.CurrentPosition = new Vector2(-88, 48); * browser.Load(string.Format(Urls.USER_PROFILE_COMPACT, User.Id)); * * dialog.spriteManager.Add(browser); * }, 1000); * }*/ }
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); } }