private void Callbacks_PlayerChat(object sender, Communication.EventArguments.Callbacks.PlayerChatEventArgs e) { if (e.IsServerMessage) { return; } RunCatchLog(() => { string text = e.Text.ToLower(CultureInfo.InvariantCulture); ServerCommand command = ServerCommand.Parse(e.Text); if (ProRestartCommands.Contains(text) || command.Is(Command.ProRestart)) { if (ConsiderLogin(e.Login, true)) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#MessageStyle]} Your vote for track restart was considered."); SendStatisticsToLogin(e.Login); } return; } if ((ConRestartCommands.Contains(text) || command.Is(Command.ConRestart)) && ConsiderLogin(e.Login, false)) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#MessageStyle]} Your vote against track restart was considered."); SendStatisticsToLogin(e.Login); } }, "Error in PlayerChat Callback.", true); }
private bool CheckForTMXInfoCommand(PlayerChatEventArgs e) { ServerCommand command = ServerCommand.Parse(e.Text); if (command.Is(Command.TMXInfo)) { if (command.PartsWithoutMainCommand.Count > 0) { string trackID = command.PartsWithoutMainCommand[0]; TMXInfo tmxInfo = TMXInfo.Retrieve(trackID); if (tmxInfo != null && !tmxInfo.Erroneous) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}[TMX-Info] Name: {[#HighlightStyle]}{[Name]}{[#MessageStyle]}, Author: {[#HighlightStyle]}{[Author]}{[#MessageStyle]}, Environment: {[#HighlightStyle]}{[Env]}", "Name", tmxInfo.Name, "Author", tmxInfo.Author, "Env", tmxInfo.Environment); } else { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve trackinfo for trackid " + trackID); } } return(true); } return(false); }
private bool CheckForDeleteCheaterCommand(PlayerChatEventArgs args) { if (args.IsServerMessage || args.Text.IsNullOrTimmedEmpty()) { return(false); } ServerCommand command = ServerCommand.Parse(args.Text); if (!command.Is(Command.DeleteCheater) || command.PartsWithoutMainCommand.Count == 0) { return(false); } string login = command.PartsWithoutMainCommand[0]; if (!LoginHasRight(args.Login, true, Command.DeleteCheater)) { return(true); } if (PlayerAdapter.RemoveAllStatsForLogin(login)) { SendFormattedMessageToLogin(args.Login, Settings.CheaterDeletedMessage, "Login", login); DetermineLocalRecords(); OnLocalRecordsDetermined(new List <RankEntry>(LocalRecords)); } else { SendFormattedMessageToLogin(args.Login, Settings.CheaterDeletionFailedMessage, "Login", login); } return(true); }
private bool CheckForSelectUndrivenTracksCommand(PlayerChatEventArgs args) { ServerCommand serverCommand = ServerCommand.Parse(args.Text); if (!serverCommand.Is(Command.SelectUndrivenTracks)) { return(false); } if (!LoginHasRight(args.Login, true, Command.SelectUndrivenTracks)) { return(true); } string targetLogin = args.Login; if (serverCommand.HasFurtherParts) { targetLogin = serverCommand.PartsWithoutMainCommand[0]; } PlayerSettings playerSettings = GetPlayerSettings(targetLogin); if (playerSettings == null) { SendNoPlayerWithLoginMessageToLogin(args.Login, targetLogin); return(true); } SelectUndrivenTracks(args.Login, targetLogin); return(true); }
private void Callbacks_PlayerChat(object sender, Communication.EventArguments.Callbacks.PlayerChatEventArgs e) { RunCatchLog(() => { ServerCommand command = ServerCommand.Parse(e.Text); if (!command.Is(Command.Donate) || command.PartsWithoutMainCommand.Count == 0) { return; } int coppers; if (!int.TryParse(command.PartsWithoutMainCommand[0], NumberStyles.None, CultureInfo.InvariantCulture, out coppers) || coppers <= 0) { return; } if (coppers < Settings.MinDonationValue) { SendFormattedMessageToLogin(e.Login, Settings.DonationToSmallMessage, "Coppers", Settings.MinDonationValue.ToString(CultureInfo.InvariantCulture)); return; } PlayerSettings playerSettings = GetPlayerSettings(e.Login); bool isUnitedAccount = playerSettings.IsUnitedAccount; if (!playerSettings.DetailMode.HasDetailedPlayerInfo()) { DetailedPlayerInfo playerInfo = GetDetailedPlayerInfo(e.Login); if (playerInfo != null) { isUnitedAccount = playerInfo.IsUnitedAccount; } } if (!isUnitedAccount) { SendFormattedMessageToLogin(e.Login, Settings.PlayerHasNoUnitedAccountMessage); return; } GenericResponse <int> billResponse = Context.RPCClient.Methods.SendBill(e.Login, coppers, Settings.DonationHint, Settings.DonationTargetLogin); if (billResponse.Erroneous) { Logger.Warn(string.Format("Error while calling method SendBill: {0}({1})", billResponse.Fault.FaultMessage, billResponse.Fault.FaultCode)); SendFormattedMessageToLogin(e.Login, Settings.DonationErrorMessage, "ErrorMessage", billResponse.Fault.FaultMessage); return; } BillDictionary[billResponse.Value] = new DonationInfo { Login = e.Login, Coppers = coppers }; }, "Error in Callbacks_PlayerChat Method.", true); }
private bool CheckForListLocalLoginsCommand(PlayerChatEventArgs args) { if (args.IsServerMessage || args.Text.IsNullOrTimmedEmpty()) { return(false); } ServerCommand command = ServerCommand.Parse(args.Text); if (!command.Is(Command.GetLocalLogins)) { return(false); } if (!LoginHasRight(args.Login, true, Command.GetLocalLogins)) { return(true); } DetermineLocalRecords(); StringBuilder msg = new StringBuilder("Local logins: "); for (int i = 0; i < LocalRecords.Length; i++) { if (i != 0) { msg.Append(", "); } RankEntry entry = LocalRecords[i]; msg.AppendFormat("{0}. {1}$z[{2}]", i + 1, entry.Nickname, entry.Login); } SendFormattedMessageToLogin(args.Login, msg.ToString()); return(true); }
private bool CheckForLastSeenCommand(PlayerChatEventArgs args) { ServerCommand command = ServerCommand.Parse(args.Text); if (!command.Is(Command.LastSeen)) { return(false); } if (command.PartsWithoutMainCommand.Count == 0) { return(true); } string login = command.PartsWithoutMainCommand[0]; string nickname = GetNickname(login, true); if (GetPlayerSettings(login) != null) { SendFormattedMessageToLogin(args.Login, Settings.PlayerOnServerMessage, "Nickname", nickname); return(true); } Player player = HostPlugin.PlayerAdapter.Deserialize(login); if (player == null) { SendNoPlayerWithLoginMessageToLogin(args.Login, login); return(true); } SendFormattedMessageToLogin(args.Login, Settings.LastSeenMessage, "Nickname", nickname, "LastSeen", TimeZone.CurrentTimeZone.ToUniversalTime(player.LastTimePlayedChanged).ToString("R")); return(true); }
private void HandleCommand(string login, ServerCommand command) { if (command.Is(Command.CreateBattle)) { HandleCreateBattleCommand(login, command); return; } if (command.Is(Command.StartBattle)) { HandleStartBattleCommand(login); return; } if (command.Is(Command.JoinBattle)) { HandleJoinBattleCommand(login, command); return; } if (command.Is(Command.LeaveBattle)) { HandleLeaveBattleCommand(login); return; } if (command.Is(Command.StopBattle)) { HandleStopBattleCommand(login); return; } if (command.Is(Command.ShowBattles)) { HandleShowBattlesCommand(login); return; } }
private void HandleCommand(string login, ServerCommand command) { if (command.Is(Command.Kick)) { HandleKickCommand(login, command); return; } if (command.Is(Command.Warn)) { HandleWarnCommand(login, command); return; } if (command.Is(Command.Ban)) { HandleBanCommand(login, command); return; } if (command.Is(Command.Unban)) { HandleUnBanCommand(login, command); return; } if (command.Is(Command.Blacklist)) { HandleBlackListCommand(login, command); return; } if (command.Is(Command.Unblacklist)) { HandleUnBlackListCommand(login, command); return; } if (command.Is(Command.Ignore)) { HandleIgnoreCommand(login, command); return; } if (command.Is(Command.Unignore)) { HandleUnIgnoreCommand(login, command); return; } if (command.Is(Command.AddGuest)) { HandleAddGuestCommand(login, command); return; } if (command.Is(Command.RemoveGuest)) { HandleRemoveGuestCommand(login, command); return; } if (command.Is(Command.ForceSpectator)) { HandleForceSpectatorCommand(login, command); return; } if (command.Is(Command.WriteTrackList)) { HandleWriteTrackListCommand(login, command); return; } if (command.Is(Command.ReadTrackList)) { HandleReadTrackListCommand(login, command); return; } if (command.Is(Command.RemoveCurrentTrack)) { HandleRemoveTrackCommand(login); return; } if (command.Is(Command.ReadCredentials)) { HandleReadCredentialsCommand(login); return; } if (command.Is(Command.Wisper)) { HandleWisperCommand(login, command); return; } if (command.Is(Command.Help)) { HandleHelpCommand(login, command); return; } }
private bool CheckForTMXAddTrackCommand(PlayerChatEventArgs e) { ServerCommand command = ServerCommand.Parse(e.Text); if (!command.IsAny(Command.AddTrack, Command.InsertTrack)) { return(false); } if (!LoginHasRight(e.Login, true, Command.AddTrack)) { return(true); } if (command.PartsWithoutMainCommand.Count == 0) { return(true); } string trackID = command.PartsWithoutMainCommand[0]; TMXInfo tmxInfo = TMXInfo.Retrieve(trackID); if (tmxInfo == null || tmxInfo.Erroneous) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve trackinfo for trackid " + trackID); return(true); } List <ChallengeListSingleInfo> challenges = GetChallengeList(); if (challenges == null) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve current challenge list."); return(true); } if (challenges.Exists(c => c.FileName.Equals(tmxInfo.GetRelativeFilePath(), StringComparison.InvariantCultureIgnoreCase))) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track is already in tracklist."); return(true); } byte[] trackData = TMXInfo.DownloadTrack(trackID); if (trackData == null) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#ErrorStyle]}Could not retrieve track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID); return(true); } string targetTrackFilePath = tmxInfo.GetRelativeFilePath(); GenericResponse <bool> writeFileResponse = Context.RPCClient.Methods.WriteFile(targetTrackFilePath, trackData); if (writeFileResponse.Erroneous || !writeFileResponse.Value) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#ErrorStyle] Could write track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID); return(true); } GenericResponse <bool> addtrackResponse = command.Is(Command.AddTrack) ? Context.RPCClient.Methods.AddChallenge(targetTrackFilePath) : Context.RPCClient.Methods.InsertChallenge(targetTrackFilePath); if (addtrackResponse.Erroneous || !addtrackResponse.Value) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}>{[#ErrorStyle] Could add track {[#HighlightStyle]}{[Trackname]}{[#ErrorStyle]} with trackid {[#HighlightStyle]}{[TrackID]}.", "Trackname", tmxInfo.Name, "TrackID", trackID); return(true); } SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track {[#HighlightStyle]}{[Trackname]}{[#MessageStyle]} with trackid {[#HighlightStyle]}{[TrackID]}{[#MessageStyle]} added to tracklist.", "Trackname", tmxInfo.Name, "TrackID", trackID); if (command.Is(Command.InsertTrack)) { SendFormattedMessageToLogin(e.Login, "{[#ServerStyle]}> {[#MessageStyle]}Track {[#HighlightStyle]}{[Trackname]}{[#MessageStyle]} with trackid {[#HighlightStyle]}{[TrackID]}{[#MessageStyle]} will be the next track.", "Trackname", tmxInfo.Name, "TrackID", trackID); } return(true); }