/// <summary> /// This will add a permanent ban to both the memory list and the disk database. /// </summary> /// <param name="rep"></param> public void AddPermBan(JusticeSystem.Report rep) { lock (PermanentBans) { PermanentBans.Add(rep); OnPlayerBanned?.Invoke(rep); } File.WriteAllText(Path.Combine(BanFolder, $"ban-{rep.Target}.json"), JsonSerializer.Serialize(rep)); }
/// <summary> /// This will permanently ban a player. The player must be connected to the server. /// </summary> /// <param name="addr">The player's address.</param> /// <param name="dashboard">The address of the dashboard from where the command originated.</param> /// <returns>True if the player was found and banned.</returns> public bool BanPlayer(IPAddress addr, string dashboard) { bool found = false; foreach (var possibleTarget in Manager.GetPlayers()) { if (possibleTarget == null || possibleTarget.Client.Connection == null || possibleTarget.Character == null) { continue; } if (possibleTarget.Client.Connection.EndPoint.Address.Equals(addr)) { //we found our target! possibleTarget.BanAsync(); if (!found) { found = true; var report = new JusticeSystem.Report { Messages = new List <string> { "<adminsys / " + DateTime.Now.ToString() + ">" }, Sources = new List <string> { dashboard }, Target = possibleTarget.Client.Connection.EndPoint.Address.ToString(), TargetName = possibleTarget.Character.PlayerInfo.PlayerName, MinutesRemaining = 0, TotalReports = 0 }; AddPermBan(report); } } } return(found); }
private void DashboardCommandReceived(string command, string data, bool single, Fleck.IWebSocketConnection source) { switch (command) { case DashboardBansMessage: { if (!single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } lock (HighCourt.PermanentBans) { string response = $" Total bans : {HighCourt.PermanentBans.Count}\n"; if (HighCourt.PermanentBans.Count > 0) { //there are bans, so we add them to our message. foreach (var ban in HighCourt.PermanentBans) { response += " IPA : " + ban.Target.ToString() + $" / {ban.TargetName}\n"; } } PluginBase.ApiServer.PushTo(response, "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardBanIpAddress: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (IPAddress.TryParse(data, out IPAddress address)) { if (HighCourt.BanPlayer(address, source.ConnectionInfo.ClientIpAddress)) { PluginBase.ApiServer.Push( $"The target [{address}] has been banned permanently by {source.ConnectionInfo.ClientIpAddress}!", "(SERVER/CRITICAL/WIDE)", Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo("Could not find player.", Structures.ServerSources.DebugSystem, Structures.MessageFlag.ConsoleLogMessage, source); } } else { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardBanIpAddressBlind: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (IPAddress.TryParse(data, out IPAddress address)) { var report = new JusticeSystem.Report { Messages = new List <string> { "<adminsys / " + DateTime.Now + ">" }, Sources = new List <string> { source.ConnectionInfo.ClientIpAddress }, Target = address.ToString(), TargetName = "<unknown>", MinutesRemaining = 0, TotalReports = 0 }; HighCourt.AddPermBan(report); PluginBase.ApiServer.Push( $"The target [{address}] has been blindly banned by {source.ConnectionInfo.ClientIpAddress}!", "(SERVER/CRITICAL/WIDE)", Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardUnBanAddress: { if (single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } if (HighCourt.RemoveBan(data)) { PluginBase.ApiServer.PushTo($"The target player has been unbanned.", Structures.ServerSources.CommandSystem, Structures.MessageFlag.ConsoleLogMessage, source); PluginBase.ApiServer.Push( $"A player with the IP address [{data}] has been unbanned by {source.ConnectionInfo.ClientIpAddress}.", Structures.ServerSources.DebugSystemCritical, Structures.MessageFlag.ConsoleLogMessage); } else { PluginBase.ApiServer.PushTo($"Error: the target player [{data}] is not banned.", Structures.ServerSources.DebugSystem, Structures.MessageFlag.ConsoleLogMessage, source); } break; } case DashboardReloadBans: { if (!single) { PluginBase.ApiServer.PushTo("Invalid command data.", "sysinfo", Structures.MessageFlag.ConsoleLogMessage, source); break; } HighCourt.ReloadBans(); break; } } }
/// <summary> /// This is called when a player is banned by reports. /// </summary> /// <param name="rep"></param> private void PlayerBanned(JusticeSystem.Report rep) { PluginBase.ApiServer.Push($"Player {rep.TargetName} / {rep.Target} was banned permanently.", "reportsys", Structures.MessageFlag.ConsoleLogMessage, null); }
/// <summary> /// Call this whenever the report command is fired. This will handle reporting, logging, and banning. /// </summary> /// <param name="data">The command data.</param> /// <param name="source">The source of the report.</param> public void HandleReport(string data, IPlayerChatEvent source) { if (data.Count(x => x == "'"[0]) != 2) { ChatInterface.SafeMultiMessage(source.Game, "Invalid format. Please use : \"/report hacking Player's name 'Describe the cheat here'\"!", Structures.BroadcastType.Error, "(server/private)", source.ClientPlayer); return; } if (data.StartsWith("hacking ")) { data = data.Remove(0, 8); int pFrom = data.IndexOf("'", StringComparison.InvariantCultureIgnoreCase) + 1; int pTo = data.LastIndexOf("'", StringComparison.CurrentCultureIgnoreCase); var message = data.Substring(pFrom, pTo - pFrom); data = new string(data.Take(pFrom - 2 /*we need to remove the ' and the space.*/).ToArray()); foreach (var client in source.Game.Players) { if (client.Character.PlayerInfo.PlayerName.Equals(data)) { lock (IpReports) { bool updated = false; for (int i = 0; i < IpReports.Count; i++) { if (IpReports[i].Target.Equals(client.Client.Connection.EndPoint.Address.ToString())) { updated = true; if (IpReports[i].TotalReports >= ReportsPerBan) { client.BanAsync(); AddPermBan(IpReports[i]); IpReports.Remove(IpReports[i]); ChatInterface.SafeMultiMessage(source.Game, $"\"{client.Character.PlayerInfo.PlayerName}\" has been permanently banned.", Structures.BroadcastType.Warning); } else { lock (IpReports) { updated = true; if (!IpReports[i].Sources.Contains(source.ClientPlayer.Client .Connection.EndPoint.Address.ToString())) { IpReports[i].TotalReports += 1; IpReports[i].Messages.Add(message); IpReports[i].Sources.Add(source.ClientPlayer.Client .Connection .EndPoint.Address.ToString()); ChatInterface.SafeMultiMessage(source.Game, $"Your report has been filed successfully. The offender has {IpReports[i].TotalReports} complaints now.", Structures.BroadcastType.Information, "(server complaints/private)", source.ClientPlayer); } else { ChatInterface.SafeMultiMessage(source.Game, $"You cannot report the offender again. He will be taken care of.", Structures.BroadcastType.Error, "(server/error/private)", source.ClientPlayer); } } } } } if (!updated) { var report = new JusticeSystem.Report { TargetName = client.Character.PlayerInfo.PlayerName, TotalReports = 1, Target = client.Client.Connection.EndPoint.Address.ToString(), Sources = new List <string>() }; report.Sources.Add(source.ClientPlayer.Client.Connection.EndPoint.Address.ToString()); lock (IpReports) IpReports.Add(report); ChatInterface.SafeMultiMessage(source.Game, $"A criminal record has been created for {client.Character.PlayerInfo.PlayerName}!", Structures.BroadcastType.Information, "(server complaints/private)", source.ClientPlayer); } } return; } } ChatInterface.SafeMultiMessage(source.Game, "Could not find player", Structures.BroadcastType.Warning, "(server/warn)", source.ClientPlayer); } }