/// <summary> /// Send a message to a particular players /// </summary> /// <param name="Message">Message to send</param> /// <param name="Target">Player to send message to</param> public async Task Tell(String Message, Player Target) { #if !DEBUG string formattedMessage = String.Format(RconParser.GetCommandPrefixes().Tell, Target.ClientNumber, Message); if (Target.ClientNumber > -1 && Message.Length > 0 && Target.Level != Player.Permission.Console) { await this.ExecuteCommandAsync(formattedMessage); } #else Logger.WriteVerbose($"{Target.ClientNumber}->{Message.StripColors()}"); await Utilities.CompletedTask; #endif if (Target.Level == Player.Permission.Console) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(Utilities.StripColors(Message)); Console.ForegroundColor = ConsoleColor.Gray; } if (CommandResult.Count > 15) { CommandResult.RemoveAt(0); } CommandResult.Add(new CommandResponseInfo() { Response = Utilities.StripColors(Message), ClientId = Target.ClientId }); }
/// <summary> /// Send a message to all players /// </summary> /// <param name="Message">Message to be sent to all players</param> public async Task Broadcast(String Message) { #if !DEBUG string formattedMessage = String.Format(RconParser.GetCommandPrefixes().Say, Message); await this.ExecuteCommandAsync(formattedMessage); #else Logger.WriteVerbose(Message.StripColors()); await Utilities.CompletedTask; #endif }
override public async Task Ban(String Message, Player Target, Player Origin) { // ensure player gets banned if command not performed on them in game if (Target.ClientNumber < 0) { Player ingameClient = null; ingameClient = Manager.GetServers() .Select(s => s.GetPlayersAsList()) .FirstOrDefault(l => l.FirstOrDefault(c => c.ClientId == Target.ClientId) != null) ?.First(c => c.ClientId == Target.ClientId); if (ingameClient != null) { await Ban(Message, ingameClient, Origin); return; } } else { // this is set only because they're still in the server. Target.Level = Player.Permission.Banned; #if !DEBUG string formattedString = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{Message} ^7({loc["SERVER_BAN_APPEAL"]} {Website})^7"); await Target.CurrentServer.ExecuteCommandAsync(formattedString); #else await Target.CurrentServer.RemovePlayer(Target.ClientNumber); #endif } Penalty newPenalty = new Penalty() { Type = Penalty.PenaltyType.Ban, Expires = DateTime.MaxValue, Offender = Target, Offense = Message, Punisher = Origin, Active = true, When = DateTime.UtcNow, Link = Target.AliasLink }; await Manager.GetPenaltyService().Create(newPenalty); }
public override async Task Kick(String Reason, Player Target, Player Origin) { // ensure player gets kicked if command not performed on them in game if (Target.ClientNumber < 0) { var ingameClient = Manager.GetActiveClients() .FirstOrDefault(c => c.ClientId == Target.ClientId); if (ingameClient != null) { await Kick(Reason, ingameClient, Origin); return; } } #if !DEBUG else { string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, Target.ClientNumber, $"{loc["SERVER_KICK_TEXT"]} - ^5{Reason}^7"); await Target.CurrentServer.ExecuteCommandAsync(formattedKick); } #endif #if DEBUG await Target.CurrentServer.RemovePlayer(Target.ClientNumber); #endif var newPenalty = new Penalty() { Type = Penalty.PenaltyType.Kick, Expires = DateTime.UtcNow, Offender = Target, Offense = Reason, Punisher = Origin, Active = true, When = DateTime.UtcNow, Link = Target.AliasLink }; await Manager.GetPenaltyService().Create(newPenalty); }
override public async Task <bool> AddPlayer(Player polledPlayer) { if ((polledPlayer.Ping == 999 && !polledPlayer.IsBot) || polledPlayer.Ping < 1 || polledPlayer.ClientNumber > (MaxClients) || polledPlayer.ClientNumber < 0) { //Logger.WriteDebug($"Skipping client not in connected state {P}"); return(true); } if (Players[polledPlayer.ClientNumber] != null && Players[polledPlayer.ClientNumber].NetworkId == polledPlayer.NetworkId) { // update their ping & score Players[polledPlayer.ClientNumber].Ping = polledPlayer.Ping; Players[polledPlayer.ClientNumber].Score = polledPlayer.Score; return(true); } #if !DEBUG if (polledPlayer.Name.Length < 3) { Logger.WriteDebug($"Kicking {polledPlayer} because their name is too short"); string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_MINNAME"]); await this.ExecuteCommandAsync(formattedKick); return(false); } if (Players.FirstOrDefault(p => p != null && p.Name == polledPlayer.Name) != null) { Logger.WriteDebug($"Kicking {polledPlayer} because their name is already in use"); string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_NAME_INUSE"]); await this.ExecuteCommandAsync(formattedKick); return(false); } if (polledPlayer.Name == "Unknown Soldier" || polledPlayer.Name == "UnknownSoldier" || polledPlayer.Name == "CHEATER") { Logger.WriteDebug($"Kicking {polledPlayer} because their name is generic"); string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_GENERICNAME"]); await this.ExecuteCommandAsync(formattedKick); return(false); } if (polledPlayer.Name.Where(c => Char.IsControl(c)).Count() > 0) { Logger.WriteDebug($"Kicking {polledPlayer} because their name contains control characters"); string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, loc["SERVER_KICK_CONTROLCHARS"]); await this.ExecuteCommandAsync(formattedKick); return(false); } #endif Logger.WriteDebug($"Client slot #{polledPlayer.ClientNumber} now reserved"); try { Player player = null; var client = await Manager.GetClientService().GetUnique(polledPlayer.NetworkId); // first time client is connecting to server if (client == null) { Logger.WriteDebug($"Client {polledPlayer} first time connecting"); player = (await Manager.GetClientService().Create(polledPlayer)).AsPlayer(); } // client has connected in the past else { client.LastConnection = DateTime.UtcNow; client.Connections += 1; var existingAlias = client.AliasLink.Children .FirstOrDefault(a => a.Name == polledPlayer.Name && a.IPAddress == polledPlayer.IPAddress); if (existingAlias == null) { Logger.WriteDebug($"Client {polledPlayer} has connected previously under a different ip/name"); client.CurrentAlias = new EFAlias() { IPAddress = polledPlayer.IPAddress, Name = polledPlayer.Name, }; // we need to update their new ip and name to the virtual property client.Name = polledPlayer.Name; client.IPAddress = polledPlayer.IPAddress; await Manager.GetClientService().Update(client); } else if (existingAlias.Name == polledPlayer.Name) { client.CurrentAlias = existingAlias; client.CurrentAliasId = existingAlias.AliasId; await Manager.GetClientService().Update(client); } player = client.AsPlayer(); } // Do the player specific stuff player.ClientNumber = polledPlayer.ClientNumber; player.IsBot = polledPlayer.IsBot; player.Score = polledPlayer.Score; player.CurrentServer = this; Players[player.ClientNumber] = player; var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(player.AliasLinkId, player.IPAddress); var currentBan = activePenalties.FirstOrDefault(b => b.Expires > DateTime.UtcNow); if (currentBan != null) { Logger.WriteInfo($"Banned client {player} trying to connect..."); var autoKickClient = (await Manager.GetClientService().Get(1)).AsPlayer(); autoKickClient.CurrentServer = this; if (currentBan.Type == Penalty.PenaltyType.TempBan) { string formattedKick = String.Format(RconParser.GetCommandPrefixes().Kick, polledPlayer.ClientNumber, $"{loc["SERVER_TB_REMAIN"]} ({(currentBan.Expires - DateTime.UtcNow).TimeSpanText()} left)"); await this.ExecuteCommandAsync(formattedKick); } else { await player.Kick($"{loc["SERVER_BAN_PREV"]} {currentBan.Offense}", autoKickClient); } if (player.Level != Player.Permission.Banned && currentBan.Type == Penalty.PenaltyType.Ban) { await player.Ban($"{loc["SERVER_BAN_PREV"]} {currentBan.Offense}", autoKickClient); } return(true); } Logger.WriteInfo($"Client {player} connecting..."); await ExecuteEvent(new GameEvent(GameEvent.EventType.Connect, "", player, null, this)); if (!Manager.GetApplicationSettings().Configuration().EnableClientVPNs&& await VPNCheck.UsingVPN(player.IPAddressString, Manager.GetApplicationSettings().Configuration().IPHubAPIKey)) { await player.Kick(Utilities.CurrentLocalization.LocalizationSet["SERVER_KICK_VPNS_NOTALLOWED"], new Player() { ClientId = 1 }); } return(true); } catch (Exception E) { Manager.GetLogger().WriteError($"Unable to add player {polledPlayer.Name}::{polledPlayer.NetworkId}"); Manager.GetLogger().WriteDebug(E.StackTrace); return(false); } }