From cd8ee681b21990389e05d38b7f14b5f95bb4b555 Mon Sep 17 00:00:00 2001 From: RoyZ Date: Sun, 11 Feb 2024 14:13:09 +0800 Subject: [PATCH 1/7] Create zh-Hans.json add Chinese translation --- lang/zh-Hans.json | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lang/zh-Hans.json diff --git a/lang/zh-Hans.json b/lang/zh-Hans.json new file mode 100644 index 0000000..ebcd21c --- /dev/null +++ b/lang/zh-Hans.json @@ -0,0 +1,43 @@ +{ + "sa_prefix": "{lightred}[SA] {default}", + "sa_adminhelp": "{GREEN}[CS2-SimpleAdmin帮助]{DEFAULT}\n- css_who <#用户ID或名称> - 显示玩家信息\n- css_players - 显示玩家列表\n- css_ban <#用户ID或名称> [时间(分钟)/0永久] [原因] - 封禁玩家\n- css_addban [时间(分钟)/0永久] [原因] - 通过SteamID64封禁玩家\n- css_banip [时间(分钟)/0永久] [原因] - 通过IP地址封禁玩家\n- css_unban - 解封玩家\n- css_kick <#用户ID或名称> [原因] - 踢出玩家\n- css_gag <#用户ID或名称> [时间(分钟)/0永久] [原因] - 禁言玩家\n- css_addgag [时间(分钟)/0永久] [原因] - 通过SteamID64禁言玩家\n- css_unmute - 解除玩家禁言\n- css_mute <#用户ID或名称> [时间(分钟)/0永久] [原因] - 禁言玩家\n- css_addmute [时间(分钟)/0永久] [原因] - 通过SteamID64禁言玩家\n- css_give <#用户ID或名称> <武器> - 给予玩家武器\n- css_strip <#用户ID或名称> <武器> - 夺取玩家所有武器\n- css_hp <#用户ID或名称> [生命值] - 设置玩家生命值\n- css_god <#用户ID或名称> - 切换玩家上帝模式\n- css_slay <#用户ID或名称> - 杀死玩家\n- css_slap <#用户ID或名称> [伤害] - 打击玩家\n- css_vote <'问题?'> ['答案1'] ['答案2'] ... - 创建投票\n- css_map <地图名称> - 切换地图\n- css_wsmap <名称或ID> - 切换创意工坊地图\n- css_asay <消息> - 向所有管理员发送消息\n- css_say <消息> - 作为管理员在聊天中发送消息\n- css_psay <#用户ID或名称> <消息> - 向玩家发送私密消息\n- css_csay <消息> - 作为管理员在中央发送消息\n- css_hsay <消息> - 作为管理员在HUD发送消息\n- css_noclip <#用户ID或名称> - 切换玩家无碰撞模式\n- css_freeze <#用户ID或名称> [持续时间] - 冻结玩家\n- css_unfreeze <#用户ID或名称> - 解冻玩家\n- css_respawn <#用户ID或名称> - 重生玩家\n- css_cvar - 更改cvar值\n- css_rcon - 作为服务器运行命令", + "sa_player_ban_message_time": "你被{lightred}{0}{default}封禁了{lightred}{1}{default}分钟,原因是{lightred}{2}{default}!", + "sa_player_ban_message_perm": "你被{lightred}{0}{default}永久封禁了,原因是{lightred}{1}{default}!", + "sa_player_kick_message": "你被{lightred}{0}{default}踢出了游戏,原因是{lightred}{1}{default}!", + "sa_player_gag_message_time": "你被{lightred}{0}{default}禁言了{lightred}{1}{default}分钟,原因是{lightred}{2}{default}!", + "sa_player_gag_message_perm": "你被{lightred}{0}{default}永久禁言了,原因是{lightred}{1}{default}!", + "sa_player_mute_message_time": "你被{lightred}{0}{default}禁言了{lightred}{1}{default}分钟,原因是{lightred}{2}{default}!", + "sa_player_mute_message_perm": "你被{lightred}{0}{default}永久禁言了,原因是{lightred}{1}{default}!", + "sa_player_silence_message_time": "你被{lightred}{0}{default}沉默了{lightred}{1}{default}分钟,原因是{lightred}{2}{default}!", + "sa_player_silence_message_perm": "你被{lightred}{0}{default}永久沉默了,原因是{lightred}{1}{default}!", + "sa_admin_ban_message_time": "管理员{lightred}{0}{default}封禁了{lightred}{1}{default},封禁时间为{lightred}{2}{default}分钟,原因是{lightred}{3}{default}!", + "sa_admin_ban_message_perm": "管理员{lightred}{0}{default}永久封禁了{lightred}{1}{default},原因是{lightred}{2}{default}!", + "sa_admin_kick_message": "管理员{lightred}{0}{default}踢出了{lightred}{1}{default},原因是{lightred}{2}{default}!", + "sa_admin_gag_message_time": "管理员{lightred}{0}{default}禁言了{lightred}{1}{default},禁言时间为{lightred}{2}{default}分钟,原因是{lightred}{3}{default}!", + "sa_admin_gag_message_perm": "管理员{lightred}{0}{default}永久禁言了{lightred}{1}{default},原因是{lightred}{2}{default}!", + "sa_admin_mute_message_time": "管理员{lightred}{0}{default}禁言了{lightred}{1}{default},禁言时间为{lightred}{2}{default}分钟,原因是{lightred}{3}{default}!", + "sa_admin_mute_message_perm": "管理员{lightred}{0}{default}永久禁言了{lightred}{1}{default},原因是{lightred}{2}{default}!", + "sa_admin_silence_message_time": "管理员{lightred}{0}{default}沉默了{lightred}{1}{default},沉默时间为{lightred}{2}{default}分钟,原因是{lightred}{3}{default}!", + "sa_admin_silence_message_perm": "管理员{lightred}{0}{default}永久沉默了{lightred}{1}{default},原因是{lightred}{2}{default}!", + "sa_admin_give_message": "管理员{lightred}{0}{default}给予了{lightred}{1}{default}一把{lightred}{2}{default}!", + "sa_admin_strip_message": "管理员{lightred}{0}{default}夺取了玩家{lightred}{1}{default}的所有武器!", + "sa_admin_hp_message": "管理员{lightred}{0}{default}修改了{lightred}{1}{default}的生命值!", + "sa_admin_speed_message": "管理员{lightred}{0}{default}修改了{lightred}{1}{default}的速度!", + "sa_admin_god_message": "管理员{lightred}{0}{default}修改了{lightred}{1}{default}的上帝模式!", + "sa_admin_slay_message": "管理员{lightred}{0}{default}杀死了{lightred}{1}{default}!", + "sa_admin_slap_message": "管理员{lightred}{0}{default}扇了{lightred}{1}{default}一巴掌!", + "sa_admin_changemap_message": "管理员{lightred}{0}{default}将地图切换为{lightred}{1}{default}!", + "sa_admin_noclip_message": "管理员{lightred}{0}{default}切换了{lightred}{1}{default}的无碰撞模式!", + "sa_admin_freeze_message": "管理员{lightred}{0}{default}冻结了{lightred}{1}{default}!", + "sa_admin_unfreeze_message": "管理员{lightred}{0}{default}解冻了{lightred}{1}{default}!", + "sa_admin_rename_message": "管理员{lightred}{0}{default}将{lightred}{1}{default}的昵称更改为{lightred}{2}{default}!", + "sa_admin_respawn_message": "管理员{lightred}{0}{default}重生了{lightred}{1}{default}!", + "sa_admin_team_message": "管理员{lightred}{0}{default}将{lightred}{1}{default}转移到{lightred}{2}{default}队伍!", + "sa_admin_vote_menu_title": "{lime}正在为{gold}{0}进行投票", + "sa_admin_vote_message": "管理员{lightred}{0}{default}开始对{lightred}{1}{default}进行投票", + "sa_admin_vote_message_results": "{lime}投票结果:{gold}{0}", + "sa_admin_vote_message_results_answer": "{lime}{0} {default}- {gold}{1}", + "sa_adminsay_prefix": "{RED}管理员:{lightred}{0}{default}", + "sa_adminchat_template_admin": "{LIME}(管理员) {lightred}{0}{default}:{lightred}{1}{default}", + "sa_adminchat_template_player": "{SILVER}(玩家) {lightred}{0}{default}:{lightred}{1}{default}" +} From 5d0234326805831d7018da44937554981ff5e39a Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:56:57 +0100 Subject: [PATCH 2/7] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c93c496..4c889d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ env: BUILD_NUMBER: ${{ github.run_number }} PROJECT_PATH: "CS2-SimpleAdmin.csproj" PROJECT_NAME: "CS2-SimpleAdmin" - OUTPUT_PATH: "./CS2-SimpleAdmin" + OUTPUT_PATH: "./CS2-SimpleAdmin/build" jobs: build: From e4e10236842e444b464a21f75ef1e716cdc02262 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:58:27 +0100 Subject: [PATCH 3/7] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4c889d9..c93c496 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ env: BUILD_NUMBER: ${{ github.run_number }} PROJECT_PATH: "CS2-SimpleAdmin.csproj" PROJECT_NAME: "CS2-SimpleAdmin" - OUTPUT_PATH: "./CS2-SimpleAdmin/build" + OUTPUT_PATH: "./CS2-SimpleAdmin" jobs: build: From bda704e84360c6ec21f3a4fa77da23f29f35450f Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:00:38 +0100 Subject: [PATCH 4/7] test test --- CS2-SimpleAdmin.cs | 2672 +---------------- CS2-SimpleAdmin.csproj | 3 +- Commands/basebans.cs | 380 +++ Commands/basechat.cs | 134 + Commands/basecommands.cs | 562 ++++ Commands/basecomms.cs | 944 ++++++ Commands/basevotes.cs | 94 + Commands/funcommands.cs | 135 + Commands/playercommands.cs | 651 ++++ Config.cs | 14 +- Database.cs => Database/Database.cs | 0 .../database_setup.sql | 0 .../PlayerExtensions.cs | 25 +- Helper.cs | 47 +- .../AdminSQLManager.cs | 0 BanManager.cs => Managers/BanManager.cs | 0 MuteManager.cs => Managers/MuteManager.cs | 0 .../PlayerPenaltyManager.cs | 0 lang/en.json | 6 +- lang/es.json | 2 +- lang/pl.json | 6 +- 21 files changed, 3012 insertions(+), 2663 deletions(-) create mode 100644 Commands/basebans.cs create mode 100644 Commands/basechat.cs create mode 100644 Commands/basecommands.cs create mode 100644 Commands/basecomms.cs create mode 100644 Commands/basevotes.cs create mode 100644 Commands/funcommands.cs create mode 100644 Commands/playercommands.cs rename Database.cs => Database/Database.cs (100%) rename database_setup.sql => Database/database_setup.sql (100%) rename PlayerUtils.cs => Extensions/PlayerExtensions.cs (87%) rename AdminSQLManager.cs => Managers/AdminSQLManager.cs (100%) rename BanManager.cs => Managers/BanManager.cs (100%) rename MuteManager.cs => Managers/MuteManager.cs (100%) rename PlayerPenaltyManager.cs => Managers/PlayerPenaltyManager.cs (100%) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 85777c1..72a73a9 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -1,24 +1,14 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CounterStrikeSharp.API.Core.Translations; -using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Cvars; -using CounterStrikeSharp.API.Modules.Entities; -using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; -using CounterStrikeSharp.API.Modules.Menu; -using CounterStrikeSharp.API.Modules.Utils; using Dapper; +using Discord.Webhook; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using MySqlConnector; -using Newtonsoft.Json; using System.Collections.Concurrent; -using System.Text; namespace CS2_SimpleAdmin; @@ -40,6 +30,8 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig? CBasePlayerController_SetPawnFunc = null; public override string ModuleName => "CS2-SimpleAdmin"; @@ -93,7 +85,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig - { - try - { - using (var connection = await _database.GetConnectionAsync()) - { - var commandText = "ALTER TABLE `sa_mutes` CHANGE `type` `type` ENUM('GAG','MUTE', 'SILENCE', '') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'GAG';"; - - using (var command = connection.CreateCommand()) - { - command.CommandText = commandText; - await command.ExecuteNonQueryAsync(); - } - } - } - catch (Exception ex) - { - Logger.LogError($"{ex.Message}"); - } - }); - } - - [ConsoleCommand("css_admin")] - [RequiresPermissions("@css/generic")] - public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command) - { - if (caller == null || !caller.IsValid) return; - - using (new WithTemporaryCulture(caller.GetLanguage())) - { - var splitMessage = _localizer!["sa_adminhelp"].ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); - - foreach (var line in splitMessage) - { - caller.PrintToChat(Helper.ReplaceTags($" {line}")); - } - } - } - - [ConsoleCommand("css_addadmin")] - [CommandHelper(minArgs: 4, usage: " ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - [RequiresPermissions("@css/root")] - public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (!Helper.IsValidSteamID64(command.GetArg(1))) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - if (command.GetArg(2).Length <= 0) - { - command.ReplyToCommand($"Invalid player name."); - return; - } - if (!command.GetArg(3).Contains("@") && !command.GetArg(3).Contains("#")) - { - command.ReplyToCommand($"Invalid flag or group."); - return; - } - - string steamid = command.GetArg(1); - string name = command.GetArg(2); - string flags = command.GetArg(3); - bool globalAdmin = command.GetArg(4).ToLower().Equals("-g") || command.GetArg(5).ToLower().Equals("-g") || command.GetArg(6).ToLower().Equals("-g"); - int immunity = 0; - int.TryParse(command.GetArg(4), out immunity); - int time = 0; - int.TryParse(command.GetArg(5), out time); - - AdminSQLManager _adminManager = new(_database); - _ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin); - - command.ReplyToCommand($"Added '{flags}' flags to '{name}' ({steamid})"); - } - - [ConsoleCommand("css_deladmin")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - [RequiresPermissions("@css/root")] - public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (!Helper.IsValidSteamID64(command.GetArg(1))) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - - string steamid = command.GetArg(1); - bool globalDelete = command.GetArg(2).ToLower().Equals("-g"); - - AdminSQLManager _adminManager = new(_database); - _ = _adminManager.DeleteAdminBySteamId(steamid, globalDelete); - - AddTimer(2, () => - { - if (!string.IsNullOrEmpty(steamid) && SteamID.TryParse(steamid, out var steamId) && steamId != null) - { - if (AdminSQLManager._adminCache.ContainsKey(steamId)) - { - AdminSQLManager._adminCache.TryRemove(steamId, out _); - //AdminSQLManager._adminCacheTimestamps.Remove(steamId); - } - - AdminManager.ClearPlayerPermissions(steamId); - AdminManager.RemovePlayerAdminData(steamId); - } - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - - command.ReplyToCommand($"Removed flags from '{steamid}'"); - } - - [ConsoleCommand("css_reladmin")] - [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - [RequiresPermissions("@css/root")] - public void OnRelAdminCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList()) - { - if (AdminSQLManager._adminCache.TryRemove(steamId, out _)) - { - AdminManager.ClearPlayerPermissions(steamId); - AdminManager.RemovePlayerAdminData(steamId); - } - } - - AdminSQLManager _adminManager = new(_database); - _ = _adminManager.GiveAllFlags(); - - command.ReplyToCommand("Reloaded sql admins"); - } - - [ConsoleCommand("css_stealth")] - [ConsoleCommand("css_hide")] - [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] - [RequiresPermissions("@css/kick")] - public void OnHideCommand(CCSPlayerController? caller, CommandInfo command) - { - if (caller == null) return; - - if (silentPlayers.Contains(caller.Slot)) - { - RemoveFromConcurrentBag(silentPlayers, caller.Slot); - caller.PrintToChat($"You aren't hidden now!"); - caller.ChangeTeam(CsTeam.Spectator); - if (Config.DiscordWebhook.Length > 0) - _ = SendWebhookMessage($"{caller.PlayerName} isn't hidden now."); - } - else - { - silentPlayers.Add(caller.Slot); - Server.ExecuteCommand("sv_disable_teamselect_menu 1"); - Server.NextFrame(() => - { - if (caller.PlayerPawn.Value != null && caller.PawnIsAlive) - caller.PlayerPawn.Value.CommitSuicide(true, false); - - AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - AddTimer(1.15f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - caller.PrintToChat($"You are hidden now!"); - if (Config.DiscordWebhook.Length > 0) - _ = SendWebhookMessage($"{caller.PlayerName} is hidden now."); - AddTimer(1.22f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); }); - }); - } - } - - [ConsoleCommand("css_who")] - [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - [RequiresPermissions("@css/generic")] - public void OnWhoCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - Database database = new Database(dbConnectionString); - BanManager _banManager = new(database, Config); - MuteManager _muteManager = new(_database); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - PlayerInfo playerInfo = new PlayerInfo - { - UserId = player.UserId, - Index = (int)player.Index, - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - - Task.Run(async () => - { - int totalBans = 0; - int totalMutes = 0; - - totalBans = await _banManager.GetPlayerBans(playerInfo); - totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!); - - Server.NextFrame(() => - { - if (caller != null) - { - caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------"); - - caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\""); - caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\""); - if (playerInfo.SteamId != null) - caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\""); - if (player.SteamID.ToString().Length == 17) - { - caller!.PrintToConsole($"• SteamID2: \"{player.SteamID}\""); - caller!.PrintToConsole($"• Community link: \"{new SteamID(player.SteamID).ToCommunityUrl()}\""); - } - if (playerInfo.IpAddress != null) - caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\""); - caller!.PrintToConsole($"• Ping: \"{player.Ping}\""); - if (player.SteamID.ToString().Length == 17) - { - caller!.PrintToConsole($"• Total Bans: \"{totalBans}\""); - caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\""); - } - - caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------"); - } - else - { - Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------"); - - Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\""); - Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\""); - if (playerInfo.SteamId != null) - Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\""); - if (player.SteamID.ToString().Length == 17) - { - Server.PrintToConsole($"• SteamID2: \"{player.SteamID}\""); - Server.PrintToConsole($"• Community link: \"{new SteamID(player.SteamID).ToCommunityUrl()}\""); - } - if (playerInfo.IpAddress != null) - Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\""); - Server.PrintToConsole($"• Ping: \"{player.Ping}\""); - if (player.SteamID.ToString().Length == 17) - { - Server.PrintToConsole($"• Total Bans: \"{totalBans}\""); - Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\""); - } - - Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------"); - } - }); - }); - } - }); - } - - [ConsoleCommand("css_players")] - [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - [RequiresPermissions("@css/generic")] - public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command) - { - List playersToTarget = Helper.GetValidPlayers(); - - if (caller != null) - { - caller!.PrintToConsole($"--------- PLAYER LIST ---------"); - playersToTarget.ForEach(player => - { - caller!.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.SteamID}\")"); - }); - caller!.PrintToConsole($"--------- END PLAYER LIST ---------"); - } - else - { - Server.PrintToConsole($"--------- PLAYER LIST ---------"); - playersToTarget.ForEach(player => - { - Server.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.SteamID}\")"); - }); - Server.PrintToConsole($"--------- END PLAYER LIST ---------"); - } - } - - [ConsoleCommand("css_kick")] - [RequiresPermissions("@css/kick")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) - { - string reason = "Unknown"; - - TargetResult? targets = GetTarget(command); - - if (targets == null) - return; - - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) - reason = command.GetArg(2); - - targets.Players.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - if (player.PawnIsAlive) - { - player.Pawn.Value!.Freeze(); - } - - if (command.ArgCount >= 2) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]); - } - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - else - { - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - - if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - } - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_gag")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnGagCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - int time = 0; - string reason = "Unknown"; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - PlayerInfo playerInfo = new PlayerInfo - { - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - Task.Run(async () => - { - await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time); - }); - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); - - if (time == 0) - { - if (!player!.IsBot && !player.IsHLTV) - { - using (new WithTemporaryCulture(player.GetLanguage())) - { - player.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player!.IsBot && !player.IsHLTV) - { - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - } - - if (caller == null || caller != null && caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - }); - } - - [ConsoleCommand("css_addgag")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - if (command.ArgCount < 2) - return; - if (string.IsNullOrEmpty(command.GetArg(1))) return; - - string steamid = command.GetArg(1); - - if (!Helper.IsValidSteamID64(steamid)) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - - int time = 0; - string reason = "Unknown"; - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - List matches = Helper.GetPlayerFromSteamid64(steamid); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (!caller!.CanTarget(player)) - { - command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); - return; - } - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); - } - } - _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0); - command.ReplyToCommand($"Gagged player with steamid {steamid}."); - } - - [ConsoleCommand("css_ungag")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (command.GetArg(1).Length <= 1) - { - command.ReplyToCommand($"Too short pattern to search."); - return; - } - - bool found = false; - - string pattern = command.GetArg(1); - MuteManager _muteManager = new(_database); - - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - if (Helper.IsValidSteamID64(pattern)) - { - List matches = Helper.GetPlayerFromSteamid64(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - - found = true; - } - } - } - else - { - List matches = Helper.GetPlayerFromName(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID.ToString()}"); - - pattern = player!.SteamID.ToString(); - - found = true; - } - } - } - if (found) - { - _ = _muteManager.UnmutePlayer(pattern, 0); // Unmute by type 0 (gag) - command.ReplyToCommand($"Ungaged player with pattern {pattern}."); - return; - } - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - if (playersToTarget.Count > 1) - { - playersToTarget.ForEach(player => - { - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); - - if (player!.SteamID.ToString().Length == 17) - _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag) - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - }); - - command.ReplyToCommand($"Ungaged player with pattern {pattern}."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"Ungaged player with pattern {pattern}."); - return; - } - } - - [ConsoleCommand("css_mute")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - int time = 0; - string reason = "Unknown"; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - PlayerInfo playerInfo = new PlayerInfo - { - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - player!.VoiceFlags = VoiceFlags.Muted; - - Task.Run(async () => - { - await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1); - }); - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - }); - } - - [ConsoleCommand("css_addmute")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (command.ArgCount < 2) - return; - if (string.IsNullOrEmpty(command.GetArg(1))) return; - - string steamid = command.GetArg(1); - - if (!Helper.IsValidSteamID64(steamid)) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - - int time = 0; - string reason = "Unknown"; - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - List matches = Helper.GetPlayerFromSteamid64(steamid); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (!caller!.CanTarget(player)) - { - command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); - return; - } - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - } - _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1); - command.ReplyToCommand($"Muted player with steamid {steamid}."); - } - - [ConsoleCommand("css_unmute")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (command.GetArg(1).Length <= 1) - { - command.ReplyToCommand($"Too short pattern to search."); - return; - } - - string pattern = command.GetArg(1); - bool found = false; - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - if (Helper.IsValidSteamID64(pattern)) - { - List matches = Helper.GetPlayerFromSteamid64(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); - player.VoiceFlags = VoiceFlags.Normal; - found = true; - } - } - } - else - { - List matches = Helper.GetPlayerFromName(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); - player.VoiceFlags = VoiceFlags.Normal; - pattern = player.SteamID.ToString(); - found = true; - } - } - } - - if (found) - { - _ = _muteManager.UnmutePlayer(pattern, 1); // Unmute by type 1 (mute) - command.ReplyToCommand($"Unmuted player with pattern {pattern}."); - return; - } - - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - if (playersToTarget.Count > 1) - { - playersToTarget.ForEach(player => - { - if (player.SteamID.ToString().Length == 17) - _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 1); // Unmute by type 1 (mute) - - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); - player.VoiceFlags = VoiceFlags.Normal; - }); - - command.ReplyToCommand($"Unmuted player with pattern {pattern}."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"Unmuted player with pattern {pattern}."); - return; - } - } - - [ConsoleCommand("css_silence")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnSilenceCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - int time = 0; - string reason = "Unknown"; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - PlayerInfo playerInfo = new PlayerInfo - { - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - Task.Run(async () => - { - await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2); - }); - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time); - - if (time == 0) - { - if (!player!.IsBot && !player.IsHLTV) - { - using (new WithTemporaryCulture(player.GetLanguage())) - { - player.PrintToCenter(_localizer!["sa_player_silence_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_silence_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player!.IsBot && !player.IsHLTV) - { - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_silence_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - } - - if (caller == null || caller != null && caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_silence_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - }); - } - - [ConsoleCommand("css_addsilence")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (command.ArgCount < 2) - return; - if (string.IsNullOrEmpty(command.GetArg(1))) return; - - string steamid = command.GetArg(1); - - if (!Helper.IsValidSteamID64(steamid)) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - - int time = 0; - string reason = "Unknown"; - - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - List matches = Helper.GetPlayerFromSteamid64(steamid); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (!caller!.CanTarget(player)) - { - command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); - return; - } - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); - - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_silence_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_silence_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_silence_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_silence_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - } - _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2); - command.ReplyToCommand($"Silenced player with steamid {steamid}."); - } - - [ConsoleCommand("css_unsilence")] - [RequiresPermissions("@css/chat")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) - { - if (_database == null) return; - - if (command.GetArg(1).Length <= 1) - { - command.ReplyToCommand($"Too short pattern to search."); - return; - } - - string pattern = command.GetArg(1); - bool found = false; - MuteManager _muteManager = new(_database); - PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - - if (Helper.IsValidSteamID64(pattern)) - { - List matches = Helper.GetPlayerFromSteamid64(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); - player.VoiceFlags = VoiceFlags.Normal; - found = true; - } - } - } - else - { - List matches = Helper.GetPlayerFromName(pattern); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); - player.VoiceFlags = VoiceFlags.Normal; - pattern = player.SteamID.ToString(); - found = true; - } - } - } - - if (found) - { - _ = _muteManager.UnmutePlayer(pattern, 2); // Unmute by type 2 (silence) - command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); - return; - } - - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - if (playersToTarget.Count > 1) - { - playersToTarget.ForEach(player => - { - if (player.SteamID.ToString().Length == 17) - _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 2); // Unmute by type 2 (silence) - - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - - playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); - player.VoiceFlags = VoiceFlags.Normal; - }); - - command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"Unsilenced player with pattern {pattern}."); - return; - } - } - - [ConsoleCommand("css_ban")] - [RequiresPermissions("@css/ban")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnBanCommand(CCSPlayerController? caller, CommandInfo command) - { - if (command.ArgCount < 2) - return; - - int time = 0; - string reason = "Unknown"; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) - { - return; - } - - Database database = new Database(dbConnectionString); - - BanManager _banManager = new(database, Config); - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - if (player.PawnIsAlive) - { - player.Pawn.Value!.Freeze(); - } - - PlayerInfo playerInfo = new PlayerInfo - { - SteamId = player?.SteamID.ToString(), - Name = player?.PlayerName, - IpAddress = player?.IpAddress?.Split(":")[0] - }; - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - Task.Run(async () => - { - await _banManager.BanPlayer(playerInfo, adminInfo, reason, time); - }); - - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - - if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress)) - bannedPlayers.Add(playerInfo.IpAddress); - if (!bannedPlayers.Contains(player!.SteamID.ToString())) - bannedPlayers.Add(player.SteamID.ToString()); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - }); - } - - [ConsoleCommand("css_addban")] - [RequiresPermissions("@css/ban")] - [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command) - { - if (command.ArgCount < 2) - return; - if (string.IsNullOrEmpty(command.GetArg(1))) return; - - string steamid = command.GetArg(1); - - if (!Helper.IsValidSteamID64(steamid)) - { - command.ReplyToCommand($"Invalid SteamID64."); - return; - } - - int time = 0; - string reason = "Unknown"; - - Database database = new Database(dbConnectionString); - - BanManager _banManager = new(database, Config); - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - List matches = Helper.GetPlayerFromSteamid64(steamid); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (!caller!.CanTarget(player)) - { - command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); - return; - } - - player!.Pawn.Value!.Freeze(); - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - } - - Task.Run(async () => - { - Database database = new Database(dbConnectionString); - - BanManager _banManager = new(database, Config); - await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time); - }); - - command.ReplyToCommand($"Banned player with steamid {steamid}."); - } - - [ConsoleCommand("css_banip")] - [RequiresPermissions("@css/ban")] - [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnBanIp(CCSPlayerController? caller, CommandInfo command) - { - if (command.ArgCount < 2) - return; - if (string.IsNullOrEmpty(command.GetArg(1))) return; - - string ipAddress = command.GetArg(1); - - if (!Helper.IsValidIP(ipAddress)) - { - command.ReplyToCommand($"Invalid IP address."); - return; - } - - int time = 0; - string reason = "Unknown"; - - PlayerInfo adminInfo = new PlayerInfo - { - SteamId = caller?.SteamID.ToString(), - Name = caller?.PlayerName, - IpAddress = caller?.IpAddress?.Split(":")[0] - }; - - int.TryParse(command.GetArg(2), out time); - - if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) - reason = command.GetArg(3); - - List matches = Helper.GetPlayerFromIp(ipAddress); - if (matches.Count == 1) - { - CCSPlayerController? player = matches.FirstOrDefault(); - if (player != null && player.IsValid) - { - if (!caller!.CanTarget(player)) - { - command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); - return; - } - - player!.Pawn.Value!.Freeze(); - - if (time == 0) - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - else - { - if (!player.IsBot && !player.IsHLTV) - using (new WithTemporaryCulture(player.GetLanguage())) - { - player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - } - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, "Banned"), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - } - - Task.Run(async () => - { - Database database = new Database(dbConnectionString); - - BanManager _banManager = new(database, Config); - await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time); - }); - - command.ReplyToCommand($"Banned player with IP address {ipAddress}."); - } - - [ConsoleCommand("css_unban")] - [RequiresPermissions("@css/unban")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command) - { - if (command.GetArg(1).Length <= 1) - { - command.ReplyToCommand($"Too short pattern to search."); - return; - } - - string pattern = command.GetArg(1); - - Database database = new Database(dbConnectionString); - - BanManager _banManager = new(database, Config); - - _ = _banManager.UnbanPlayer(pattern); - - command.ReplyToCommand($"Unbanned player with pattern {pattern}."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"Unbanned player with pattern {pattern}."); - } - - [ConsoleCommand("css_slay")] - [RequiresPermissions("@css/slay")] - [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnSlayCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - player.CommitSuicide(false, true); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_give")] - [RequiresPermissions("@css/cheats")] - [CommandHelper(minArgs: 2, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnGiveCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - if (targets == null) return; - - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - - string weaponName = command.GetArg(2); - - // check if item is typed - if (weaponName == null || weaponName.Length < 5) - { - command.ReplyToCommand($"No weapon typed."); - return; - } - - // check if item is valid - if (!weaponName.Contains("weapon_") && !weaponName.Contains("item_")) - { - command.ReplyToCommand($"{weaponName} is not a valid item."); - return; - } - - // check if weapon is knife - if (weaponName.Contains("_knife") || weaponName.Contains("bayonet")) - { - if (CoreConfig.FollowCS2ServerGuidelines) - { - command.ReplyToCommand($"Cannot Give {weaponName} because it's illegal to be given."); - return; - } - } - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - player.GiveNamedItem(weaponName); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_strip")] - [RequiresPermissions("@css/slay")] - [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnStripCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - if (targets == null) return; - - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - player.RemoveWeapons(); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_hp")] - [RequiresPermissions("@css/slay")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnHpCommand(CCSPlayerController? caller, CommandInfo command) - { - int health = 100; - int.TryParse(command.GetArg(2), out health); - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - player.SetHp(health); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_speed")] - [RequiresPermissions("@css/slay")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnSpeedCommand(CCSPlayerController? caller, CommandInfo command) - { - double speed = 1.0; - double.TryParse(command.GetArg(2), out speed); - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - /* - player.Speed = (float)speed; - player.PlayerPawn.Value!.Speed = (float)speed; - */ - player.SetSpeed((float)speed); - - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_god")] - [RequiresPermissions("@css/cheats")] - [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnGodCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - if (player != null) - { - if (!godPlayers.Contains(player.Slot)) - { - godPlayers.Add(player.Slot); - } - else - { - godPlayers = new ConcurrentBag(godPlayers.Where(item => item != player.Slot)); - } - - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - } - }); - } - - [ConsoleCommand("css_slap")] - [RequiresPermissions("@css/slay")] - [CommandHelper(minArgs: 1, usage: "<#userid or name> [damage]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnSlapCommand(CCSPlayerController? caller, CommandInfo command) - { - int damage = 0; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - if (command.ArgCount >= 2) - { - int.TryParse(command.GetArg(2), out damage); - } - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - player!.Pawn.Value!.Slap(damage); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_team")] - [RequiresPermissions("@css/kick")] - [CommandHelper(minArgs: 2, usage: "<#userid or name> [] [-k]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnTeamCommand(CCSPlayerController? caller, CommandInfo command) - { - string teamName = command.GetArg(2).ToLower(); - string _teamName; - CsTeam teamNum = CsTeam.Spectator; - - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - - switch (teamName) - { - case "ct": - case "counterterrorist": - teamNum = CsTeam.CounterTerrorist; - _teamName = "CT"; - break; - - case "t": - case "tt": - case "terrorist": - teamNum = CsTeam.Terrorist; - _teamName = "TT"; - break; - - case "swap": - _teamName = "SWAP"; - break; - - default: - teamNum = CsTeam.Spectator; - _teamName = "SPEC"; - break; - } - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (!teamName.Equals("swap")) - { - if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !command.GetArg(3).ToLower().Equals("-k") && Config.TeamSwitchType == 1) - player.SwitchTeam(teamNum); - else - player.ChangeTeam(teamNum); - } - else - { - if (player.TeamNum != (byte)CsTeam.Spectator) - { - CsTeam teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist; - _teamName = teamNum == CsTeam.Terrorist ? "TT" : "CT"; - if (player.PawnIsAlive && !command.GetArg(3).ToLower().Equals("-k") && Config.TeamSwitchType == 1) - { - player.SwitchTeam(teamNum); - } - else - { - player.ChangeTeam(teamNum); - } - } - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, _teamName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_team_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, _teamName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_vote")] - [RequiresPermissions("@css/generic")] - [CommandHelper(minArgs: 2, usage: " [... options ...]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command) - { - if (command.GetArg(1) == null || command.GetArg(1).Length < 0 || command.ArgCount < 2) - return; - - voteAnswers.Clear(); - - string question = command.GetArg(1); - int answersCount = command.ArgCount; - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]); - - for (int i = 2; i <= answersCount - 1; i++) - { - voteAnswers.Add(command.GetArg(i), 0); - voteMenu.AddMenuOption(command.GetArg(i), Helper.handleVotes); - } - - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - - using (new WithTemporaryCulture(_player.GetLanguage())) - { - Helper.PrintToCenterAll(_localizer!["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); - _player.PrintToChat(sb.ToString()); - } - - MenuManager.OpenChatMenu(_player, voteMenu); - } - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - - voteInProgress = true; - } - - if (voteInProgress) - { - AddTimer(30, () => - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_vote_message_results", question]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_vote_message_results", question]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - - foreach (KeyValuePair kvp in voteAnswers) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - voteAnswers.Clear(); - votePlayers.Clear(); - voteInProgress = false; - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - } - - [ConsoleCommand("css_changemap")] - [ConsoleCommand("css_map")] - [RequiresPermissions("@css/changemap")] - [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] - public void OnMapCommand(CCSPlayerController? caller, CommandInfo command) - { - string _command = string.Empty; - string? map = command.GetCommandString.Split(" ")[1]; - - if (map.StartsWith("ws:")) - { - if (long.TryParse(map.Replace("ws:", ""), out long mapId)) - { - _command = $"host_workshop_map {mapId}"; - } - else - { - _command = $"ds_workshop_changelevel {map.Replace("ws:", "")}"; - } - - AddTimer(2.0f, () => - { - Server.ExecuteCommand(_command); - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - else - { - if (!Server.IsMapValid(map)) - { - command.ReplyToCommand($"Map {map} not found."); - return; - } - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - - if (!map.StartsWith("ws:")) - { - AddTimer(2.0f, () => - { - Server.ExecuteCommand($"changelevel {map}"); - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - } - - [ConsoleCommand("css_changewsmap", "Change workshop map.")] - [ConsoleCommand("css_wsmap", "Change workshop map.")] - [ConsoleCommand("css_workshop", "Change workshop map.")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/changemap")] - public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command) - { - string _command = string.Empty; - string? map = command.GetArg(1); - - if (long.TryParse(map, out long mapId)) - { - _command = $"host_workshop_map {mapId}"; - } - else - { - _command = $"ds_workshop_changelevel {map}"; - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - - AddTimer(2.0f, () => - { - Server.ExecuteCommand(_command); - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } - - [ConsoleCommand("css_asay", "Say to all admins.")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/chat")] - public void OnAdminToAdminSayCommand(CCSPlayerController? caller, CommandInfo command) - { - if (caller == null || !caller.IsValid || command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; - - byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); - string utf8String = Encoding.UTF8.GetString(utf8BytesString); - - foreach (CCSPlayerController _player in Helper.GetValidPlayers().Where(p => AdminManager.PlayerHasPermissions(p, "@css/chat"))) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(); - sb.Append(_localizer!["sa_adminchat_template_admin", caller == null ? "Console" : caller.PlayerName, utf8String]); - _player.PrintToChat(sb.ToString()); - } - } - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"ASAY: {caller!.PlayerName}: {utf8String}"); - } - - [ConsoleCommand("css_say", "Say to all players.")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/chat")] - public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command) - { - if (command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; - - byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); - string utf8String = Encoding.UTF8.GetString(utf8BytesString); - - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(); - sb.Append(_localizer!["sa_adminsay_prefix", utf8String]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"ASAY: {caller!.PlayerName}: {utf8String}"); - } - - [ConsoleCommand("css_psay", "Private message a player.")] - [CommandHelper(2, "<#userid or name> ")] - [RequiresPermissions("@css/chat")] - public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - if (targets == null) return; - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - - int range = command.GetArg(0).Length + command.GetArg(1).Length + 2; - string message = command.GetCommandString[range..]; - - byte[] utf8BytesString = Encoding.UTF8.GetBytes(message); - string utf8String = Encoding.UTF8.GetString(utf8BytesString); - - playersToTarget.ForEach(player => - { - player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {utf8String}")); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"PSAY: {caller!.PlayerName} --> {player!.PlayerName}: {utf8String}"); - }); - - command.ReplyToCommand(Helper.ReplaceTags($" Private message sent!")); - } - - [ConsoleCommand("css_csay", "Say to all players (in center).")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/chat")] - public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo command) - { - byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); - string utf8String = Encoding.UTF8.GetString(utf8BytesString); - - Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String)); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"CSAY: {caller!.PlayerName}: {utf8String}"); - } - - [ConsoleCommand("css_hsay", "Say to all players (in hud).")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/chat")] - public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo command) - { - byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); - string utf8String = Encoding.UTF8.GetString(utf8BytesString); - - VirtualFunctions.ClientPrintAll( - HudDestination.Alert, - Helper.ReplaceTags(utf8String), - 0, 0, 0, 0); - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"HSAY: {caller!.PlayerName}: {utf8String}"); - } - - [ConsoleCommand("css_noclip", "Noclip a player.")] - [CommandHelper(1, "<#userid or name>")] - [RequiresPermissions("@css/cheats")] - public void OnNoclipCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (caller!.CanTarget(player)) - { - player!.Pawn.Value!.ToggleNoclip(); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_freeze", "Freeze a player.")] - [CommandHelper(1, "<#userid or name> [duration]")] - [RequiresPermissions("@css/slay")] - public void OnFreezeCommand(CCSPlayerController? caller, CommandInfo command) - { - int time = 0; - int.TryParse(command.GetArg(2), out time); - - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - player!.Pawn.Value!.Freeze(); - - if (time > 0) - AddTimer(time, () => player.Pawn.Value!.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - } - }); - } - - [ConsoleCommand("css_unfreeze", "Unfreeze a player.")] - [CommandHelper(1, "<#userid or name>")] - [RequiresPermissions("@css/slay")] - public void OnUnfreezeCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - player!.Pawn.Value!.Unfreeze(); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_rename", "Rename a player.")] - [CommandHelper(1, "<#userid or name> ")] - [RequiresPermissions("@css/kick")] - public void OnRenameCommand(CCSPlayerController? caller, CommandInfo command) - { - string? newName = command.GetArg(2); - - if (string.IsNullOrEmpty(newName)) - return; - - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - player.Rename(newName); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_rename_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, newName]); - _player.PrintToChat(sb.ToString()); - } - } - } - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_rename_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, newName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_respawn", "Respawn a dead player.")] - [CommandHelper(1, "<#userid or name>")] - [RequiresPermissions("@css/cheats")] - public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo command) - { - TargetResult? targets = GetTarget(command); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - - playersToTarget.ForEach(player => - { - if (!player.IsBot && player.SteamID.ToString().Length != 17) - return; - - if (caller!.CanTarget(player)) - { - if (CBasePlayerController_SetPawnFunc == null || player.PlayerPawn.Value == null || !player.PlayerPawn.IsValid) return; - - var playerPawn = player.PlayerPawn.Value; - CBasePlayerController_SetPawnFunc.Invoke(player, playerPawn, true, false); - VirtualFunction.CreateVoid(player.Handle, - GameData.GetOffset("CCSPlayerController_Respawn"))(player); - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) - { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } - } - } - - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - { - LocalizedString localizedMessage = _localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]; - _ = SendWebhookMessage(localizedMessage.ToString().Replace("", "").Replace("", "")); - } - } - }); - } - - [ConsoleCommand("css_cvar", "Change a cvar.")] - [CommandHelper(2, " ")] - [RequiresPermissions("@css/cvar")] - public void OnCvarCommand(CCSPlayerController? caller, CommandInfo command) - { - var cvar = ConVar.Find(command.GetArg(1)); - string playerName = caller == null ? "Console" : caller.PlayerName; - - if (cvar == null) - { - command.ReplyToCommand($"Cvar \"{command.GetArg(1)}\" not found."); - return; - } - - if (cvar.Name.Equals("sv_cheats") && !AdminManager.PlayerHasPermissions(caller, "@css/cheats")) - { - command.ReplyToCommand($"You don't have permissions to change \"{command.GetArg(1)}\"."); - return; - } - - var value = command.GetArg(2); - - Server.ExecuteCommand($"{cvar.Name} {value}"); - - command.ReplyToCommand($"{playerName} changed cvar {cvar.Name} to {value}."); - Logger.LogInformation($"{playerName} changed cvar {cvar.Name} to {value}."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"{playerName} changed cvar {cvar.Name} to {value}."); - } - - [ConsoleCommand("css_rcon", "Run a server console command.")] - [CommandHelper(1, "")] - [RequiresPermissions("@css/rcon")] - public void OnRconCommand(CCSPlayerController? caller, CommandInfo command) - { - string playerName = caller == null ? "Console" : caller.PlayerName; - Server.ExecuteCommand(command.ArgString); - command.ReplyToCommand($"{playerName} executed command {command.ArgString}."); - Logger.LogInformation($"{playerName} executed command ({command.ArgString})."); - if (Config.DiscordWebhook.Length > 0 && _localizer != null) - _ = SendWebhookMessage($"{playerName} executed command ({command.ArgString})."); + if (!string.IsNullOrEmpty(Config.Discord.DiscordLogWebhook)) + _discordWebhookClientLog = new(Config.Discord.DiscordLogWebhook); + if (!string.IsNullOrEmpty(Config.Discord.DiscordPenaltyWebhook)) + _discordWebhookClientPenalty = new(Config.Discord.DiscordPenaltyWebhook); } private static TargetResult? GetTarget(CommandInfo command) @@ -2759,31 +136,20 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig bag, int playerSlot) { - using (var httpClient = new HttpClient()) + var tempList = new List(); + while (!bag.IsEmpty) { - var payload = new + if (bag.TryTake(out int item) && item != playerSlot) { - content = message - }; - - var jsonPayload = JsonConvert.SerializeObject(payload); - var content = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); - - var response = await httpClient.PostAsync(Config.DiscordWebhook, content); - } - } - - private static void RemoveFromConcurrentBag(ConcurrentBag bag, int value) - { - if (bag.Count > 0) - { - if (bag.Contains(value)) - { - bag = new ConcurrentBag(bag.Where(item => item != value)); + tempList.Add(item); } } + foreach (var item in tempList) + { + bag.Add(item); + } } } diff --git a/CS2-SimpleAdmin.csproj b/CS2-SimpleAdmin.csproj index c1d5959..84b2f44 100644 --- a/CS2-SimpleAdmin.csproj +++ b/CS2-SimpleAdmin.csproj @@ -12,6 +12,7 @@ + @@ -21,7 +22,7 @@ - + diff --git a/Commands/basebans.cs b/Commands/basebans.cs new file mode 100644 index 0000000..e9258a2 --- /dev/null +++ b/Commands/basebans.cs @@ -0,0 +1,380 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Entities; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_ban")] + [RequiresPermissions("@css/ban")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnBanCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + if (command.ArgCount < 2) + return; + + string reason = "Unknown"; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + Database database = new Database(dbConnectionString); + + BanManager _banManager = new(database, Config); + + int.TryParse(command.GetArg(2), out int time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + if (player.PawnIsAlive) + { + player.Pawn.Value!.Freeze(); + } + + PlayerInfo playerInfo = new PlayerInfo + { + SteamId = player?.SteamID.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + Task.Run(async () => + { + await _banManager.BanPlayer(playerInfo, adminInfo, reason, time); + }); + + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress)) + bannedPlayers.Add(playerInfo.IpAddress); + if (!bannedPlayers.Contains(player!.SteamID.ToString())) + bannedPlayers.Add(player.SteamID.ToString()); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + }); + } + + [ConsoleCommand("css_addban")] + [RequiresPermissions("@css/ban")] + [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + if (command.ArgCount < 2) + return; + if (string.IsNullOrEmpty(command.GetArg(1))) return; + + string steamid = command.GetArg(1); + + if (!Helper.IsValidSteamID64(steamid)) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string reason = "Unknown"; + + Database database = new Database(dbConnectionString); + + BanManager _banManager = new(database, Config); + + int.TryParse(command.GetArg(2), out int time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + List matches = Helper.GetPlayerFromSteamid64(steamid); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + player!.Pawn.Value!.Freeze(); + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + } + + Task.Run(async () => + { + Database database = new Database(dbConnectionString); + + BanManager _banManager = new(database, Config); + await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time); + }); + + command.ReplyToCommand($"Banned player with steamid {steamid}."); + } + + [ConsoleCommand("css_banip")] + [RequiresPermissions("@css/ban")] + [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnBanIp(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.ArgCount < 2) + return; + if (string.IsNullOrEmpty(command.GetArg(1))) return; + + string ipAddress = command.GetArg(1); + + if (!Helper.IsValidIP(ipAddress)) + { + command.ReplyToCommand($"Invalid IP address."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string reason = "Unknown"; + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + int.TryParse(command.GetArg(2), out int time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + List matches = Helper.GetPlayerFromIp(ipAddress); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + player!.Pawn.Value!.Freeze(); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, "Banned"), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + } + + Task.Run(async () => + { + Database database = new Database(dbConnectionString); + + BanManager _banManager = new(database, Config); + await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time); + }); + + command.ReplyToCommand($"Banned player with IP address {ipAddress}."); + } + + [ConsoleCommand("css_unban")] + [RequiresPermissions("@css/unban")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + if (command.GetArg(1).Length <= 1) + { + command.ReplyToCommand($"Too short pattern to search."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string pattern = command.GetArg(1); + + Database database = new Database(dbConnectionString); + + BanManager _banManager = new(database, Config); + + _ = _banManager.UnbanPlayer(pattern); + + command.ReplyToCommand($"Unbanned player with pattern {pattern}."); + } + } +} diff --git a/Commands/basechat.cs b/Commands/basechat.cs new file mode 100644 index 0000000..4d8d855 --- /dev/null +++ b/Commands/basechat.cs @@ -0,0 +1,134 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Utils; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_asay", "Say to all admins.")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/chat")] + public void OnAdminToAdminSayCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null || !caller.IsValid || command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); + string utf8String = Encoding.UTF8.GetString(utf8BytesString); + + foreach (CCSPlayerController _player in Helper.GetValidPlayers().Where(p => AdminManager.PlayerHasPermissions(p, "@css/chat"))) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(); + sb.Append(_localizer!["sa_adminchat_template_admin", caller == null ? "Console" : caller.PlayerName, utf8String]); + _player.PrintToChat(sb.ToString()); + } + } + } + + [ConsoleCommand("css_say", "Say to all players.")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/chat")] + public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command) + { + if (command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; + + string playerName = caller == null ? "Console" : caller.PlayerName; + byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); + string utf8String = Encoding.UTF8.GetString(utf8BytesString); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(); + sb.Append(_localizer!["sa_adminsay_prefix", utf8String]); + _player.PrintToChat(sb.ToString()); + } + } + } + + [ConsoleCommand("css_psay", "Private message a player.")] + [CommandHelper(2, "<#userid or name> ")] + [RequiresPermissions("@css/chat")] + public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo command) + { + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + int range = command.GetArg(0).Length + command.GetArg(1).Length + 2; + string message = command.GetCommandString[range..]; + + byte[] utf8BytesString = Encoding.UTF8.GetBytes(message); + string utf8String = Encoding.UTF8.GetString(utf8BytesString); + + playersToTarget.ForEach(player => + { + player.PrintToChat(Helper.ReplaceTags($"({caller!.PlayerName}) {utf8String}")); + }); + + command.ReplyToCommand(Helper.ReplaceTags($" Private message sent!")); + } + + [ConsoleCommand("css_csay", "Say to all players (in center).")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/chat")] + public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); + string utf8String = Encoding.UTF8.GetString(utf8BytesString); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String)); + } + + [ConsoleCommand("css_hsay", "Say to all players (in hud).")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/chat")] + public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); + string utf8String = Encoding.UTF8.GetString(utf8BytesString); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + VirtualFunctions.ClientPrintAll( + HudDestination.Alert, + Helper.ReplaceTags(utf8String), + 0, 0, 0, 0); + } + } +} diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs new file mode 100644 index 0000000..fe04b84 --- /dev/null +++ b/Commands/basecommands.cs @@ -0,0 +1,562 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Utils; +using Microsoft.Extensions.Logging; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_sa_upgrade")] + [CommandHelper(whoCanExecute: CommandUsage.SERVER_ONLY)] + public void OnSaUpgradeCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller != null || _database == null) return; + + Task.Run(async () => + { + try + { + using (var connection = await _database.GetConnectionAsync()) + { + var commandText = "ALTER TABLE `sa_mutes` CHANGE `type` `type` ENUM('GAG','MUTE', 'SILENCE', '') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'GAG';"; + + using (var command = connection.CreateCommand()) + { + command.CommandText = commandText; + await command.ExecuteNonQueryAsync(); + } + } + } + catch (Exception ex) + { + Logger.LogError($"{ex.Message}"); + } + }); + } + + [ConsoleCommand("css_admin")] + [RequiresPermissions("@css/generic")] + public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null || !caller.IsValid) return; + + using (new WithTemporaryCulture(caller.GetLanguage())) + { + var splitMessage = _localizer!["sa_adminhelp"].ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + + foreach (var line in splitMessage) + { + caller.PrintToChat(Helper.ReplaceTags($" {line}")); + } + } + } + + [ConsoleCommand("css_addadmin")] + [CommandHelper(minArgs: 4, usage: " ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (!Helper.IsValidSteamID64(command.GetArg(1))) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + if (command.GetArg(2).Length <= 0) + { + command.ReplyToCommand($"Invalid player name."); + return; + } + if (!command.GetArg(3).Contains("@") && !command.GetArg(3).Contains("#")) + { + command.ReplyToCommand($"Invalid flag or group."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string steamid = command.GetArg(1); + string name = command.GetArg(2); + string flags = command.GetArg(3); + bool globalAdmin = command.GetArg(4).ToLower().Equals("-g") || command.GetArg(5).ToLower().Equals("-g") || command.GetArg(6).ToLower().Equals("-g"); + int immunity = 0; + int.TryParse(command.GetArg(4), out immunity); + int time = 0; + int.TryParse(command.GetArg(5), out time); + + AdminSQLManager _adminManager = new(_database); + _ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin); + + command.ReplyToCommand($"Added '{flags}' flags to '{name}' ({steamid})"); + } + + [ConsoleCommand("css_deladmin")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (!Helper.IsValidSteamID64(command.GetArg(1))) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string steamid = command.GetArg(1); + bool globalDelete = command.GetArg(2).ToLower().Equals("-g"); + + AdminSQLManager _adminManager = new(_database); + _ = _adminManager.DeleteAdminBySteamId(steamid, globalDelete); + + AddTimer(2, () => + { + if (!string.IsNullOrEmpty(steamid) && SteamID.TryParse(steamid, out var steamId) && steamId != null) + { + if (AdminSQLManager._adminCache.ContainsKey(steamId)) + { + AdminSQLManager._adminCache.TryRemove(steamId, out _); + } + + AdminManager.ClearPlayerPermissions(steamId); + AdminManager.RemovePlayerAdminData(steamId); + } + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + command.ReplyToCommand($"Removed flags from '{steamid}'"); + } + + [ConsoleCommand("css_reladmin")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/root")] + public void OnRelAdminCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + + foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList()) + { + if (AdminSQLManager._adminCache.TryRemove(steamId, out _)) + { + AdminManager.ClearPlayerPermissions(steamId); + AdminManager.RemovePlayerAdminData(steamId); + } + } + + AdminSQLManager _adminManager = new(_database); + _ = _adminManager.GiveAllFlags(); + + command.ReplyToCommand("Reloaded sql admins"); + } + + [ConsoleCommand("css_stealth")] + [ConsoleCommand("css_hide")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] + [RequiresPermissions("@css/kick")] + public void OnHideCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null) return; + + if (silentPlayers.Contains(caller.Slot)) + { + RemoveFromConcurrentBag(silentPlayers, caller.Slot); + caller.PrintToChat($"You aren't hidden now!"); + caller.ChangeTeam(CsTeam.Spectator); + } + else + { + silentPlayers.Add(caller.Slot); + Server.ExecuteCommand("sv_disable_teamselect_menu 1"); + Server.NextFrame(() => + { + if (caller.PlayerPawn.Value != null && caller.PawnIsAlive) + caller.PlayerPawn.Value.CommitSuicide(true, false); + + AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + AddTimer(1.15f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + caller.PrintToChat($"You are hidden now!"); + AddTimer(1.22f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); }); + }); + } + } + + [ConsoleCommand("css_who")] + [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/generic")] + public void OnWhoCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + Database database = new Database(dbConnectionString); + BanManager _banManager = new(database, Config); + MuteManager _muteManager = new(_database); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + PlayerInfo playerInfo = new PlayerInfo + { + UserId = player.UserId, + Index = (int)player.Index, + SteamId = player?.SteamID.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + + Task.Run(async () => + { + int totalBans = 0; + int totalMutes = 0; + + totalBans = await _banManager.GetPlayerBans(playerInfo); + totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!); + + Server.NextFrame(() => + { + if (caller != null) + { + caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------"); + + caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\""); + caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\""); + if (playerInfo.SteamId != null) + caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\""); + if (player.SteamID.ToString().Length == 17) + { + caller!.PrintToConsole($"• SteamID2: \"{player.SteamID}\""); + caller!.PrintToConsole($"• Community link: \"{new SteamID(player.SteamID).ToCommunityUrl()}\""); + } + if (playerInfo.IpAddress != null) + caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\""); + caller!.PrintToConsole($"• Ping: \"{player.Ping}\""); + if (player.SteamID.ToString().Length == 17) + { + caller!.PrintToConsole($"• Total Bans: \"{totalBans}\""); + caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\""); + } + + caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------"); + } + else + { + Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------"); + + Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\""); + Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\""); + if (playerInfo.SteamId != null) + Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\""); + if (player.SteamID.ToString().Length == 17) + { + Server.PrintToConsole($"• SteamID2: \"{player.SteamID}\""); + Server.PrintToConsole($"• Community link: \"{new SteamID(player.SteamID).ToCommunityUrl()}\""); + } + if (playerInfo.IpAddress != null) + Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\""); + Server.PrintToConsole($"• Ping: \"{player.Ping}\""); + if (player.SteamID.ToString().Length == 17) + { + Server.PrintToConsole($"• Total Bans: \"{totalBans}\""); + Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\""); + } + + Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------"); + } + }); + }); + } + }); + } + + [ConsoleCommand("css_players")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + [RequiresPermissions("@css/generic")] + public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command) + { + List playersToTarget = Helper.GetValidPlayers(); + + if (caller != null) + { + caller!.PrintToConsole($"--------- PLAYER LIST ---------"); + playersToTarget.ForEach(player => + { + caller!.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.SteamID}\")"); + }); + caller!.PrintToConsole($"--------- END PLAYER LIST ---------"); + } + else + { + Server.PrintToConsole($"--------- PLAYER LIST ---------"); + playersToTarget.ForEach(player => + { + Server.PrintToConsole($"• [#{player.UserId}] \"{player.PlayerName}\" (IP Address: \"{player.IpAddress?.Split(":")[0]}\" SteamID64: \"{player.SteamID}\")"); + }); + Server.PrintToConsole($"--------- END PLAYER LIST ---------"); + } + } + + [ConsoleCommand("css_kick")] + [RequiresPermissions("@css/kick")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + string reason = "Unknown"; + + TargetResult? targets = GetTarget(command); + + if (targets == null) + return; + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) + reason = command.GetArg(2); + + targets.Players.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + if (player.PawnIsAlive) + { + player.Pawn.Value!.Freeze(); + } + + if (command.ArgCount >= 2) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]); + } + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + else + { + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + + if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_kick_message", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_changemap")] + [ConsoleCommand("css_map")] + [RequiresPermissions("@css/changemap")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnMapCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + string _command = string.Empty; + string? map = command.GetCommandString.Split(" ")[1]; + + if (map.StartsWith("ws:")) + { + if (long.TryParse(map.Replace("ws:", ""), out long mapId)) + { + _command = $"host_workshop_map {mapId}"; + } + else + { + _command = $"ds_workshop_changelevel {map.Replace("ws:", "")}"; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + AddTimer(2.0f, () => + { + Server.ExecuteCommand(_command); + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + else + { + if (!Server.IsMapValid(map)) + { + command.ReplyToCommand($"Map {map} not found."); + return; + } + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); + _player.PrintToChat(sb.ToString()); + } + } + } + + if (!map.StartsWith("ws:")) + { + AddTimer(2.0f, () => + { + Server.ExecuteCommand($"changelevel {map}"); + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + } + + [ConsoleCommand("css_changewsmap", "Change workshop map.")] + [ConsoleCommand("css_wsmap", "Change workshop map.")] + [ConsoleCommand("css_workshop", "Change workshop map.")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/changemap")] + public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + string _command = string.Empty; + string? map = command.GetArg(1); + + if (long.TryParse(map, out long mapId)) + { + _command = $"host_workshop_map {mapId}"; + } + else + { + _command = $"ds_workshop_changelevel {map}"; + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_changemap_message", caller == null ? "Console" : caller.PlayerName, map]); + _player.PrintToChat(sb.ToString()); + } + } + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + AddTimer(2.0f, () => + { + Server.ExecuteCommand(_command); + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + + [ConsoleCommand("css_cvar", "Change a cvar.")] + [CommandHelper(2, " ")] + [RequiresPermissions("@css/cvar")] + public void OnCvarCommand(CCSPlayerController? caller, CommandInfo command) + { + var cvar = ConVar.Find(command.GetArg(1)); + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (cvar == null) + { + command.ReplyToCommand($"Cvar \"{command.GetArg(1)}\" not found."); + return; + } + + if (cvar.Name.Equals("sv_cheats") && !AdminManager.PlayerHasPermissions(caller, "@css/cheats")) + { + command.ReplyToCommand($"You don't have permissions to change \"{command.GetArg(1)}\"."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + var value = command.GetArg(2); + + Server.ExecuteCommand($"{cvar.Name} {value}"); + + command.ReplyToCommand($"{playerName} changed cvar {cvar.Name} to {value}."); + Logger.LogInformation($"{playerName} changed cvar {cvar.Name} to {value}."); + } + + [ConsoleCommand("css_rcon", "Run a server console command.")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/rcon")] + public void OnRconCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + Server.ExecuteCommand(command.ArgString); + command.ReplyToCommand($"{playerName} executed command {command.ArgString}."); + Logger.LogInformation($"{playerName} executed command ({command.ArgString})."); + } + } +} diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs new file mode 100644 index 0000000..6f30b63 --- /dev/null +++ b/Commands/basecomms.cs @@ -0,0 +1,944 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Entities; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_gag")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnGagCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + int time = 0; + string reason = "Unknown"; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + PlayerInfo playerInfo = new PlayerInfo + { + SteamId = player?.SteamID.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + Task.Run(async () => + { + await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time); + }); + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); + + if (time == 0) + { + if (!player!.IsBot && !player.IsHLTV) + { + using (new WithTemporaryCulture(player.GetLanguage())) + { + player.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_gag_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player!.IsBot && !player.IsHLTV) + { + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + } + + if (caller == null || caller != null && caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_gag_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + }); + } + + [ConsoleCommand("css_addgag")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.ArgCount < 2) + return; + + if (string.IsNullOrEmpty(command.GetArg(1))) return; + + string steamid = command.GetArg(1); + + if (!Helper.IsValidSteamID64(steamid)) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int time = 0; + string reason = "Unknown"; + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + List matches = Helper.GetPlayerFromSteamid64(steamid); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_gag_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_gag_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); + } + } + _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0); + command.ReplyToCommand($"Gagged player with steamid {steamid}."); + } + + [ConsoleCommand("css_ungag")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.GetArg(1).Length <= 1) + { + command.ReplyToCommand($"Too short pattern to search."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + bool found = false; + + string pattern = command.GetArg(1); + MuteManager _muteManager = new(_database); + + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + if (Helper.IsValidSteamID64(pattern)) + { + List matches = Helper.GetPlayerFromSteamid64(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + + found = true; + } + } + } + else + { + List matches = Helper.GetPlayerFromName(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID.ToString()}"); + + pattern = player!.SteamID.ToString(); + + found = true; + } + } + } + if (found) + { + _ = _muteManager.UnmutePlayer(pattern, 0); // Unmute by type 0 (gag) + command.ReplyToCommand($"Ungaged player with pattern {pattern}."); + return; + } + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (playersToTarget.Count > 1) + { + playersToTarget.ForEach(player => + { + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag); + + if (player!.SteamID.ToString().Length == 17) + _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag) + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + }); + + command.ReplyToCommand($"Ungaged player with pattern {pattern}."); + return; + } + } + + [ConsoleCommand("css_mute")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + int time = 0; + string reason = "Unknown"; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + PlayerInfo playerInfo = new PlayerInfo + { + SteamId = player?.SteamID.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + player!.VoiceFlags = VoiceFlags.Muted; + + Task.Run(async () => + { + await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1); + }); + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_mute_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_mute_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + }); + } + + [ConsoleCommand("css_addmute")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.ArgCount < 2) + return; + if (string.IsNullOrEmpty(command.GetArg(1))) return; + + string steamid = command.GetArg(1); + + if (!Helper.IsValidSteamID64(steamid)) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int time = 0; + string reason = "Unknown"; + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + List matches = Helper.GetPlayerFromSteamid64(steamid); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_mute_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_mute_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + } + _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1); + command.ReplyToCommand($"Muted player with steamid {steamid}."); + } + + [ConsoleCommand("css_unmute")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.GetArg(1).Length <= 1) + { + command.ReplyToCommand($"Too short pattern to search."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string pattern = command.GetArg(1); + bool found = false; + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + if (Helper.IsValidSteamID64(pattern)) + { + List matches = Helper.GetPlayerFromSteamid64(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); + player.VoiceFlags = VoiceFlags.Normal; + found = true; + } + } + } + else + { + List matches = Helper.GetPlayerFromName(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); + player.VoiceFlags = VoiceFlags.Normal; + pattern = player.SteamID.ToString(); + found = true; + } + } + } + + if (found) + { + _ = _muteManager.UnmutePlayer(pattern, 1); // Unmute by type 1 (mute) + command.ReplyToCommand($"Unmuted player with pattern {pattern}."); + return; + } + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (playersToTarget.Count > 1) + { + playersToTarget.ForEach(player => + { + if (player.SteamID.ToString().Length == 17) + _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 1); // Unmute by type 1 (mute) + + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); + player.VoiceFlags = VoiceFlags.Normal; + }); + + command.ReplyToCommand($"Unmuted player with pattern {pattern}."); + return; + } + } + + [ConsoleCommand("css_silence")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnSilenceCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + int time = 0; + string reason = "Unknown"; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + PlayerInfo playerInfo = new PlayerInfo + { + SteamId = player?.SteamID.ToString(), + Name = player?.PlayerName, + IpAddress = player?.IpAddress?.Split(":")[0] + }; + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + Task.Run(async () => + { + await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2); + }); + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time); + + if (time == 0) + { + if (!player!.IsBot && !player.IsHLTV) + { + using (new WithTemporaryCulture(player.GetLanguage())) + { + player.PrintToCenter(_localizer!["sa_player_silence_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_silence_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player!.IsBot && !player.IsHLTV) + { + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_silence_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + } + + if (caller == null || caller != null && caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_silence_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + }); + } + + [ConsoleCommand("css_addsilence")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.ArgCount < 2) + return; + if (string.IsNullOrEmpty(command.GetArg(1))) return; + + string steamid = command.GetArg(1); + + if (!Helper.IsValidSteamID64(steamid)) + { + command.ReplyToCommand($"Invalid SteamID64."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + int time = 0; + string reason = "Unknown"; + + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + int.TryParse(command.GetArg(2), out time); + + if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) + reason = command.GetArg(3); + + PlayerInfo adminInfo = new PlayerInfo + { + SteamId = caller?.SteamID.ToString(), + Name = caller?.PlayerName, + IpAddress = caller?.IpAddress?.Split(":")[0] + }; + + List matches = Helper.GetPlayerFromSteamid64(steamid); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); + + playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time); + + if (time == 0) + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_silence_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_silence_message_perm", playerName, reason]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + else + { + if (!player.IsBot && !player.IsHLTV) + using (new WithTemporaryCulture(player.GetLanguage())) + { + player!.PrintToCenter(_localizer!["sa_player_silence_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); + } + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_silence_message_time", playerName, reason, time]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + } + _ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2); + command.ReplyToCommand($"Silenced player with steamid {steamid}."); + } + + [ConsoleCommand("css_unsilence")] + [RequiresPermissions("@css/chat")] + [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) + { + if (_database == null) return; + string playerName = caller == null ? "Console" : caller.PlayerName; + + if (command.GetArg(1).Length <= 1) + { + command.ReplyToCommand($"Too short pattern to search."); + return; + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + string pattern = command.GetArg(1); + bool found = false; + MuteManager _muteManager = new(_database); + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); + + if (Helper.IsValidSteamID64(pattern)) + { + List matches = Helper.GetPlayerFromSteamid64(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); + player.VoiceFlags = VoiceFlags.Normal; + found = true; + } + } + } + else + { + List matches = Helper.GetPlayerFromName(pattern); + if (matches.Count == 1) + { + CCSPlayerController? player = matches.FirstOrDefault(); + if (player != null && player.IsValid) + { + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); + player.VoiceFlags = VoiceFlags.Normal; + pattern = player.SteamID.ToString(); + found = true; + } + } + } + + if (found) + { + _ = _muteManager.UnmutePlayer(pattern, 2); // Unmute by type 2 (silence) + command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); + return; + } + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); + + if (playersToTarget.Count > 1 && Config.DisableDangerousCommands || playersToTarget.Count == 0) + { + return; + } + + if (playersToTarget.Count > 1) + { + playersToTarget.ForEach(player => + { + if (player.SteamID.ToString().Length == 17) + _ = _muteManager.UnmutePlayer(player.SteamID.ToString(), 2); // Unmute by type 2 (silence) + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + + playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); + player.VoiceFlags = VoiceFlags.Normal; + }); + + command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); + return; + } + } + } +} \ No newline at end of file diff --git a/Commands/basevotes.cs b/Commands/basevotes.cs new file mode 100644 index 0000000..1775d3c --- /dev/null +++ b/Commands/basevotes.cs @@ -0,0 +1,94 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Menu; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_vote")] + [RequiresPermissions("@css/generic")] + [CommandHelper(minArgs: 2, usage: " [... options ...]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + if (command.GetArg(1) == null || command.GetArg(1).Length < 0 || command.ArgCount < 2) + return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + voteAnswers.Clear(); + + string question = command.GetArg(1); + int answersCount = command.ArgCount; + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]); + + for (int i = 2; i <= answersCount - 1; i++) + { + voteAnswers.Add(command.GetArg(i), 0); + voteMenu.AddMenuOption(command.GetArg(i), Helper.handleVotes); + } + + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + + using (new WithTemporaryCulture(_player.GetLanguage())) + { + Helper.PrintToCenterAll(_localizer!["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); + _player.PrintToChat(sb.ToString()); + } + + MenuManager.OpenChatMenu(_player, voteMenu); + } + + voteInProgress = true; + } + + if (voteInProgress) + { + AddTimer(30, () => + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_vote_message_results", question]); + _player.PrintToChat(sb.ToString()); + } + } + + foreach (KeyValuePair kvp in voteAnswers) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_vote_message_results_answer", kvp.Key, kvp.Value]); + _player.PrintToChat(sb.ToString()); + } + } + } + voteAnswers.Clear(); + votePlayers.Clear(); + voteInProgress = false; + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + } + } + } +} diff --git a/Commands/funcommands.cs b/Commands/funcommands.cs new file mode 100644 index 0000000..1213608 --- /dev/null +++ b/Commands/funcommands.cs @@ -0,0 +1,135 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Entities; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_noclip", "Noclip a player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/cheats")] + public void OnNoclipCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && player.PawnIsAlive && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + player!.Pawn.Value!.ToggleNoclip(); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_noclip_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_freeze", "Freeze a player.")] + [CommandHelper(1, "<#userid or name> [duration]")] + [RequiresPermissions("@css/slay")] + public void OnFreezeCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + int.TryParse(command.GetArg(2), out int time); + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + player!.Pawn.Value!.Freeze(); + + if (time > 0) + AddTimer(time, () => player.Pawn.Value!.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_freeze_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_unfreeze", "Unfreeze a player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/slay")] + public void OnUnfreezeCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + player!.Pawn.Value!.Unfreeze(); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_unfreeze_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + }); + } + } +} diff --git a/Commands/playercommands.cs b/Commands/playercommands.cs new file mode 100644 index 0000000..d4f749c --- /dev/null +++ b/Commands/playercommands.cs @@ -0,0 +1,651 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Core.Translations; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Commands.Targeting; +using CounterStrikeSharp.API.Modules.Entities; +using CounterStrikeSharp.API.Modules.Memory; +using CounterStrikeSharp.API.Modules.Utils; +using System.Collections.Concurrent; +using System.Text; + +namespace CS2_SimpleAdmin +{ + public partial class CS2_SimpleAdmin + { + [ConsoleCommand("css_slay")] + [RequiresPermissions("@css/slay")] + [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnSlayCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + player.CommitSuicide(false, true); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_slay_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + }); + } + + [ConsoleCommand("css_give")] + [RequiresPermissions("@css/cheats")] + [CommandHelper(minArgs: 2, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnGiveCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + string weaponName = command.GetArg(2); + + // check if item is typed + if (weaponName == null || weaponName.Length < 5) + { + command.ReplyToCommand($"No weapon typed."); + return; + } + + // check if item is valid + if (!weaponName.Contains("weapon_") && !weaponName.Contains("item_")) + { + command.ReplyToCommand($"{weaponName} is not a valid item."); + return; + } + + // check if weapon is knife + if (weaponName.Contains("_knife") || weaponName.Contains("bayonet")) + { + if (CoreConfig.FollowCS2ServerGuidelines) + { + command.ReplyToCommand($"Cannot Give {weaponName} because it's illegal to be given."); + return; + } + } + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + player.GiveNamedItem(weaponName); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_give_message", playerName, weaponName]); + _player.PrintToChat(sb.ToString()); + } + } + } + }); + } + + [ConsoleCommand("css_strip")] + [RequiresPermissions("@css/slay")] + [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnStripCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + player.RemoveWeapons(); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_strip_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_hp")] + [RequiresPermissions("@css/slay")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnHpCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + int health = 100; + int.TryParse(command.GetArg(2), out health); + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + playersToTarget.ForEach(player => + { + if (caller!.CanTarget(player)) + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + player.SetHp(health); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_hp_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_speed")] + [RequiresPermissions("@css/slay")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnSpeedCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + double speed = 1.0; + double.TryParse(command.GetArg(2), out speed); + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + /* + player.Speed = (float)speed; + player.PlayerPawn.Value!.Speed = (float)speed; + */ + player.SetSpeed((float)speed); + + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_speed_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_god")] + [RequiresPermissions("@css/cheats")] + [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnGodCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + if (player != null) + { + if (!godPlayers.Contains(player.Slot)) + { + godPlayers.Add(player.Slot); + } + else + { + godPlayers = new ConcurrentBag(godPlayers.Where(item => item != player.Slot)); + } + + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_god_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + } + }); + } + + [ConsoleCommand("css_slap")] + [RequiresPermissions("@css/slay")] + [CommandHelper(minArgs: 1, usage: "<#userid or name> [damage]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnSlapCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + int damage = 0; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); + + if (command.ArgCount >= 2) + { + int.TryParse(command.GetArg(2), out damage); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + player!.Pawn.Value!.Slap(damage); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_slap_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_team")] + [RequiresPermissions("@css/kick")] + [CommandHelper(minArgs: 2, usage: "<#userid or name> [] [-k]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnTeamCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + string teamName = command.GetArg(2).ToLower(); + string _teamName; + CsTeam teamNum = CsTeam.Spectator; + + TargetResult? targets = GetTarget(command); + if (targets == null) return; + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + switch (teamName) + { + case "ct": + case "counterterrorist": + teamNum = CsTeam.CounterTerrorist; + _teamName = "CT"; + break; + + case "t": + case "tt": + case "terrorist": + teamNum = CsTeam.Terrorist; + _teamName = "TT"; + break; + + case "swap": + _teamName = "SWAP"; + break; + + default: + teamNum = CsTeam.Spectator; + _teamName = "SPEC"; + break; + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (!teamName.Equals("swap")) + { + if (player.PawnIsAlive && teamNum != CsTeam.Spectator && !command.GetArg(3).ToLower().Equals("-k") && Config.TeamSwitchType == 1) + player.SwitchTeam(teamNum); + else + player.ChangeTeam(teamNum); + } + else + { + if (player.TeamNum != (byte)CsTeam.Spectator) + { + CsTeam teamNum = (CsTeam)player.TeamNum == CsTeam.Terrorist ? CsTeam.CounterTerrorist : CsTeam.Terrorist; + _teamName = teamNum == CsTeam.Terrorist ? "TT" : "CT"; + if (player.PawnIsAlive && !command.GetArg(3).ToLower().Equals("-k") && Config.TeamSwitchType == 1) + { + player.SwitchTeam(teamNum); + } + else + { + player.ChangeTeam(teamNum); + } + } + } + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_team_message", playerName, _teamName]); + _player.PrintToChat(sb.ToString()); + } + } + } + }); + } + + [ConsoleCommand("css_rename", "Rename a player.")] + [CommandHelper(1, "<#userid or name> ")] + [RequiresPermissions("@css/kick")] + public void OnRenameCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + string? newName = command.GetArg(2); + + if (string.IsNullOrEmpty(newName)) + return; + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + player.Rename(newName); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_rename_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_respawn", "Respawn a dead player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/cheats")] + public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo command) + { + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17) + return; + + if (caller!.CanTarget(player)) + { + if (CBasePlayerController_SetPawnFunc == null || player.PlayerPawn.Value == null || !player.PlayerPawn.IsValid) return; + + var playerPawn = player.PlayerPawn.Value; + CBasePlayerController_SetPawnFunc.Invoke(player, playerPawn, true, false); + VirtualFunction.CreateVoid(player.Handle, + GameData.GetOffset("CCSPlayerController_Respawn"))(player); + + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_respawn_message", playerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + + } + }); + } + + [ConsoleCommand("css_tp", "Teleport to a player.")] + [ConsoleCommand("css_tpto", "Teleport to a player.")] + [ConsoleCommand("css_goto", "Teleport to a player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/kick")] + public void OnGotoCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null || !caller.PawnIsAlive) return; + + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + + if (targets == null || targets.Count() > 1) + return; + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive) + return; + + if (caller!.CanTarget(player)) + { + caller!.TeleportPlayer(player); + caller!.Pawn.Value!.ToggleNoclip(); + + AddTimer(3, () => + { + caller!.Pawn.Value!.ToggleNoclip(); + }); + + if (caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_tp_message", caller.PlayerName, player.PlayerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + + [ConsoleCommand("css_bring", "Teleport a player to you.")] + [ConsoleCommand("css_tphere", "Teleport a player to you.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/kick")] + public void OnBringCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null || !caller.PawnIsAlive) return; + + string playerName = caller == null ? "Console" : caller.PlayerName; + + TargetResult? targets = GetTarget(command); + + if (targets == null || targets.Count() > 1) + return; + + List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); + + if (_discordWebhookClientLog != null && _localizer != null) + { + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + } + + playersToTarget.ForEach(player => + { + if (!player.IsBot && player.SteamID.ToString().Length != 17 || !player.PawnIsAlive) + return; + + if (caller!.CanTarget(player)) + { + player!.TeleportPlayer(caller!); + caller!.Pawn.Value!.ToggleNoclip(); + + AddTimer(3, () => + { + caller!.Pawn.Value!.ToggleNoclip(); + }); + + if (caller != null && !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + { + using (new WithTemporaryCulture(_player.GetLanguage())) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_bring_message", caller.PlayerName, player.PlayerName]); + _player.PrintToChat(sb.ToString()); + } + } + } + } + }); + } + } +} diff --git a/Config.cs b/Config.cs index 21b3862..f42f0e2 100644 --- a/Config.cs +++ b/Config.cs @@ -3,9 +3,17 @@ using System.Text.Json.Serialization; namespace CS2_SimpleAdmin { + public class Discord + { + [JsonPropertyName("DiscordLogWebhook")] + public string DiscordLogWebhook { get; set; } = ""; + [JsonPropertyName("DiscordPenaltyWebhook")] + public string DiscordPenaltyWebhook { get; set; } = ""; + } + public class CS2_SimpleAdminConfig : BasePluginConfig { - public override int Version { get; set; } = 5; + public override int Version { get; set; } = 6; [JsonPropertyName("DatabaseHost")] public string DatabaseHost { get; set; } = ""; @@ -34,7 +42,7 @@ namespace CS2_SimpleAdmin [JsonPropertyName("TeamSwitchType")] public int TeamSwitchType { get; set; } = 1; - [JsonPropertyName("DiscordWebhook")] - public string DiscordWebhook { get; set; } = ""; + [JsonPropertyName("Discord")] + public Discord Discord { get; set; } = new Discord(); } } \ No newline at end of file diff --git a/Database.cs b/Database/Database.cs similarity index 100% rename from Database.cs rename to Database/Database.cs diff --git a/database_setup.sql b/Database/database_setup.sql similarity index 100% rename from database_setup.sql rename to Database/database_setup.sql diff --git a/PlayerUtils.cs b/Extensions/PlayerExtensions.cs similarity index 87% rename from PlayerUtils.cs rename to Extensions/PlayerExtensions.cs index 6acdddf..4743278 100644 --- a/PlayerUtils.cs +++ b/Extensions/PlayerExtensions.cs @@ -3,12 +3,12 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Memory; -using CounterStrikeSharp.API.Modules.Utils; using System.Text; +using Vector = CounterStrikeSharp.API.Modules.Utils.Vector; namespace CS2_SimpleAdmin; -public static class PlayerUtils +public static class PlayerExtensions { public static void Slap(this CBasePlayerPawn pawn, int damage = 0) { @@ -137,6 +137,27 @@ public static class PlayerUtils }); } + public static void TeleportPlayer(this CCSPlayerController controller, CCSPlayerController target) + { + if (controller.PlayerPawn?.Value == null && target!.PlayerPawn?.Value == null) + return; + + if ( + controller?.PlayerPawn?.Value?.AbsOrigin != null && + controller?.PlayerPawn?.Value?.AbsRotation != null && + target?.PlayerPawn?.Value?.AbsOrigin != null && + target?.PlayerPawn?.Value?.AbsRotation != null + ) + { + controller.PlayerPawn.Value.Teleport( + target.PlayerPawn.Value.AbsOrigin, + target.PlayerPawn.Value.AbsRotation, + target.PlayerPawn.Value.AbsVelocity + ); + + } + } + private static void PerformSlap(CBasePlayerPawn pawn, int damage = 0) { if (pawn.LifeState != (int)LifeState_t.LIFE_ALIVE) diff --git a/Helper.cs b/Helper.cs index c545fea..6135d8d 100644 --- a/Helper.cs +++ b/Helper.cs @@ -1,10 +1,12 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Menu; using CounterStrikeSharp.API.Modules.Utils; +using Discord; using System.Reflection; using System.Runtime.CompilerServices; using System.Text; @@ -162,6 +164,49 @@ namespace CS2_SimpleAdmin CS2_SimpleAdmin.voteAnswers[option.Text]++; } } + + public static IEnumerable GenerateEmbedsDiscord(string title, string description, string thumbnailUrl, Color color, string[] fieldNames, string[] fieldValues, bool[] inlineFlags) + { + string? hostname = ConVar.Find("hostname")!.StringValue ?? "Unknown"; + string? address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue()}"; + + description = description.Replace("{hostname}", hostname ?? "Unknown"); + description = description.Replace("{address}", address ?? "Unknown"); + + var embed = new EmbedBuilder + { + Title = title, + Description = description, + ThumbnailUrl = thumbnailUrl, + Color = color, + }; + + for (int i = 0; i < fieldNames.Length; i++) + { + fieldValues[i] = fieldValues[i].Replace("{hostname}", hostname ?? "Unknown"); + fieldValues[i] = fieldValues[i].Replace("{address}", address ?? "Unknown"); + + embed.AddField(fieldNames[i], fieldValues[i], inlineFlags[i]); + + if ((i + 1) % 2 == 0 && i < fieldNames.Length - 1) + { + embed.AddField("\u200b", "\u200b", false); + } + } + + return new List { embed.Build() }; + } + + public static string GenerateMessageDiscord(string message) + { + string? hostname = ConVar.Find("hostname")!.StringValue ?? "Unknown"; + string? address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue()}"; + + message = message.Replace("HOSTNAME", hostname); + message = message.Replace("ADDRESS", address); + + return message; + } } public class SchemaString : NativeObject where SchemaClass : NativeObject @@ -186,4 +231,4 @@ namespace CS2_SimpleAdmin return Encoding.ASCII.GetBytes(str); } } -} \ No newline at end of file +} diff --git a/AdminSQLManager.cs b/Managers/AdminSQLManager.cs similarity index 100% rename from AdminSQLManager.cs rename to Managers/AdminSQLManager.cs diff --git a/BanManager.cs b/Managers/BanManager.cs similarity index 100% rename from BanManager.cs rename to Managers/BanManager.cs diff --git a/MuteManager.cs b/Managers/MuteManager.cs similarity index 100% rename from MuteManager.cs rename to Managers/MuteManager.cs diff --git a/PlayerPenaltyManager.cs b/Managers/PlayerPenaltyManager.cs similarity index 100% rename from PlayerPenaltyManager.cs rename to Managers/PlayerPenaltyManager.cs diff --git a/lang/en.json b/lang/en.json index 099961d..4954a0c 100644 --- a/lang/en.json +++ b/lang/en.json @@ -32,6 +32,8 @@ "sa_admin_unfreeze_message": "Admin {lightred}{0}{default} umfreezed {lightred}{1}{default}!", "sa_admin_rename_message": "Admin {lightred}{0}{default} changed {lightred}{1}{default} nickname to {lightred}{2}{default}!", "sa_admin_respawn_message": "Admin {lightred}{0}{default} respawned {lightred}{1}{default}!", + "sa_admin_tp_message": "Admin {lightred}{0}{default} teleported to {lightred}{1}{default}!", + "sa_admin_bring_message": "Admin {lightred}{0}{default} teleported to himself {lightred}{1}{default}!", "sa_admin_team_message": "Admin {lightred}{0}{default} transfered {lightred}{1}{default} to {lightred}{2}{default}!", "sa_admin_vote_menu_title": "{lime}VOTING FOR {gold}{0}", "sa_admin_vote_message": "Admin {lightred}{0}{default} started voting for {lightred}{1}{default}", @@ -39,5 +41,7 @@ "sa_admin_vote_message_results_answer": "{lime}{0} {default}- {gold}{1}", "sa_adminsay_prefix": "{RED}ADMIN: {lightred}{0}{default}", "sa_adminchat_template_admin": "{LIME}(ADMIN) {lightred}{0}{default}: {lightred}{1}{default}", - "sa_adminchat_template_player": "{SILVER}(PLAYER) {lightred}{0}{default}: {lightred}{1}{default}" + "sa_adminchat_template_player": "{SILVER}(PLAYER) {lightred}{0}{default}: {lightred}{1}{default}", + + "sa_discord_log_command": "**{0}** issued command `{1}` on server `HOSTNAME`" } \ No newline at end of file diff --git a/lang/es.json b/lang/es.json index 9c8d680..4a4a605 100644 --- a/lang/es.json +++ b/lang/es.json @@ -30,7 +30,7 @@ "sa_admin_noclip_message": "El administrador {lightred}{0}{default} ha activado noclip para {lightred}{1}{default}.", "sa_admin_freeze_message": "El administrador {lightred}{0}{default} ha congelado a {lightred}{1}{default}.", "sa_admin_unfreeze_message": "El administrador {lightred}{0}{default} ha descongelado a {lightred}{1}{default}.", - "sa_admin_rename_message": "El administrador {lightred}{0}{default} ha cambiado el nombre de {lightred}{1}{default} a {lightred}{2}{default}." + "sa_admin_rename_message": "El administrador {lightred}{0}{default} ha cambiado el nombre de {lightred}{1}{default} a {lightred}{2}{default}.", "sa_admin_respawn_message": "El administrador {lightred}{0}{default} ha respawnado a {lightred}{1}{default}.", "sa_admin_team_message": "El administrador {lightred}{0}{default} ha transferido a {lightred}{1}{default} a {lightred}{2}{default}.", "sa_admin_vote_menu_title": "{lime}VOTACIÓN PARA {gold}{0}", diff --git a/lang/pl.json b/lang/pl.json index f2823f1..289453a 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -32,6 +32,8 @@ "sa_admin_unfreeze_message": "Admin {lightred}{0}{default} odmroził {lightred}{1}{default}!", "sa_admin_rename_message": "Admin {lightred}{0}{default} zmienił nick gracza {lightred}{1}{default} na {lightred}{2}{default}!", "sa_admin_respawn_message": "Admin {lightred}{0}{default} odrodził {lightred}{1}{default}!", + "sa_admin_tp_message": "Admin {lightred}{0}{default} teleportował się do {lightred}{1}{default}!", + "sa_admin_bring_message": "Admin {lightred}{0}{default} teleportował do siebie {lightred}{1}{default}!", "sa_admin_team_message": "Admin {lightred}{0}{default} przerzucił {lightred}{1}{default} do {lightred}{2}{default}!", "sa_admin_vote_menu_title": "{lime}GŁOSOWANIE NA {gold}{0}", "sa_admin_vote_message": "Admin {lightred}{0}{default} rozpoczął głosowanie na {lightred}{1}{default}", @@ -39,5 +41,7 @@ "sa_admin_vote_message_results_answer": "{lime}{0} {default}- {gold}[{1}]", "sa_adminsay_prefix": "{RED}ADMIN: {lightred}{0}{default}", "sa_adminchat_template_admin": "{LIME}(ADMIN) {lightred}{0}{default}: {lightred}{1}{default}", - "sa_adminchat_template_player": "{SILVER}(GRACZ) {lightred}{0}{default}: {lightred}{1}{default}" + "sa_adminchat_template_player": "{SILVER}(GRACZ) {lightred}{0}{default}: {lightred}{1}{default}", + + "sa_discord_log_command": "**{0}** użył komendy `{1}` na serwerze `HOSTNAME`" } \ No newline at end of file From 953234078c0943620f39bd5f0e39c7e81957ca06 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:03:02 +0100 Subject: [PATCH 5/7] 1.3.1a - Added `css_tp` - Added `css_bring` - Added logging commands to discord - Small refactor --- CS2-SimpleAdmin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 72a73a9..11743e6 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -37,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin"; public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy"; - public override string ModuleVersion => "1.3.0f"; + public override string ModuleVersion => "1.3.1a"; public CS2_SimpleAdminConfig Config { get; set; } = new(); From e2df860b6feed4c8c0323bb7e53aef00e820fda3 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:44:05 +0100 Subject: [PATCH 6/7] Update CS2-SimpleAdmin.cs --- CS2-SimpleAdmin.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 11743e6..c11e836 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -85,7 +85,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Date: Mon, 12 Feb 2024 14:11:34 +0100 Subject: [PATCH 7/7] Fix? for messages --- Commands/basebans.cs | 28 ++++++++-------- Commands/basechat.cs | 16 ++++----- Commands/basecommands.cs | 42 +++++++++++------------ Commands/basecomms.cs | 60 ++++++++++++++++----------------- Commands/basevotes.cs | 4 +-- Commands/funcommands.cs | 18 +++++----- Commands/playercommands.cs | 68 +++++++++++++++++++------------------- 7 files changed, 118 insertions(+), 118 deletions(-) diff --git a/Commands/basebans.cs b/Commands/basebans.cs index e9258a2..0580c90 100644 --- a/Commands/basebans.cs +++ b/Commands/basebans.cs @@ -16,7 +16,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnBanCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -34,7 +34,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } Database database = new Database(dbConnectionString); @@ -96,7 +96,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_ban_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -116,7 +116,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_ban_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -131,7 +131,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; if (string.IsNullOrEmpty(command.GetArg(1))) return; @@ -147,7 +147,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string reason = "Unknown"; @@ -197,7 +197,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_ban_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -218,7 +218,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_ban_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -243,7 +243,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnBanIp(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -260,7 +260,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string reason = "Unknown"; @@ -306,7 +306,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_ban_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -326,7 +326,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_ban_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -353,7 +353,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.GetArg(1).Length <= 1) { command.ReplyToCommand($"Too short pattern to search."); @@ -363,7 +363,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string pattern = command.GetArg(1); diff --git a/Commands/basechat.cs b/Commands/basechat.cs index 4d8d855..64a54be 100644 --- a/Commands/basechat.cs +++ b/Commands/basechat.cs @@ -19,12 +19,12 @@ namespace CS2_SimpleAdmin public void OnAdminToAdminSayCommand(CCSPlayerController? caller, CommandInfo command) { if (caller == null || !caller.IsValid || command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName= caller == null ? "Console" : caller.PlayerName; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); @@ -48,14 +48,14 @@ namespace CS2_SimpleAdmin { if (command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName= caller == null ? "Console" : caller.PlayerName; byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } foreach (CCSPlayerController _player in Helper.GetValidPlayers()) @@ -97,14 +97,14 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/chat")] public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName= caller == null ? "Console" : caller.PlayerName; byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } Helper.PrintToCenterAll(Helper.ReplaceTags(utf8String)); @@ -115,14 +115,14 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/chat")] public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName= caller == null ? "Console" : caller.PlayerName; byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } VirtualFunctions.ClientPrintAll( diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index fe04b84..2858c0a 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -66,7 +66,7 @@ namespace CS2_SimpleAdmin public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (!Helper.IsValidSteamID64(command.GetArg(1))) { @@ -87,7 +87,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string steamid = command.GetArg(1); @@ -111,7 +111,7 @@ namespace CS2_SimpleAdmin public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (!Helper.IsValidSteamID64(command.GetArg(1))) { @@ -122,7 +122,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string steamid = command.GetArg(1); @@ -207,7 +207,7 @@ namespace CS2_SimpleAdmin public void OnWhoCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); if (targets == null) return; @@ -215,7 +215,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -333,7 +333,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; string reason = "Unknown"; TargetResult? targets = GetTarget(command); @@ -351,7 +351,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) @@ -390,7 +390,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_kick_message", playerName, reason]); + sb.Append(_localizer["sa_admin_kick_message", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -405,7 +405,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnMapCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; string _command = string.Empty; string? map = command.GetCommandString.Split(" ")[1]; @@ -423,7 +423,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } AddTimer(2.0f, () => @@ -469,7 +469,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/changemap")] public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; string _command = string.Empty; string? map = command.GetArg(1); @@ -498,7 +498,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } AddTimer(2.0f, () => @@ -513,7 +513,7 @@ namespace CS2_SimpleAdmin public void OnCvarCommand(CCSPlayerController? caller, CommandInfo command) { var cvar = ConVar.Find(command.GetArg(1)); - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (cvar == null) { @@ -530,15 +530,15 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } var value = command.GetArg(2); Server.ExecuteCommand($"{cvar.Name} {value}"); - command.ReplyToCommand($"{playerName} changed cvar {cvar.Name} to {value}."); - Logger.LogInformation($"{playerName} changed cvar {cvar.Name} to {value}."); + command.ReplyToCommand($"{callerName} changed cvar {cvar.Name} to {value}."); + Logger.LogInformation($"{callerName} changed cvar {cvar.Name} to {value}."); } [ConsoleCommand("css_rcon", "Run a server console command.")] @@ -546,17 +546,17 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/rcon")] public void OnRconCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } Server.ExecuteCommand(command.ArgString); - command.ReplyToCommand($"{playerName} executed command {command.ArgString}."); - Logger.LogInformation($"{playerName} executed command ({command.ArgString})."); + command.ReplyToCommand($"{callerName} executed command {command.ArgString}."); + Logger.LogInformation($"{callerName} executed command ({command.ArgString})."); } } } diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 6f30b63..2464caa 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -18,7 +18,7 @@ namespace CS2_SimpleAdmin public void OnGagCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int time = 0; string reason = "Unknown"; @@ -35,7 +35,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int.TryParse(command.GetArg(2), out time); @@ -91,7 +91,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_gag_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -114,7 +114,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_gag_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -130,7 +130,7 @@ namespace CS2_SimpleAdmin public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -148,7 +148,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int time = 0; @@ -196,7 +196,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_gag_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -217,7 +217,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_gag_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_gag_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -240,7 +240,7 @@ namespace CS2_SimpleAdmin public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.GetArg(1).Length <= 1) { @@ -251,7 +251,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } bool found = false; @@ -337,7 +337,7 @@ namespace CS2_SimpleAdmin public void OnMuteCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int time = 0; string reason = "Unknown"; @@ -354,7 +354,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int.TryParse(command.GetArg(2), out time); @@ -407,7 +407,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_mute_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -427,7 +427,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_mute_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -443,7 +443,7 @@ namespace CS2_SimpleAdmin public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -460,7 +460,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int time = 0; @@ -509,7 +509,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_mute_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -529,7 +529,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_mute_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_mute_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -547,7 +547,7 @@ namespace CS2_SimpleAdmin public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.GetArg(1).Length <= 1) { @@ -558,7 +558,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string pattern = command.GetArg(1); @@ -633,7 +633,7 @@ namespace CS2_SimpleAdmin public void OnSilenceCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int time = 0; string reason = "Unknown"; @@ -650,7 +650,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int.TryParse(command.GetArg(2), out time); @@ -706,7 +706,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_silence_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -729,7 +729,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_silence_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -745,7 +745,7 @@ namespace CS2_SimpleAdmin public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -762,7 +762,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } int time = 0; @@ -814,7 +814,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_perm", playerName, reason]); + sb.Append(_localizer["sa_admin_silence_message_perm", callerName, player.PlayerName, reason]); _player.PrintToChat(sb.ToString()); } } @@ -834,7 +834,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_silence_message_time", playerName, reason, time]); + sb.Append(_localizer["sa_admin_silence_message_time", callerName, player.PlayerName, reason, time]); _player.PrintToChat(sb.ToString()); } } @@ -852,7 +852,7 @@ namespace CS2_SimpleAdmin public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; if (command.GetArg(1).Length <= 1) { @@ -863,7 +863,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } string pattern = command.GetArg(1); diff --git a/Commands/basevotes.cs b/Commands/basevotes.cs index 1775d3c..6c36606 100644 --- a/Commands/basevotes.cs +++ b/Commands/basevotes.cs @@ -16,14 +16,14 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 2, usage: " [... options ...]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName= caller == null ? "Console" : caller.PlayerName; if (command.GetArg(1) == null || command.GetArg(1).Length < 0 || command.ArgCount < 2) return; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } voteAnswers.Clear(); diff --git a/Commands/funcommands.cs b/Commands/funcommands.cs index 1213608..25fe166 100644 --- a/Commands/funcommands.cs +++ b/Commands/funcommands.cs @@ -16,7 +16,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/cheats")] public void OnNoclipCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -24,7 +24,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -40,7 +40,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_noclip_message", playerName]); + sb.Append(_localizer["sa_admin_noclip_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -54,7 +54,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/slay")] public void OnFreezeCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int.TryParse(command.GetArg(2), out int time); TargetResult? targets = GetTarget(command); @@ -63,7 +63,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -85,7 +85,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_freeze_message", playerName]); + sb.Append(_localizer["sa_admin_freeze_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -99,7 +99,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/slay")] public void OnUnfreezeCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -107,7 +107,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -124,7 +124,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_unfreeze_message", playerName]); + sb.Append(_localizer["sa_admin_unfreeze_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } diff --git a/Commands/playercommands.cs b/Commands/playercommands.cs index d4f749c..d295ba6 100644 --- a/Commands/playercommands.cs +++ b/Commands/playercommands.cs @@ -19,14 +19,14 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnSlayCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); if (targets == null) return; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -46,7 +46,7 @@ namespace CS2_SimpleAdmin { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_slay_message", playerName]); + sb.Append(_localizer["sa_admin_slay_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -59,7 +59,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 2, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnGiveCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); if (targets == null) return; @@ -93,7 +93,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -110,7 +110,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_give_message", playerName, weaponName]); + sb.Append(_localizer["sa_admin_give_message", callerName, player.PlayerName, weaponName]); _player.PrintToChat(sb.ToString()); } } @@ -123,14 +123,14 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnStripCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); if (targets == null) return; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -151,7 +151,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_strip_message", playerName]); + sb.Append(_localizer["sa_admin_strip_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -165,7 +165,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnHpCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int health = 100; int.TryParse(command.GetArg(2), out health); @@ -175,7 +175,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -196,7 +196,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_hp_message", playerName]); + sb.Append(_localizer["sa_admin_hp_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -210,7 +210,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnSpeedCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; double speed = 1.0; double.TryParse(command.GetArg(2), out speed); @@ -220,7 +220,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -246,7 +246,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_speed_message", playerName]); + sb.Append(_localizer["sa_admin_speed_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -260,14 +260,14 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnGodCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); if (targets == null) return; if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -298,7 +298,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_god_message", playerName]); + sb.Append(_localizer["sa_admin_god_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -313,7 +313,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 1, usage: "<#userid or name> [damage]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnSlapCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; int damage = 0; TargetResult? targets = GetTarget(command); @@ -322,7 +322,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -348,7 +348,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_slap_message", playerName]); + sb.Append(_localizer["sa_admin_slap_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -362,7 +362,7 @@ namespace CS2_SimpleAdmin [CommandHelper(minArgs: 2, usage: "<#userid or name> [] [-k]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnTeamCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; string teamName = command.GetArg(2).ToLower(); string _teamName; CsTeam teamNum = CsTeam.Spectator; @@ -373,7 +373,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); @@ -439,7 +439,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_team_message", playerName, _teamName]); + sb.Append(_localizer["sa_admin_team_message", callerName, player.PlayerName, _teamName]); _player.PrintToChat(sb.ToString()); } } @@ -452,7 +452,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/kick")] public void OnRenameCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; string? newName = command.GetArg(2); if (string.IsNullOrEmpty(newName)) @@ -464,7 +464,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -483,7 +483,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_rename_message", playerName]); + sb.Append(_localizer["sa_admin_rename_message", callerName, player.PlayerName, newName]); _player.PrintToChat(sb.ToString()); } } @@ -497,7 +497,7 @@ namespace CS2_SimpleAdmin [RequiresPermissions("@css/cheats")] public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo command) { - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); @@ -505,7 +505,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -529,7 +529,7 @@ namespace CS2_SimpleAdmin using (new WithTemporaryCulture(_player.GetLanguage())) { StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_respawn_message", playerName]); + sb.Append(_localizer["sa_admin_respawn_message", callerName, player.PlayerName]); _player.PrintToChat(sb.ToString()); } } @@ -548,7 +548,7 @@ namespace CS2_SimpleAdmin { if (caller == null || !caller.PawnIsAlive) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); @@ -560,7 +560,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player => @@ -602,7 +602,7 @@ namespace CS2_SimpleAdmin { if (caller == null || !caller.PawnIsAlive) return; - string playerName = caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; TargetResult? targets = GetTarget(command); @@ -614,7 +614,7 @@ namespace CS2_SimpleAdmin if (_discordWebhookClientLog != null && _localizer != null) { string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{playerName}]({communityUrl})", command.GetCommandString])); + _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } playersToTarget.ForEach(player =>