From ac940259f7234179c49b6e2d81c02aa338510544 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Wed, 13 Mar 2024 11:43:33 +0100 Subject: [PATCH 1/8] Moved custom commands to its specific menu --- Menus/AdminMenu.cs | 6 +++++ Menus/CustomCommandsMenu.cs | 47 +++++++++++++++++++++++++++++++++++++ Menus/ManageServerMenu.cs | 14 ----------- 3 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 Menus/CustomCommandsMenu.cs diff --git a/Menus/AdminMenu.cs b/Menus/AdminMenu.cs index a43495f..c3754cb 100644 --- a/Menus/AdminMenu.cs +++ b/Menus/AdminMenu.cs @@ -44,6 +44,12 @@ namespace CS2_SimpleAdmin.Menus new ChatMenuOptionData("Manage Server", () => ManageServerMenu.OpenMenu(admin)), new ChatMenuOptionData("Fun actions", () => FunActionsMenu.OpenMenu(admin)), }; + + List customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands; + if (customCommands.Count > 0) + { + options.Add(new ChatMenuOptionData("Custom Commands", () => CustomCommandsMenu.OpenMenu(admin))); + } if (AdminManager.PlayerHasPermissions(admin, "@css/root")) options.Add(new ChatMenuOptionData("Manage Admins", () => ManageAdminsMenu.OpenMenu(admin))); diff --git a/Menus/CustomCommandsMenu.cs b/Menus/CustomCommandsMenu.cs new file mode 100644 index 0000000..6d0805c --- /dev/null +++ b/Menus/CustomCommandsMenu.cs @@ -0,0 +1,47 @@ +using CounterStrikeSharp.API; +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Menu; + +namespace CS2_SimpleAdmin.Menus +{ + public static class CustomCommandsMenu + { + public static void OpenMenu(CCSPlayerController admin) + { + if (admin == null || admin.IsValid == false) + return; + + if (AdminManager.PlayerHasPermissions(admin, "@css/generic") == false) + { + // TODO: Localize + admin.PrintToChat("[Simple Admin] You do not have permissions to use this command."); + return; + } + + BaseMenu menu = AdminMenu.CreateMenu("Custom Commands"); + List options = new(); + + List customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands; + foreach (CustomServerCommandData customCommand in customCommands) + { + if (string.IsNullOrEmpty(customCommand.DisplayName) || string.IsNullOrEmpty(customCommand.Command)) + continue; + + bool hasRights = AdminManager.PlayerHasPermissions(admin, customCommand.Flag); + if (!hasRights) + continue; + + options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => Server.ExecuteCommand(customCommand.Command))); + } + + foreach (ChatMenuOptionData menuOptionData in options) + { + string menuName = menuOptionData.name; + menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled); + } + + AdminMenu.OpenMenu(admin, menu); + } + } +} diff --git a/Menus/ManageServerMenu.cs b/Menus/ManageServerMenu.cs index 8b19ebb..ea75e80 100644 --- a/Menus/ManageServerMenu.cs +++ b/Menus/ManageServerMenu.cs @@ -1,4 +1,3 @@ -using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Menu; @@ -35,19 +34,6 @@ namespace CS2_SimpleAdmin.Menus options.Add(new ChatMenuOptionData("Restart Game", () => CS2_SimpleAdmin.RestartGame(admin))); - List customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands; - foreach (CustomServerCommandData customCommand in customCommands) - { - if (string.IsNullOrEmpty(customCommand.DisplayName) || string.IsNullOrEmpty(customCommand.Command)) - continue; - - bool hasRights = AdminManager.PlayerHasPermissions(admin, customCommand.Flag); - if (!hasRights) - continue; - - options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => Server.ExecuteCommand(customCommand.Command))); - } - foreach (ChatMenuOptionData menuOptionData in options) { string menuName = menuOptionData.name; From 60c76562f9c7e85343481fcb52773bc00777e596 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Wed, 13 Mar 2024 11:46:09 +0100 Subject: [PATCH 2/8] Added ExecuteOnClient option on custom commands --- Config.cs | 3 +++ Menus/CustomCommandsMenu.cs | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Config.cs b/Config.cs index 5b83208..5f07dc7 100644 --- a/Config.cs +++ b/Config.cs @@ -22,6 +22,9 @@ namespace CS2_SimpleAdmin [JsonPropertyName("Command")] public string Command { get; set; } = ""; + + [JsonPropertyName("ExecuteOnClient")] + public bool ExecuteOnClient { get; set; } = false; } public class CS2_SimpleAdminConfig : BasePluginConfig diff --git a/Menus/CustomCommandsMenu.cs b/Menus/CustomCommandsMenu.cs index 6d0805c..58ebe67 100644 --- a/Menus/CustomCommandsMenu.cs +++ b/Menus/CustomCommandsMenu.cs @@ -31,8 +31,14 @@ namespace CS2_SimpleAdmin.Menus bool hasRights = AdminManager.PlayerHasPermissions(admin, customCommand.Flag); if (!hasRights) continue; - - options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => Server.ExecuteCommand(customCommand.Command))); + + options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => + { + if (customCommand.ExecuteOnClient) + admin.ExecuteClientCommand(customCommand.Command); + else + Server.ExecuteCommand(customCommand.Command); + })); } foreach (ChatMenuOptionData menuOptionData in options) From c6126ab2ec76c1af53e245207524512630253362 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Sat, 16 Mar 2024 11:32:58 +0100 Subject: [PATCH 3/8] Fixed Respawn menu that was disabling dead players instead of alive ones --- Menus/FunActionsMenu.cs | 2 +- Menus/PlayersMenu.cs | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Menus/FunActionsMenu.cs b/Menus/FunActionsMenu.cs index 3e4b60b..4a1879f 100644 --- a/Menus/FunActionsMenu.cs +++ b/Menus/FunActionsMenu.cs @@ -57,7 +57,7 @@ namespace CS2_SimpleAdmin.Menus { options.Add(new ChatMenuOptionData("God Mode", () => PlayersMenu.OpenAliveMenu(admin, "God Mode", GodMode))); options.Add(new ChatMenuOptionData("No Clip", () => PlayersMenu.OpenAliveMenu(admin, "No Clip", NoClip))); - options.Add(new ChatMenuOptionData("Respawn", () => PlayersMenu.OpenAliveMenu(admin, "Respawn", Respawn))); + options.Add(new ChatMenuOptionData("Respawn", () => PlayersMenu.OpenDeadMenu(admin, "Respawn", Respawn))); options.Add(new ChatMenuOptionData("Give Weapon", () => PlayersMenu.OpenAliveMenu(admin, "Give Weapon", GiveWeaponMenu))); } diff --git a/Menus/PlayersMenu.cs b/Menus/PlayersMenu.cs index 3e3d631..de22bb0 100644 --- a/Menus/PlayersMenu.cs +++ b/Menus/PlayersMenu.cs @@ -9,6 +9,11 @@ namespace CS2_SimpleAdmin.Menus { OpenMenu(admin, menuName, onSelectAction, p => p.PawnIsAlive); } + + public static void OpenDeadMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) + { + OpenMenu(admin, menuName, onSelectAction, p => p.PawnIsAlive == false); + } public static void OpenMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) { From 0f4a2835d23ba75637a2b6486016e01bc46d74d8 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Sat, 16 Mar 2024 11:51:44 +0100 Subject: [PATCH 4/8] Added gravity and set money in fun commands menu --- Menus/FunActionsMenu.cs | 66 +++++++++++++++++++++++++++++++++++++++-- Menus/PlayersMenu.cs | 4 +-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Menus/FunActionsMenu.cs b/Menus/FunActionsMenu.cs index 4a1879f..59b8909 100644 --- a/Menus/FunActionsMenu.cs +++ b/Menus/FunActionsMenu.cs @@ -21,7 +21,8 @@ namespace CS2_SimpleAdmin.Menus _weaponsCache = new(); foreach (CsItem item in weaponsArray) { - if (item == CsItem.Tablet) continue; + if (item == CsItem.Tablet) + continue; _weaponsCache[(int)item] = item; } @@ -67,6 +68,8 @@ namespace CS2_SimpleAdmin.Menus options.Add(new ChatMenuOptionData("Freeze", () => PlayersMenu.OpenAliveMenu(admin, "Freeze", Freeze))); options.Add(new ChatMenuOptionData("HP", () => PlayersMenu.OpenAliveMenu(admin, "HP", SetHpMenu))); options.Add(new ChatMenuOptionData("Speed", () => PlayersMenu.OpenAliveMenu(admin, "Speed", SetSpeedMenu))); + options.Add(new ChatMenuOptionData("Gravity", () => PlayersMenu.OpenAliveMenu(admin, "Gravity", SetGravityMenu))); + options.Add(new ChatMenuOptionData("Set Money", () => PlayersMenu.OpenMenu(admin, "Set Money", SetMoneyMenu))); } foreach (ChatMenuOptionData menuOptionData in options) @@ -117,7 +120,8 @@ namespace CS2_SimpleAdmin.Menus private static void Freeze(CCSPlayerController admin, CCSPlayerController player) { - if (!(player.PlayerPawn?.Value?.IsValid ?? false)) return; + if (!(player.PlayerPawn?.Value?.IsValid ?? false)) + return; if (player.PlayerPawn.Value.MoveType != MoveType_t.MOVETYPE_OBSOLETE) CS2_SimpleAdmin.Instance.Freeze(admin, player, -1); @@ -184,5 +188,61 @@ namespace CS2_SimpleAdmin.Menus { CS2_SimpleAdmin.Instance.SetSpeed(admin, player, speed); } + + private static void SetGravityMenu(CCSPlayerController admin, CCSPlayerController player) + { + Tuple[] _gravityArray = new[] + { + new Tuple("0.1", .1f), + new Tuple("0.25", .25f), + new Tuple("0.5", .5f), + new Tuple("0.75", .75f), + new Tuple("1", 1), + new Tuple("2", 2) + }; + + BaseMenu menu = AdminMenu.CreateMenu($"Set Gravity: {player.PlayerName}"); + + foreach (Tuple gravityTuple in _gravityArray) + { + string optionName = gravityTuple.Item1; + menu.AddMenuOption(optionName, (_, _) => { SetGravity(admin, player, gravityTuple.Item2); }); + } + + AdminMenu.OpenMenu(admin, menu); + } + + private static void SetGravity(CCSPlayerController admin, CCSPlayerController player, float gravity) + { + CS2_SimpleAdmin.Instance.SetGravity(admin, player, gravity); + } + + private static void SetMoneyMenu(CCSPlayerController admin, CCSPlayerController player) + { + Tuple[] _moneyArray = new[] + { + new Tuple("$0", 0), + new Tuple("$1000", 1000), + new Tuple("$2500", 2500), + new Tuple("$5000", 5000), + new Tuple("$10000", 10000), + new Tuple("$16000", 16000) + }; + + BaseMenu menu = AdminMenu.CreateMenu($"Set Money: {player.PlayerName}"); + + foreach (Tuple moneyTuple in _moneyArray) + { + string optionName = moneyTuple.Item1; + menu.AddMenuOption(optionName, (_, _) => { SetMoney(admin, player, moneyTuple.Item2); }); + } + + AdminMenu.OpenMenu(admin, menu); + } + + private static void SetMoney(CCSPlayerController admin, CCSPlayerController player, int money) + { + CS2_SimpleAdmin.Instance.SetMoney(admin, player, money); + } } -} \ No newline at end of file +} diff --git a/Menus/PlayersMenu.cs b/Menus/PlayersMenu.cs index de22bb0..c3f8332 100644 --- a/Menus/PlayersMenu.cs +++ b/Menus/PlayersMenu.cs @@ -24,8 +24,8 @@ namespace CS2_SimpleAdmin.Menus { string optionName = player.PlayerName; bool enabled = admin.CanTarget(player); - if (enableFilter != null) - enabled &= enableFilter(player); + if (enableFilter != null && enableFilter(player) == false) + continue; menu.AddMenuOption(optionName, (_, _) => { onSelectAction?.Invoke(admin, player); }, enabled == false); } From 90c0564f56caa27e8c6d41858f428080de0c7899 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Sat, 16 Mar 2024 16:01:26 +0100 Subject: [PATCH 5/8] Discord webhook from menus --- Commands/basebans.cs | 10 +-- Commands/basecommands.cs | 71 ++++++++--------- Commands/basecomms.cs | 36 +++------ Commands/funcommands.cs | 30 +++----- Commands/playercommands.cs | 149 +++++++++++++----------------------- Helper.cs | 13 ++++ Menus/CustomCommandsMenu.cs | 2 + 7 files changed, 123 insertions(+), 188 deletions(-) diff --git a/Commands/basebans.cs b/Commands/basebans.cs index 20b411b..094e711 100644 --- a/Commands/basebans.cs +++ b/Commands/basebans.cs @@ -31,12 +31,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - Database database = new Database(dbConnectionString); BanManager _banManager = new(database, Config); @@ -80,7 +74,9 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, $"css_ban {player.SteamID} {time} {reason}"); + string commandName = $"css_ban {player.SteamID} {time} {reason}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); Task.Run(async () => { diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index ff564a6..b4033fb 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -109,12 +109,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - string steamid = command.GetArg(1); string name = command.GetArg(2); string flags = command.GetArg(3); @@ -133,7 +127,9 @@ namespace CS2_SimpleAdmin AdminSQLManager _adminManager = new(_database); _ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin); - Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}"); + string commandName = $"css_addadmin {steamid} {name} {flags} {immunity} {time}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); string msg = $"Added '{flags}' flags to '{name}' ({steamid})"; if (command != null) @@ -158,12 +154,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - string steamid = command.GetArg(1); bool globalDelete = command.GetArg(2).ToLower().Equals("-g"); @@ -190,7 +180,9 @@ namespace CS2_SimpleAdmin } }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - Helper.LogCommand(caller, $"css_deladmin {steamid}"); + string commandName = $"css_deladmin {steamid}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); string msg = $"Removed flags from '{steamid}'"; if (command != null) @@ -208,15 +200,18 @@ namespace CS2_SimpleAdmin { if (_database == null) return; - ReloadAdmins(); + ReloadAdmins(caller); command.ReplyToCommand("Reloaded sql admins"); } - public void ReloadAdmins() + public void ReloadAdmins(CCSPlayerController? caller) { if (_database == null) return; - + + string commandName = "css_reladmin"; + Helper.TryLogCommandOnDiscord(caller, commandName); + foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList()) { if (AdminSQLManager._adminCache.TryRemove(steamId, out _)) @@ -384,12 +379,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) reason = command.GetArg(2); @@ -414,8 +403,10 @@ namespace CS2_SimpleAdmin } reason = reason ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; - - Helper.LogCommand(caller, $"css_kick {player.PlayerName} {reason}"); + + string commandName = $"css_kick {player.PlayerName} {reason}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); if (string.IsNullOrEmpty(reason) == false) { @@ -475,12 +466,8 @@ namespace CS2_SimpleAdmin _command = $"ds_workshop_changelevel {map.Replace("ws:", "")}"; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - string commandName = command?.GetCommandString ?? "css_changemap"; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - } + string commandName = command?.GetCommandString ?? $"css_changewsmap {map}"; + Helper.TryLogCommandOnDiscord(caller, commandName); if (command is not null) Helper.LogCommand(caller, command); @@ -519,6 +506,9 @@ namespace CS2_SimpleAdmin if (!map.StartsWith("ws:")) { + string commandName = command?.GetCommandString ?? $"css_changemap {map}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + AddTimer(2.0f, () => { Server.ExecuteCommand($"changelevel {map}"); @@ -565,13 +555,9 @@ namespace CS2_SimpleAdmin } } } - - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - string commandName = command?.GetCommandString ?? "css_changewsmap"; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - } + + string commandName = command?.GetCommandString ?? $"css_changewsmap {map}"; + Helper.TryLogCommandOnDiscord(caller, commandName); if (command is not null) Helper.LogCommand(caller, command); @@ -650,10 +636,13 @@ namespace CS2_SimpleAdmin public static void RestartGame(CCSPlayerController? admin) { - Helper.LogCommand(admin, "css_restartgame"); - // TODO: Localize - var name = admin == null ? "Console" : admin.PlayerName; + string name = admin == null ? "Console" : admin.PlayerName; + + string commandName = "css_restartgame"; + Helper.TryLogCommandOnDiscord(admin, commandName); + Helper.LogCommand(admin, commandName); + Server.PrintToChatAll($"[SA] {name}: Restarting game..."); Server.ExecuteCommand("mp_restartgame 2"); } diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 1a56e49..e7e57f4 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -32,12 +32,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -75,8 +69,10 @@ namespace CS2_SimpleAdmin Name = caller?.PlayerName, IpAddress = caller?.IpAddress?.Split(":")[0] }; - - Helper.LogCommand(caller, $"css_gag {player?.SteamID} {time} {reason}"); + + string commandName = $"css_gag {player?.SteamID} {time} {reason}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); Task.Run(async () => { @@ -387,12 +383,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -430,8 +420,10 @@ namespace CS2_SimpleAdmin Name = caller?.PlayerName, IpAddress = caller?.IpAddress?.Split(":")[0] }; - - Helper.LogCommand(caller, $"css_mute {player?.SteamID} {time} {reason}"); + + string commandName = $"css_mute {player?.SteamID} {time} {reason}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); player!.VoiceFlags = VoiceFlags.Muted; @@ -716,12 +708,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -759,8 +745,10 @@ namespace CS2_SimpleAdmin Name = caller?.PlayerName, IpAddress = caller?.IpAddress?.Split(":")[0] }; - - Helper.LogCommand(caller, $"css_silence {player?.SteamID} {time} {reason}"); + + string commandName = $"css_silence {player?.SteamID} {time} {reason}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); Task.Run(async () => { diff --git a/Commands/funcommands.cs b/Commands/funcommands.cs index 9f82bf4..6d32789 100644 --- a/Commands/funcommands.cs +++ b/Commands/funcommands.cs @@ -21,12 +21,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - playersToTarget.ForEach(player => { if (caller!.CanTarget(player)) @@ -41,7 +35,9 @@ namespace CS2_SimpleAdmin callerName ??= caller == null ? "Console" : caller.PlayerName; player!.Pawn.Value!.ToggleNoclip(); - Helper.LogCommand(caller, $"css_noclip {player.PlayerName}"); + string commandName = $"css_noclip {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -68,12 +64,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) @@ -92,7 +82,9 @@ namespace CS2_SimpleAdmin player.Pawn.Value!.Freeze(); - Helper.LogCommand(caller, $"css_freeze {player.PlayerName}"); + string commandName = $"css_freeze {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (time > 0) AddTimer(time, () => player.Pawn.Value!.Unfreeze(), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); @@ -121,12 +113,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) @@ -142,7 +128,9 @@ namespace CS2_SimpleAdmin player!.Pawn.Value!.Unfreeze(); - Helper.LogCommand(caller, $"css_unfreeze {player.PlayerName}"); + string commandName = $"css_unfreeze {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { diff --git a/Commands/playercommands.cs b/Commands/playercommands.cs index 089e84d..598db7e 100644 --- a/Commands/playercommands.cs +++ b/Commands/playercommands.cs @@ -23,12 +23,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -46,7 +40,9 @@ namespace CS2_SimpleAdmin player.CommitSuicide(false, true); - Helper.LogCommand(caller, $"css_slay {player.PlayerName}"); + string commandName = $"css_slay {player.PlayerName}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -98,12 +94,6 @@ 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) @@ -132,7 +122,11 @@ namespace CS2_SimpleAdmin public void SubGiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; - + + string commandName = $"css_give {player.PlayerName} {weaponName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); + if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { foreach (CCSPlayerController _player in Helper.GetValidPlayers()) @@ -156,12 +150,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -182,7 +170,9 @@ namespace CS2_SimpleAdmin player.RemoveWeapons(); - Helper.LogCommand(caller, $"css_strip {player.PlayerName}"); + string commandName = $"css_strip {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -210,12 +200,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -236,7 +220,9 @@ namespace CS2_SimpleAdmin player.SetHp(health); - Helper.LogCommand(caller, $"css_hp {player.PlayerName} {health}"); + string commandName = $"css_hp {player.PlayerName} {health}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -264,12 +250,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -290,7 +270,9 @@ namespace CS2_SimpleAdmin player.SetSpeed((float)speed); - Helper.LogCommand(caller, $"css_speed {player?.PlayerName} {speed}"); + string commandName = $"css_speed {player?.PlayerName} {speed}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -318,12 +300,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -344,7 +320,9 @@ namespace CS2_SimpleAdmin player.SetGravity((float)gravity); - Helper.LogCommand(caller, $"css_gravity {player?.PlayerName} {gravity}"); + string commandName = $"css_gravity {player?.PlayerName} {gravity}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -372,12 +350,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -398,7 +370,9 @@ namespace CS2_SimpleAdmin player.SetMoney(money); - Helper.LogCommand(caller, $"css_money {player?.PlayerName} {money}"); + string commandName = $"css_money {player?.PlayerName} {money}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -423,12 +397,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -447,29 +415,31 @@ namespace CS2_SimpleAdmin { callerName ??= caller == null ? "Console" : caller.PlayerName; - if (player != null) + if (player == null || player.IsValid == false) + return; + + string commandName = $"css_god {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, callerName); + + if (!godPlayers.Contains(player.Slot)) { - Helper.LogCommand(caller, $"css_god {player.PlayerName}"); + godPlayers.Add(player.Slot); + } + else + { + RemoveFromConcurrentBag(godPlayers, player.Slot); + } - if (!godPlayers.Contains(player.Slot)) + if (caller == null || !silentPlayers.Contains(caller.Slot)) + { + foreach (CCSPlayerController _player in Helper.GetValidPlayers()) { - godPlayers.Add(player.Slot); - } - else - { - RemoveFromConcurrentBag(godPlayers, player.Slot); - } - - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) - { - foreach (CCSPlayerController _player in Helper.GetValidPlayers()) + using (new WithTemporaryCulture(_player.GetLanguage())) { - using (new WithTemporaryCulture(_player.GetLanguage())) - { - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_god_message", callerName, player.PlayerName]); - _player.PrintToChat(sb.ToString()); - } + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_god_message", callerName, player.PlayerName]); + _player.PrintToChat(sb.ToString()); } } } @@ -486,12 +456,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); if (command.ArgCount >= 2) @@ -516,7 +480,9 @@ namespace CS2_SimpleAdmin callerName ??= caller == null ? "Console" : caller.PlayerName; player!.Pawn.Value!.Slap(damage); - Helper.LogCommand(caller, $"css_slap {player.PlayerName} {damage}"); + string commandName = $"css_slap {player.PlayerName} {damage}"; + Helper.LogCommand(caller, callerName); + Helper.TryLogCommandOnDiscord(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -545,12 +511,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); switch (teamName) @@ -594,6 +554,9 @@ namespace CS2_SimpleAdmin return; callerName ??= caller == null ? "Console" : caller.PlayerName; + string commandName = $"css_team {player.PlayerName} {teamName} {teamNum} {kill}"; + Helper.LogCommand(caller, commandName); + Helper.TryLogCommandOnDiscord(caller, commandName); if (!teamName.Equals("swap")) { @@ -690,12 +653,6 @@ namespace CS2_SimpleAdmin 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", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) @@ -714,12 +671,14 @@ namespace CS2_SimpleAdmin if (CBasePlayerController_SetPawnFunc == null || player.PlayerPawn.Value == null || !player.PlayerPawn.IsValid) return; - var playerPawn = player.PlayerPawn.Value; + CCSPlayerPawn? playerPawn = player.PlayerPawn.Value; CBasePlayerController_SetPawnFunc.Invoke(player, playerPawn, true, false); VirtualFunction.CreateVoid(player.Handle, GameData.GetOffset("CCSPlayerController_Respawn"))(player); - Helper.LogCommand(caller, $"css_respawn {player.PlayerName}"); + string commandName = $"css_respawn {player.PlayerName}"; + Helper.TryLogCommandOnDiscord(caller, commandName); + Helper.LogCommand(caller, commandName); if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { diff --git a/Helper.cs b/Helper.cs index 51e7548..32d9962 100644 --- a/Helper.cs +++ b/Helper.cs @@ -223,6 +223,19 @@ namespace CS2_SimpleAdmin var updatedJsonContent = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping }); File.WriteAllText(CfgPath, updatedJsonContent); } + + public static void TryLogCommandOnDiscord(CCSPlayerController? caller, string commandString) + { + if (CS2_SimpleAdmin._discordWebhookClientLog == null || CS2_SimpleAdmin._localizer == null) + return; + + if (caller != null && caller.IsValid == false) + caller = null; + + string callerName = caller == null ? "Console" : caller.PlayerName; + string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + CS2_SimpleAdmin._discordWebhookClientLog.SendMessageAsync(GenerateMessageDiscord(CS2_SimpleAdmin._localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandString])); + } } public class SchemaString : NativeObject where SchemaClass : NativeObject diff --git a/Menus/CustomCommandsMenu.cs b/Menus/CustomCommandsMenu.cs index 58ebe67..dd1d9d1 100644 --- a/Menus/CustomCommandsMenu.cs +++ b/Menus/CustomCommandsMenu.cs @@ -34,6 +34,8 @@ namespace CS2_SimpleAdmin.Menus options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => { + Helper.TryLogCommandOnDiscord(admin, customCommand.Command); + if (customCommand.ExecuteOnClient) admin.ExecuteClientCommand(customCommand.Command); else From aac5caa5652c980cf46bbe4ed9da7de4260e0204 Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Sat, 16 Mar 2024 16:02:04 +0100 Subject: [PATCH 6/8] fixed typo in freeze --- lang/en.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/en.json b/lang/en.json index f4666b0..dfb7116 100644 --- a/lang/en.json +++ b/lang/en.json @@ -31,8 +31,8 @@ "sa_admin_slap_message": "Admin {lightred}{0}{default} slapped {lightred}{1}{default}!", "sa_admin_changemap_message": "Admin {lightred}{0}{default} changed map to {lightred}{1}{default}!", "sa_admin_noclip_message": "Admin {lightred}{0}{default} toggled noclip for {lightred}{1}{default}!", - "sa_admin_freeze_message": "Admin {lightred}{0}{default} freezed {lightred}{1}{default}!", - "sa_admin_unfreeze_message": "Admin {lightred}{0}{default} umfreezed {lightred}{1}{default}!", + "sa_admin_freeze_message": "Admin {lightred}{0}{default} froze {lightred}{1}{default}!", + "sa_admin_unfreeze_message": "Admin {lightred}{0}{default} unfroze {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}!", From 0cca38b10b57ba56e2b300ce350f5ab6065ba34c Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Sat, 16 Mar 2024 16:08:28 +0100 Subject: [PATCH 7/8] Improved player selection in menus --- Menus/ManageAdminsMenu.cs | 10 +++++----- Menus/ManagePlayersMenu.cs | 8 ++++---- Menus/PlayersMenu.cs | 14 +++++++++++++- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Menus/ManageAdminsMenu.cs b/Menus/ManageAdminsMenu.cs index c7cfbff..ac4127f 100644 --- a/Menus/ManageAdminsMenu.cs +++ b/Menus/ManageAdminsMenu.cs @@ -24,9 +24,9 @@ namespace CS2_SimpleAdmin.Menus // TODO: Localize options // options added in order - options.Add(new ChatMenuOptionData("Add Admin", () => PlayersMenu.OpenAliveMenu(admin, "Add Admin", AddAdminMenu))); - options.Add(new ChatMenuOptionData("Remove Admin", () => PlayersMenu.OpenAliveMenu(admin, "Remove Admin", RemoveAdmin, player => player != admin && admin.CanTarget(player)))); - options.Add(new ChatMenuOptionData("Reload Admins", ReloadAdmins)); + options.Add(new ChatMenuOptionData("Add Admin", () => PlayersMenu.OpenRealPlayersMenu(admin, "Add Admin", AddAdminMenu))); + options.Add(new ChatMenuOptionData("Remove Admin", () => PlayersMenu.OpenAdminPlayersMenu(admin, "Remove Admin", RemoveAdmin, player => player != admin && admin.CanTarget(player)))); + options.Add(new ChatMenuOptionData("Reload Admins", () => ReloadAdmins(admin))); foreach (ChatMenuOptionData menuOptionData in options) { @@ -77,9 +77,9 @@ namespace CS2_SimpleAdmin.Menus CS2_SimpleAdmin.Instance.RemoveAdmin(admin, player.SteamID.ToString()); } - private static void ReloadAdmins() + private static void ReloadAdmins(CCSPlayerController admin) { - CS2_SimpleAdmin.Instance.ReloadAdmins(); + CS2_SimpleAdmin.Instance.ReloadAdmins(admin); } } } \ No newline at end of file diff --git a/Menus/ManagePlayersMenu.cs b/Menus/ManagePlayersMenu.cs index 33a44fc..399080f 100644 --- a/Menus/ManagePlayersMenu.cs +++ b/Menus/ManagePlayersMenu.cs @@ -44,14 +44,14 @@ namespace CS2_SimpleAdmin.Menus if (hasBan) { - options.Add(new ChatMenuOptionData("Ban", () => PlayersMenu.OpenMenu(admin, "Ban", (admin, player) => DurationMenu.OpenMenu(admin, $"Ban: {player.PlayerName}", player, BanMenu)))); + options.Add(new ChatMenuOptionData("Ban", () => PlayersMenu.OpenRealPlayersMenu(admin, "Ban", (admin, player) => DurationMenu.OpenMenu(admin, $"Ban: {player.PlayerName}", player, BanMenu)))); } if (hasChat) { - options.Add(new ChatMenuOptionData("Gag", () => PlayersMenu.OpenMenu(admin, "Gag", (admin, player) => DurationMenu.OpenMenu(admin, $"Gag: {player.PlayerName}", player, GagMenu)))); - options.Add(new ChatMenuOptionData("Mute", () => PlayersMenu.OpenMenu(admin, "Mute", (admin, player) => DurationMenu.OpenMenu(admin, $"Mute: {player.PlayerName}", player, MuteMenu)))); - options.Add(new ChatMenuOptionData("Silence", () => PlayersMenu.OpenMenu(admin, "Silence", (admin, player) => DurationMenu.OpenMenu(admin, $"Silence: {player.PlayerName}", player, SilenceMenu)))); + options.Add(new ChatMenuOptionData("Gag", () => PlayersMenu.OpenRealPlayersMenu(admin, "Gag", (admin, player) => DurationMenu.OpenMenu(admin, $"Gag: {player.PlayerName}", player, GagMenu)))); + options.Add(new ChatMenuOptionData("Mute", () => PlayersMenu.OpenRealPlayersMenu(admin, "Mute", (admin, player) => DurationMenu.OpenMenu(admin, $"Mute: {player.PlayerName}", player, MuteMenu)))); + options.Add(new ChatMenuOptionData("Silence", () => PlayersMenu.OpenRealPlayersMenu(admin, "Silence", (admin, player) => DurationMenu.OpenMenu(admin, $"Silence: {player.PlayerName}", player, SilenceMenu)))); } if (hasKick) diff --git a/Menus/PlayersMenu.cs b/Menus/PlayersMenu.cs index c3f8332..8fd20f4 100644 --- a/Menus/PlayersMenu.cs +++ b/Menus/PlayersMenu.cs @@ -1,10 +1,21 @@ using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Menu; namespace CS2_SimpleAdmin.Menus { public static class PlayersMenu { + public static void OpenRealPlayersMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) + { + OpenMenu(admin, menuName, onSelectAction, p => p.IsBot == false); + } + + public static void OpenAdminPlayersMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) + { + OpenMenu(admin, menuName, onSelectAction, p => AdminManager.GetPlayerAdminData(p)?.Flags?.Count > 0); + } + public static void OpenAliveMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) { OpenMenu(admin, menuName, onSelectAction, p => p.PawnIsAlive); @@ -23,9 +34,10 @@ namespace CS2_SimpleAdmin.Menus foreach (CCSPlayerController player in players) { string optionName = player.PlayerName; - bool enabled = admin.CanTarget(player); if (enableFilter != null && enableFilter(player) == false) continue; + + bool enabled = admin.CanTarget(player); menu.AddMenuOption(optionName, (_, _) => { onSelectAction?.Invoke(admin, player); }, enabled == false); } From 39404e52ac932b9ed7b914eac936cd40a72a14fb Mon Sep 17 00:00:00 2001 From: Valentin Barat Date: Thu, 21 Mar 2024 23:36:56 +0100 Subject: [PATCH 8/8] Fixed hmtl-incompatible player names --- Menus/PlayersMenu.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Menus/PlayersMenu.cs b/Menus/PlayersMenu.cs index 8fd20f4..7d0525f 100644 --- a/Menus/PlayersMenu.cs +++ b/Menus/PlayersMenu.cs @@ -1,3 +1,4 @@ +using System.Web; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Menu; @@ -10,17 +11,17 @@ namespace CS2_SimpleAdmin.Menus { OpenMenu(admin, menuName, onSelectAction, p => p.IsBot == false); } - + public static void OpenAdminPlayersMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) { OpenMenu(admin, menuName, onSelectAction, p => AdminManager.GetPlayerAdminData(p)?.Flags?.Count > 0); } - + public static void OpenAliveMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) { OpenMenu(admin, menuName, onSelectAction, p => p.PawnIsAlive); } - + public static void OpenDeadMenu(CCSPlayerController admin, string menuName, Action onSelectAction, Func? enableFilter = null) { OpenMenu(admin, menuName, onSelectAction, p => p.PawnIsAlive == false); @@ -33,10 +34,10 @@ namespace CS2_SimpleAdmin.Menus IEnumerable players = Helper.GetValidPlayersWithBots(); foreach (CCSPlayerController player in players) { - string optionName = player.PlayerName; + string optionName = HttpUtility.HtmlEncode(player.PlayerName); if (enableFilter != null && enableFilter(player) == false) continue; - + bool enabled = admin.CanTarget(player); menu.AddMenuOption(optionName, (_, _) => { onSelectAction?.Invoke(admin, player); }, enabled == false); } @@ -44,4 +45,4 @@ namespace CS2_SimpleAdmin.Menus AdminMenu.OpenMenu(admin, menu); } } -} \ No newline at end of file +}