From 32520c7e841c8f2d2d3ed0a9b0082741fac6ac1b Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Sun, 29 Sep 2024 18:29:04 +0200 Subject: [PATCH] 1.6.1a :new: **What's new and what's changed:** ```diff + Added `css_hidecomms` command - Disable showing penalties when player connect + Added customizable commands in `Commands.json` file in plugin config directory - U can disable command by removing aliases or rename/add more aliases (remember to not remove key, edit only Aliases) + Added missing `Console` translation `sa_console` + Added `LogCommand` to api ``` --- CS2-SimpleAdmin/Api/CS2_SimpleAdminApi.cs | 11 + CS2-SimpleAdmin/CS2-SimpleAdmin.cs | 10 +- CS2-SimpleAdmin/Commands/RegisterCommands.cs | 208 +++++++++++++++++++ CS2-SimpleAdmin/Commands/basebans.cs | 22 +- CS2-SimpleAdmin/Commands/basechat.cs | 10 +- CS2-SimpleAdmin/Commands/basecommands.cs | 70 +++---- CS2-SimpleAdmin/Commands/basecomms.cs | 33 ++- CS2-SimpleAdmin/Commands/basevotes.cs | 5 +- CS2-SimpleAdmin/Commands/funcommands.cs | 20 +- CS2-SimpleAdmin/Commands/playercommands.cs | 66 +++--- CS2-SimpleAdmin/Helper.cs | 18 +- CS2-SimpleAdmin/Managers/BanManager.cs | 12 +- CS2-SimpleAdmin/Managers/MuteManager.cs | 8 +- CS2-SimpleAdmin/Managers/PlayerManager.cs | 33 +-- CS2-SimpleAdmin/Managers/WarnManager.cs | 8 +- CS2-SimpleAdmin/VERSION | 2 +- CS2-SimpleAdmin/Variables.cs | 28 ++- CS2-SimpleAdmin/lang/en.json | 1 + CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs | 3 + 19 files changed, 361 insertions(+), 207 deletions(-) create mode 100644 CS2-SimpleAdmin/Commands/RegisterCommands.cs diff --git a/CS2-SimpleAdmin/Api/CS2_SimpleAdminApi.cs b/CS2-SimpleAdmin/Api/CS2_SimpleAdminApi.cs index 89a704f..c66c344 100644 --- a/CS2-SimpleAdmin/Api/CS2_SimpleAdminApi.cs +++ b/CS2-SimpleAdmin/Api/CS2_SimpleAdminApi.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Entities; using CS2_SimpleAdmin.Managers; using CS2_SimpleAdminApi; @@ -72,4 +73,14 @@ public void IssuePenalty(CCSPlayerController player, CCSPlayerController? admin, throw new ArgumentOutOfRangeException(nameof(penaltyType), penaltyType, null); } } + + public void LogCommand(CCSPlayerController? caller, string command) + { + Helper.LogCommand(caller, command); + } + + public void LogCommand(CCSPlayerController? caller, CommandInfo command) + { + Helper.LogCommand(caller, command); + } } \ No newline at end of file diff --git a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs index 6c6d083..405d6e4 100644 --- a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; using CounterStrikeSharp.API.Core.Capabilities; +using CounterStrikeSharp.API.Core.Commands; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions; @@ -20,7 +21,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)"); public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy & Dliix66"; - public override string ModuleVersion => "1.6.0a"; + public override string ModuleVersion => "1.6.1a"; public CS2_SimpleAdminConfig Config { get; set; } = new(); @@ -60,6 +61,8 @@ public override void OnAllPluginsLoaded(bool hotReload) MenuApi = MenuCapability.Get(); if (MenuApi == null) Logger.LogError("MenuManager Core not found..."); + + RegisterCommands.InitializeCommands(); } public void OnConfigParsed(CS2_SimpleAdminConfig config) @@ -71,7 +74,7 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config) Instance = this; _logger = Logger; - + MySqlConnectionStringBuilder builder = new() { Server = config.DatabaseHost, @@ -112,9 +115,6 @@ public void OnConfigParsed(CS2_SimpleAdminConfig config) PluginInfo.ShowAd(ModuleVersion); if (Config.EnableUpdateCheck) Task.Run(async () => await PluginInfo.CheckVersion(ModuleVersion, _logger)); - - AddCommand($"css_last{Config.OtherSettings.DisconnectedPlayersHistoryCount}", - "Show last x disconnected players", OnDisconnectedCommand); } private static TargetResult? GetTarget(CommandInfo command) diff --git a/CS2-SimpleAdmin/Commands/RegisterCommands.cs b/CS2-SimpleAdmin/Commands/RegisterCommands.cs new file mode 100644 index 0000000..9c64469 --- /dev/null +++ b/CS2-SimpleAdmin/Commands/RegisterCommands.cs @@ -0,0 +1,208 @@ +using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Commands; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace CS2_SimpleAdmin; + +public static class RegisterCommands +{ + private delegate void CommandCallback(CCSPlayerController? caller, CommandInfo.CommandCallback callback); + + private static readonly string CommandsPath = Path.Combine(CS2_SimpleAdmin.ConfigDirectory, "Commands.json"); + private static readonly List CommandMappings = + [ + new CommandMapping("css_ban", CS2_SimpleAdmin.Instance.OnBanCommand), + new CommandMapping("css_addban", CS2_SimpleAdmin.Instance.OnAddBanCommand), + new CommandMapping("css_banip", CS2_SimpleAdmin.Instance.OnBanIpCommand), + new CommandMapping("css_unban", CS2_SimpleAdmin.Instance.OnUnbanCommand), + new CommandMapping("css_warn", CS2_SimpleAdmin.Instance.OnWarnCommand), + new CommandMapping("css_unwarn", CS2_SimpleAdmin.Instance.OnUnwarnCommand), + + new CommandMapping("css_asay", CS2_SimpleAdmin.Instance.OnAdminToAdminSayCommand), + new CommandMapping("css_cssay", CS2_SimpleAdmin.Instance.OnAdminCustomSayCommand), + new CommandMapping("css_say", CS2_SimpleAdmin.Instance.OnAdminSayCommand), + new CommandMapping("css_psay", CS2_SimpleAdmin.Instance.OnAdminPrivateSayCommand), + new CommandMapping("css_csay", CS2_SimpleAdmin.Instance.OnAdminCenterSayCommand), + new CommandMapping("css_hsay", CS2_SimpleAdmin.Instance.OnAdminHudSayCommand), + + new CommandMapping("css_penalties", CS2_SimpleAdmin.Instance.OnPenaltiesCommand), + new CommandMapping("css_admin", CS2_SimpleAdmin.Instance.OnAdminCommand), + new CommandMapping("css_adminhelp", CS2_SimpleAdmin.Instance.OnAdminHelpCommand), + new CommandMapping("css_addadmin", CS2_SimpleAdmin.Instance.OnAddAdminCommand), + new CommandMapping("css_deladmin", CS2_SimpleAdmin.Instance.OnDelAdminCommand), + new CommandMapping("css_addgroup", CS2_SimpleAdmin.Instance.OnAddGroup), + new CommandMapping("css_delgroup", CS2_SimpleAdmin.Instance.OnDelGroupCommand), + new CommandMapping("css_reloadadmins", CS2_SimpleAdmin.Instance.OnRelAdminCommand), + new CommandMapping("css_hide", CS2_SimpleAdmin.Instance.OnHideCommand), + new CommandMapping("css_hidecomms", CS2_SimpleAdmin.Instance.OnHideCommsCommand), + new CommandMapping("css_who", CS2_SimpleAdmin.Instance.OnWhoCommand), + new CommandMapping("css_disconnected", CS2_SimpleAdmin.Instance.OnDisconnectedCommand), + new CommandMapping("css_warns", CS2_SimpleAdmin.Instance.OnWarnsCommand), + new CommandMapping("css_players", CS2_SimpleAdmin.Instance.OnPlayersCommand), + new CommandMapping("css_kick", CS2_SimpleAdmin.Instance.OnKickCommand), + new CommandMapping("css_map", CS2_SimpleAdmin.Instance.OnMapCommand), + new CommandMapping("css_wsmap", CS2_SimpleAdmin.Instance.OnWorkshopMapCommand), + new CommandMapping("css_cvar", CS2_SimpleAdmin.Instance.OnCvarCommand), + new CommandMapping("css_rcon", CS2_SimpleAdmin.Instance.OnRconCommand), + new CommandMapping("css_rr", CS2_SimpleAdmin.Instance.OnRestartCommand), + + new CommandMapping("css_gag", CS2_SimpleAdmin.Instance.OnGagCommand), + new CommandMapping("css_addgag", CS2_SimpleAdmin.Instance.OnAddGagCommand), + new CommandMapping("css_ungag", CS2_SimpleAdmin.Instance.OnUngagCommand), + new CommandMapping("css_mute", CS2_SimpleAdmin.Instance.OnMuteCommand), + new CommandMapping("css_addmute", CS2_SimpleAdmin.Instance.OnAddMuteCommand), + new CommandMapping("css_unmute", CS2_SimpleAdmin.Instance.OnUnmuteCommand), + new CommandMapping("css_silence", CS2_SimpleAdmin.Instance.OnSilenceCommand), + new CommandMapping("css_addsilence", CS2_SimpleAdmin.Instance.OnAddSilenceCommand), + new CommandMapping("css_unsilence", CS2_SimpleAdmin.Instance.OnUnsilenceCommand), + + new CommandMapping("css_vote", CS2_SimpleAdmin.Instance.OnVoteCommand), + + new CommandMapping("css_noclip", CS2_SimpleAdmin.Instance.OnNoclipCommand), + new CommandMapping("css_freeze", CS2_SimpleAdmin.Instance.OnFreezeCommand), + new CommandMapping("css_unfreeze", CS2_SimpleAdmin.Instance.OnUnfreezeCommand), + new CommandMapping("css_godmode", CS2_SimpleAdmin.Instance.OnGodCommand), + + new CommandMapping("css_slay", CS2_SimpleAdmin.Instance.OnSlayCommand), + new CommandMapping("css_slap", CS2_SimpleAdmin.Instance.OnSlapCommand), + new CommandMapping("css_give", CS2_SimpleAdmin.Instance.OnGiveCommand), + new CommandMapping("css_strip", CS2_SimpleAdmin.Instance.OnStripCommand), + new CommandMapping("css_hp", CS2_SimpleAdmin.Instance.OnHpCommand), + new CommandMapping("css_speed", CS2_SimpleAdmin.Instance.OnSpeedCommand), + new CommandMapping("css_gravity", CS2_SimpleAdmin.Instance.OnGravityCommand), + new CommandMapping("css_money", CS2_SimpleAdmin.Instance.OnMoneyCommand), + new CommandMapping("css_team", CS2_SimpleAdmin.Instance.OnTeamCommand), + new CommandMapping("css_rename", CS2_SimpleAdmin.Instance.OnRenameCommand), + new CommandMapping("css_prename", CS2_SimpleAdmin.Instance.OnPrenameCommand), + new CommandMapping("css_respawn", CS2_SimpleAdmin.Instance.OnRespawnCommand), + new CommandMapping("css_tp", CS2_SimpleAdmin.Instance.OnGotoCommand), + new CommandMapping("css_bring", CS2_SimpleAdmin.Instance.OnBringCommand) + ]; + + public static void InitializeCommands() + { + if (!File.Exists(CommandsPath)) + { + CreateConfig(); + InitializeCommands(); + } + else + { + Register(); + } + } + + private static void CreateConfig() + { + var commands = new CommandsConfig + { + Commands = new Dictionary + { + { "css_ban", new Command { Aliases = ["css_ban"] } }, + { "css_addban", new Command { Aliases = ["css_addban"] } }, + { "css_banip", new Command { Aliases = ["css_banip"] } }, + { "css_unban", new Command { Aliases = ["css_unban"] } }, + { "css_warn", new Command { Aliases = ["css_warn"] } }, + { "css_unwarn", new Command { Aliases = ["css_unwarn"] } }, + { "css_asay", new Command { Aliases = ["css_asay"] } }, + { "css_cssay", new Command { Aliases = ["css_cssay"] } }, + { "css_say", new Command { Aliases = ["css_say"] } }, + { "css_psay", new Command { Aliases = ["css_psay"] } }, + { "css_csay", new Command { Aliases = ["css_csay"] } }, + { "css_hsay", new Command { Aliases = ["css_hsay"] } }, + { "css_penalties", new Command { Aliases = ["css_penalties", "css_mypenalties", "css_comms"] } }, + { "css_admin", new Command { Aliases = ["css_admin"] } }, + { "css_adminhelp", new Command { Aliases = ["css_adminhelp"] } }, + { "css_addadmin", new Command { Aliases = ["css_addadmin"] } }, + { "css_deladmin", new Command { Aliases = ["css_deladmin"] } }, + { "css_addgroup", new Command { Aliases = ["css_addgroup"] } }, + { "css_delgroup", new Command { Aliases = ["css_delgroup"] } }, + { "css_reloadadmins", new Command { Aliases = ["css_reloadadmins"] } }, + { "css_hide", new Command { Aliases = ["css_hide", "css_stealth"] } }, + { "css_hidecomms", new Command { Aliases = ["css_hidecomms"] } }, + { "css_who", new Command { Aliases = ["css_who"] } }, + { "css_disconnected", new Command { Aliases = ["css_disconnected", "css_last"] } }, + { "css_warns", new Command { Aliases = ["css_warns"] } }, + { "css_players", new Command { Aliases = ["css_players"] } }, + { "css_kick", new Command { Aliases = ["css_kick"] } }, + { "css_map", new Command { Aliases = ["css_map", "css_changemap"] } }, + { "css_wsmap", new Command { Aliases = ["css_wsmap", "css_changewsmap", "css_workshop"] } }, + { "css_cvar", new Command { Aliases = ["css_cvar"] } }, + { "css_rcon", new Command { Aliases = ["css_rcon"] } }, + { "css_rr", new Command { Aliases = ["css_rr", "css_rg", "css_restart", "css_restartgame"] } }, + { "css_gag", new Command { Aliases = ["css_gag"] } }, + { "css_addgag", new Command { Aliases = ["css_addgag"] } }, + { "css_ungag", new Command { Aliases = ["css_ungag"] } }, + { "css_mute", new Command { Aliases = ["css_mute"] } }, + { "css_addmute", new Command { Aliases = ["css_addmute"] } }, + { "css_unmute", new Command { Aliases = ["css_unmute"] } }, + { "css_silence", new Command { Aliases = ["css_silence"] } }, + { "css_addsilence", new Command { Aliases = ["css_addsilence"] } }, + { "css_unsilence", new Command { Aliases = ["css_unsilence"] } }, + { "css_vote", new Command { Aliases = ["css_vote"] } }, + { "css_noclip", new Command { Aliases = ["css_noclip"] } }, + { "css_freeze", new Command { Aliases = ["css_freeze"] } }, + { "css_unfreeze", new Command { Aliases = ["css_unfreeze"] } }, + { "css_godmode", new Command { Aliases = ["css_godmode"] } }, + { "css_slay", new Command { Aliases = ["css_slay"] } }, + { "css_slap", new Command { Aliases = ["css_slap"] } }, + { "css_give", new Command { Aliases = ["css_give"] } }, + { "css_strip", new Command { Aliases = ["css_strip"] } }, + { "css_hp", new Command { Aliases = ["css_hp"] } }, + { "css_speed", new Command { Aliases = ["css_speed"] } }, + { "css_gravity", new Command { Aliases = ["css_gravity"] } }, + { "css_money", new Command { Aliases = ["css_money"] } }, + { "css_team", new Command { Aliases = ["css_team"] } }, + { "css_rename", new Command { Aliases = ["css_rename"] } }, + { "css_prename", new Command { Aliases = ["css_prename"] } }, + { "css_respawn", new Command { Aliases = ["css_respawn"] } }, + { "css_tp", new Command { Aliases = ["css_tp", "css_tpto", "css_goto"] } }, + { "css_bring", new Command { Aliases = ["css_bring", "css_tphere"] } } + } + }; + + var json = JsonConvert.SerializeObject(commands, Formatting.Indented); + File.WriteAllText(CommandsPath, json); + } + + private static void Register() + { + var json = File.ReadAllText(CommandsPath); + var commandsConfig = JsonConvert.DeserializeObject(json); + + if (commandsConfig?.Commands == null) return; + + foreach (var command in commandsConfig.Commands) + { + if (command.Value.Aliases == null) continue; + + CS2_SimpleAdmin._logger?.LogInformation( + $"Registering command: `{command.Key}` with aliases: `{string.Join(", ", command.Value.Aliases)}`"); + + var mapping = CommandMappings.FirstOrDefault(m => m.CommandKey == command.Key); + if (mapping == null || command.Value.Aliases.Length == 0) continue; + + foreach (var alias in command.Value.Aliases) + { + CS2_SimpleAdmin.Instance.AddCommand(alias, "", mapping.Callback); + } + } + } + + private class CommandsConfig + { + public Dictionary? Commands { get; init; } + } + + private class Command + { + public string[]? Aliases { get; init; } + } + + private class CommandMapping(string commandKey, CommandInfo.CommandCallback callback) + { + public string CommandKey { get; } = commandKey; + public CommandInfo.CommandCallback Callback { get; } = callback; + } +} \ No newline at end of file diff --git a/CS2-SimpleAdmin/Commands/basebans.cs b/CS2-SimpleAdmin/Commands/basebans.cs index e0f3af4..d076966 100644 --- a/CS2-SimpleAdmin/Commands/basebans.cs +++ b/CS2-SimpleAdmin/Commands/basebans.cs @@ -12,12 +12,11 @@ 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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -56,7 +55,7 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t if (!CheckValidBan(caller, time)) return; // Set default caller name if not provided - callerName ??= "Console"; + callerName ??= _localizer?["sa_console"] ?? "Console"; // Freeze player pawn if alive if (player.PawnIsAlive) @@ -128,13 +127,12 @@ internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int t SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Ban, reason, time); } - [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 (Database == null) return; - var callerName = caller?.PlayerName ?? "Console"; + var callerName = caller?.PlayerName ?? _localizer?["sa_console"] ?? "Console"; if (command.ArgCount < 2 || string.IsNullOrEmpty(command.GetArg(1))) return; if (!Helper.ValidateSteamId(command.GetArg(1), out var steamId) || steamId == null) { @@ -185,13 +183,12 @@ public void OnAddBanCommand(CCSPlayerController? caller, CommandInfo command) SimpleAdminApi?.OnPlayerPenaltiedAddedEvent(steamId, adminInfo, PenaltyType.Ban, reason, time); } - [ConsoleCommand("css_banip")] [RequiresPermissions("@css/ban")] [CommandHelper(minArgs: 1, usage: " [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnBanIpCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerName = caller?.PlayerName ?? "Console"; + var callerName = caller?.PlayerName ?? _localizer?["sa_console"] ?? "Console"; if (command.ArgCount < 2 || string.IsNullOrEmpty(command.GetArg(1))) return; var ipAddress = command.GetArg(1); @@ -255,14 +252,13 @@ private bool CheckValidBan(CCSPlayerController? caller, int duration) return false; } - [ConsoleCommand("css_unban")] [RequiresPermissions("@css/unban")] [CommandHelper(minArgs: 1, usage: " [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerSteamId = caller?.SteamID.ToString() ?? "Console"; + var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console"; if (command.GetArg(1).Length <= 1) { @@ -281,14 +277,13 @@ public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command) command.ReplyToCommand($"Unbanned player with pattern {pattern}."); } - [ConsoleCommand("css_warn")] [RequiresPermissions("@css/kick")] [CommandHelper(minArgs: 1, usage: "<#userid or name> [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnWarnCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; if (command.ArgCount < 2) return; @@ -326,7 +321,7 @@ internal void Warn(CCSPlayerController? caller, CCSPlayerController player, int if (!CheckValidBan(caller, time)) return; // Set default caller name if not provided - callerName ??= "Console"; + callerName ??= _localizer?["sa_console"] ?? "Console"; // Freeze player pawn if alive if (player.PawnIsAlive) @@ -395,14 +390,13 @@ await Server.NextFrameAsync(() => SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Warn, reason, time); } - [ConsoleCommand("css_unwarn")] [RequiresPermissions("@css/kick")] [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnUnwarnCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerSteamId = caller?.SteamID.ToString() ?? "Console"; + var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console"; if (command.GetArg(1).Length <= 1) { diff --git a/CS2-SimpleAdmin/Commands/basechat.cs b/CS2-SimpleAdmin/Commands/basechat.cs index 74e18e7..3e8896f 100644 --- a/CS2-SimpleAdmin/Commands/basechat.cs +++ b/CS2-SimpleAdmin/Commands/basechat.cs @@ -11,7 +11,6 @@ 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) @@ -26,12 +25,11 @@ public void OnAdminToAdminSayCommand(CCSPlayerController? caller, CommandInfo co { if (_localizer != null) player.PrintToChat(_localizer["sa_adminchat_template_admin", - caller == null ? "Console" : caller.PlayerName, + caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName, utf8String]); } } - [ConsoleCommand("css_cssay", "Say custom text to all players - u can use color tags.")] [CommandHelper(1, "")] [RequiresPermissions("@css/chat")] public void OnAdminCustomSayCommand(CCSPlayerController? caller, CommandInfo command) @@ -49,7 +47,6 @@ public void OnAdminCustomSayCommand(CCSPlayerController? caller, CommandInfo com } } - [ConsoleCommand("css_say", "Say to all players.")] [CommandHelper(1, "")] [RequiresPermissions("@css/chat")] public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command) @@ -69,12 +66,11 @@ public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command) } } - [ConsoleCommand("css_psay", "Private message a player.")] [CommandHelper(2, "<#userid or name> ")] [RequiresPermissions("@css/chat")] public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -96,7 +92,6 @@ public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo co command.ReplyToCommand($" Private message sent!"); } - [ConsoleCommand("css_csay", "Say to all players (in center).")] [CommandHelper(1, "")] [RequiresPermissions("@css/chat")] public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo command) @@ -109,7 +104,6 @@ public void OnAdminCenterSayCommand(CCSPlayerController? caller, CommandInfo com Helper.PrintToCenterAll(utf8String.ReplaceColorTags()); } - [ConsoleCommand("css_hsay", "Say to all players (in hud).")] [CommandHelper(1, "")] [RequiresPermissions("@css/chat")] public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo command) diff --git a/CS2-SimpleAdmin/Commands/basecommands.cs b/CS2-SimpleAdmin/Commands/basecommands.cs index 4c2f832..9c2a181 100644 --- a/CS2-SimpleAdmin/Commands/basecommands.cs +++ b/CS2-SimpleAdmin/Commands/basecommands.cs @@ -19,9 +19,6 @@ namespace CS2_SimpleAdmin; public partial class CS2_SimpleAdmin { - [ConsoleCommand("css_penalties")] - [ConsoleCommand("css_mypenalties")] - [ConsoleCommand("css_comms")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] public void OnPenaltiesCommand(CCSPlayerController? caller, CommandInfo command) { @@ -128,7 +125,6 @@ await Server.NextFrameAsync(() => }); } - [ConsoleCommand("css_admin")] [RequiresPermissions("@css/generic")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command) @@ -139,7 +135,6 @@ public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command) AdminMenu.OpenMenu(caller); } - [ConsoleCommand("css_adminhelp")] [RequiresPermissions("@css/generic")] public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command) { @@ -151,7 +146,6 @@ public void OnAdminHelpCommand(CCSPlayerController? caller, CommandInfo command) } } - [ConsoleCommand("css_addadmin")] [CommandHelper(minArgs: 4, usage: " ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnAddAdminCommand(CCSPlayerController? caller, CommandInfo command) @@ -207,7 +201,6 @@ public static void AddAdmin(CCSPlayerController? caller, string steamid, string Server.PrintToConsole(msg); } - [ConsoleCommand("css_deladmin")] [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnDelAdminCommand(CCSPlayerController? caller, CommandInfo command) @@ -255,7 +248,6 @@ public void RemoveAdmin(CCSPlayerController? caller, string steamid, bool global Server.PrintToConsole(msg); } - [ConsoleCommand("css_addgroup")] [CommandHelper(minArgs: 3, usage: " ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnAddGroup(CCSPlayerController? caller, CommandInfo command) @@ -301,7 +293,6 @@ private static void AddGroup(CCSPlayerController? caller, string name, string fl Server.PrintToConsole(msg); } - [ConsoleCommand("css_delgroup")] [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnDelGroupCommand(CCSPlayerController? caller, CommandInfo command) @@ -341,7 +332,6 @@ private void RemoveGroup(CCSPlayerController? caller, string name, CommandInfo? Server.PrintToConsole(msg); } - [ConsoleCommand("css_reloadadmins")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/root")] public void OnRelAdminCommand(CCSPlayerController? caller, CommandInfo command) @@ -391,8 +381,6 @@ await Server.NextFrameAsync(() => //_ = _adminManager.GiveAllFlags(); } - [ConsoleCommand("css_stealth")] - [ConsoleCommand("css_hide")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] [RequiresPermissions("@css/kick")] public void OnHideCommand(CCSPlayerController? caller, CommandInfo command) @@ -421,7 +409,25 @@ public void OnHideCommand(CCSPlayerController? caller, CommandInfo command) } } - [ConsoleCommand("css_who")] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] + [RequiresPermissions("@css/kick")] + public void OnHideCommsCommand(CCSPlayerController? caller, CommandInfo command) + { + if (caller == null) + return; + + if (!AdminDisabledJoinComms.Add(caller.SteamID)) + { + AdminDisabledJoinComms.Remove(caller.SteamID); + command.ReplyToCommand("From now on, you'll see penalty notifications"); + } + else + { + AdminDisabledJoinComms.Add(caller.SteamID); + command.ReplyToCommand($"You don't see penalty notifications now"); + } + } + [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/generic")] public void OnWhoCommand(CCSPlayerController? caller, CommandInfo command) @@ -476,8 +482,6 @@ await Server.NextFrameAsync(() => }); } - [ConsoleCommand("css_disconnected")] - [ConsoleCommand("css_last")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] [RequiresPermissions("@css/kick")] public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo command) @@ -494,7 +498,7 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma disconnectedMenuAction?.AddMenuOption(_localizer["sa_ban"], (_, _) => { DurationMenu.OpenMenu(caller, _localizer["sa_ban"], player, (_, _, duration) => - ReasonMenu.OpenMenu(caller, PenaltyType.Ban, "Powód", player, (_, _, reason) => + ReasonMenu.OpenMenu(caller, PenaltyType.Ban, _localizer["sa_reason"], player, (_, _, reason) => { caller.ExecuteClientCommandFromServer($"css_addban {player.SteamId.SteamId64} {duration} \"{reason}\""); })); @@ -502,7 +506,7 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma disconnectedMenuAction?.AddMenuOption(_localizer["sa_mute"], (_, _) => { DurationMenu.OpenMenu(caller, _localizer["sa_mute"], player, (_, _, duration) => - ReasonMenu.OpenMenu(caller, PenaltyType.Mute, "Powód", player, (_, _, reason) => + ReasonMenu.OpenMenu(caller, PenaltyType.Mute, _localizer["sa_reason"], player, (_, _, reason) => { caller.ExecuteClientCommandFromServer($"css_addmute {player.SteamId.SteamId64} {duration} \"{reason}\""); })); @@ -510,7 +514,7 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma disconnectedMenuAction?.AddMenuOption(_localizer["sa_gag"], (_, _) => { DurationMenu.OpenMenu(caller, _localizer["sa_gag"], player, (_, _, duration) => - ReasonMenu.OpenMenu(caller, PenaltyType.Mute, "Powód", player, (_, _, reason) => + ReasonMenu.OpenMenu(caller, PenaltyType.Mute, _localizer["sa_reason"], player, (_, _, reason) => { caller.ExecuteClientCommandFromServer($"css_addgag {player.SteamId.SteamId64} {duration} \"{reason}\""); })); @@ -518,7 +522,7 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma disconnectedMenuAction?.AddMenuOption(_localizer["sa_silence"], (_, _) => { DurationMenu.OpenMenu(caller, _localizer["sa_silence"], player, (_, _, duration) => - ReasonMenu.OpenMenu(caller, PenaltyType.Mute, "Powód", player, (_, _, reason) => + ReasonMenu.OpenMenu(caller, PenaltyType.Mute, _localizer["sa_reason"], player, (_, _, reason) => { caller.ExecuteClientCommandFromServer($"css_addsilence {player.SteamId.SteamId64} {duration} \"{reason}\""); })); @@ -531,7 +535,6 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma disconnectedMenu?.Open(caller); } - [ConsoleCommand("css_warns")] [CommandHelper(minArgs: 1, usage: "<#userid or name>", whoCanExecute: CommandUsage.CLIENT_ONLY)] [RequiresPermissions("@css/kick")] public void OnWarnsCommand(CCSPlayerController? caller, CommandInfo command) @@ -586,7 +589,6 @@ await Server.NextFrameAsync(() => }); } - [ConsoleCommand("css_players")] [CommandHelper(whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] [RequiresPermissions("@css/generic")] public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command) @@ -654,12 +656,11 @@ public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command) } } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var reason = _localizer?["sa_unknown"] ?? "Unknown"; var targets = GetTarget(command); @@ -695,7 +696,7 @@ public void Kick(CCSPlayerController? caller, CCSPlayerController player, string if (!player.UserId.HasValue) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; reason ??= _localizer?["sa_unknown"] ?? "Unknown"; var playerInfo = PlayersInfo[player.UserId.Value]; @@ -743,8 +744,6 @@ public void Kick(CCSPlayerController? caller, CCSPlayerController player, string SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Kick, reason); } - [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) @@ -755,7 +754,7 @@ public void OnMapCommand(CCSPlayerController? caller, CommandInfo command) public void ChangeMap(CCSPlayerController? caller, string map, CommandInfo? command = null) { - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; map = map.ToLower(); if (map.StartsWith("ws:")) @@ -802,9 +801,6 @@ public void ChangeMap(CCSPlayerController? caller, string map, CommandInfo? comm Helper.LogCommand(caller, command?.GetCommandString ?? $"css_map {map}"); } - [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) @@ -816,7 +812,7 @@ public void OnWorkshopMapCommand(CCSPlayerController? caller, CommandInfo comman public void ChangeWorkshopMap(CCSPlayerController? caller, string map, CommandInfo? command = null) { map = map.ToLower(); - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Determine the workshop command var issuedCommand = long.TryParse(map, out var mapId) @@ -842,13 +838,12 @@ public void ChangeWorkshopMap(CCSPlayerController? caller, string map, CommandIn Helper.LogCommand(caller, command?.GetCommandString ?? $"css_wsmap {map}"); } - [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)); - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; if (cvar == null) { @@ -872,12 +867,11 @@ public void OnCvarCommand(CCSPlayerController? caller, CommandInfo command) Logger.LogInformation($"{callerName} 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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; Helper.LogCommand(caller, command); @@ -886,10 +880,6 @@ public void OnRconCommand(CCSPlayerController? caller, CommandInfo command) Logger.LogInformation($"{callerName} executed command ({command.ArgString})."); } - [ConsoleCommand("css_rr")] - [ConsoleCommand("css_rg")] - [ConsoleCommand("css_restart")] - [ConsoleCommand("css_restartgame")] [RequiresPermissions("@css/generic")] [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnRestartCommand(CCSPlayerController? caller, CommandInfo command) @@ -902,7 +892,7 @@ public static void RestartGame(CCSPlayerController? admin) Helper.LogCommand(admin, "css_restartgame"); // TODO: Localize - var name = admin == null ? "Console" : admin.PlayerName; + var name = admin == null ? _localizer?["sa_console"] ?? "Console" : admin.PlayerName; Server.PrintToChatAll($"[SA] {name}: Restarting game..."); Server.ExecuteCommand("mp_restartgame 2"); } diff --git a/CS2-SimpleAdmin/Commands/basecomms.cs b/CS2-SimpleAdmin/Commands/basecomms.cs index 4e70c63..99ad0a9 100644 --- a/CS2-SimpleAdmin/Commands/basecomms.cs +++ b/CS2-SimpleAdmin/Commands/basecomms.cs @@ -10,13 +10,12 @@ 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; - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var reason = _localizer?["sa_unknown"] ?? "Unknown"; @@ -51,7 +50,7 @@ internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int t if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller == null ? "Console" : caller.PlayerName; + callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; muteManager ??= new MuteManager(Database); // Get player and admin information @@ -101,7 +100,6 @@ internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int t SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Gag, reason, time); } - [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) @@ -109,7 +107,7 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command) if (Database == null) return; // Set caller name - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Validate command arguments if (command.ArgCount < 2 || string.IsNullOrEmpty(command.GetArg(1))) return; @@ -160,14 +158,13 @@ public void OnAddGagCommand(CCSPlayerController? caller, CommandInfo command) SimpleAdminApi?.OnPlayerPenaltiedAddedEvent(steamId, adminInfo, PenaltyType.Gag, reason, time); } - [ConsoleCommand("css_ungag")] [RequiresPermissions("@css/chat")] [CommandHelper(minArgs: 1, usage: " [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerSteamId = caller?.SteamID.ToString() ?? "Console"; + var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console"; var pattern = command.GetArg(1); var reason = command.GetArg(2); @@ -229,13 +226,12 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) } } - [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; - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var reason = _localizer?["sa_unknown"] ?? "Unknown"; @@ -270,7 +266,7 @@ internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller == null ? "Console" : caller.PlayerName; + callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; muteManager ??= new MuteManager(Database); // Get player and admin information @@ -323,7 +319,6 @@ internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Mute, reason, time); } - [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) @@ -331,7 +326,7 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command) if (Database == null) return; // Set caller name - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Validate command arguments if (command.ArgCount < 2 || string.IsNullOrEmpty(command.GetArg(1))) return; @@ -382,14 +377,13 @@ public void OnAddMuteCommand(CCSPlayerController? caller, CommandInfo command) SimpleAdminApi?.OnPlayerPenaltiedAddedEvent(steamId, adminInfo, PenaltyType.Mute, reason, time); } - [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; - var callerSteamId = caller?.SteamID.ToString() ?? "Console"; + var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console"; var pattern = command.GetArg(1); var reason = command.GetArg(2); @@ -453,13 +447,12 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) } } - [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; - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var reason = _localizer?["sa_unknown"] ?? "Unknown"; @@ -494,7 +487,7 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController player, i if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller == null ? "Console" : caller.PlayerName; + callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; muteManager ??= new MuteManager(Database); // Get player and admin information @@ -544,7 +537,6 @@ internal void Silence(CCSPlayerController? caller, CCSPlayerController player, i SimpleAdminApi?.OnPlayerPenaltiedEvent(playerInfo, adminInfo, PenaltyType.Silence, reason, time); } - [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) @@ -552,7 +544,7 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command if (Database == null) return; // Set caller name - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Validate command arguments if (command.ArgCount < 2 || string.IsNullOrEmpty(command.GetArg(1))) return; @@ -603,14 +595,13 @@ public void OnAddSilenceCommand(CCSPlayerController? caller, CommandInfo command SimpleAdminApi?.OnPlayerPenaltiedAddedEvent(steamId, adminInfo, PenaltyType.Silence, reason, time); } - [ConsoleCommand("css_unsilence")] [RequiresPermissions("@css/chat")] [CommandHelper(minArgs: 1, usage: " [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) { if (Database == null) return; - var callerSteamId = caller?.SteamID.ToString() ?? "Console"; + var callerSteamId = caller?.SteamID.ToString() ?? _localizer?["sa_console"] ?? "Console"; var pattern = command.GetArg(1); var reason = command.GetArg(2); diff --git a/CS2-SimpleAdmin/Commands/basevotes.cs b/CS2-SimpleAdmin/Commands/basevotes.cs index 9298d60..f65d9dc 100644 --- a/CS2-SimpleAdmin/Commands/basevotes.cs +++ b/CS2-SimpleAdmin/Commands/basevotes.cs @@ -9,7 +9,6 @@ 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) @@ -47,11 +46,11 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command) voteMenu.PostSelectAction = PostSelectAction.Close; - Helper.PrintToCenterAll(_localizer["sa_admin_vote_message", caller == null ? "Console" : caller.PlayerName, question]); + Helper.PrintToCenterAll(_localizer["sa_admin_vote_message", caller == null ? _localizer["sa_console"] : caller.PlayerName, question]); player.SendLocalizedMessage(_localizer, "sa_admin_vote_message", - caller == null ? "Console" : caller.PlayerName, + caller == null ? _localizer["sa_console"] : caller.PlayerName, question); voteMenu.Open(player); diff --git a/CS2-SimpleAdmin/Commands/funcommands.cs b/CS2-SimpleAdmin/Commands/funcommands.cs index 557a953..19b52a1 100644 --- a/CS2-SimpleAdmin/Commands/funcommands.cs +++ b/CS2-SimpleAdmin/Commands/funcommands.cs @@ -7,12 +7,11 @@ 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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -35,7 +34,7 @@ internal static void NoClip(CCSPlayerController? caller, CCSPlayerController pla if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Toggle no-clip mode for the player player.Pawn.Value?.ToggleNoclip(); @@ -62,12 +61,11 @@ internal static void NoClip(CCSPlayerController? caller, CCSPlayerController pla } } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -90,7 +88,7 @@ internal static void God(CCSPlayerController? caller, CCSPlayerController player if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Toggle god mode for the player if (!GodPlayers.Add(player.Slot)) @@ -116,12 +114,11 @@ internal static void God(CCSPlayerController? caller, CCSPlayerController player } } - [ConsoleCommand("css_freeze", "Freeze a player.")] [CommandHelper(1, "<#userid or name> [duration]")] [RequiresPermissions("@css/slay")] public void OnFreezeCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; int.TryParse(command.GetArg(2), out var time); var targets = GetTarget(command); @@ -143,7 +140,7 @@ internal static void Freeze(CCSPlayerController? caller, CCSPlayerController pla if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Freeze player pawn player.Pawn.Value?.Freeze(); @@ -172,12 +169,11 @@ internal static void Freeze(CCSPlayerController? caller, CCSPlayerController pla Helper.LogCommand(caller, command); } - [ConsoleCommand("css_unfreeze", "Unfreeze a player.")] [CommandHelper(1, "<#userid or name>")] [RequiresPermissions("@css/slay")] public void OnUnfreezeCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -195,7 +191,7 @@ internal static void Unfreeze(CCSPlayerController? caller, CCSPlayerController p if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Unfreeze player pawn player.Pawn.Value?.Unfreeze(); diff --git a/CS2-SimpleAdmin/Commands/playercommands.cs b/CS2-SimpleAdmin/Commands/playercommands.cs index 2d5f896..8e83e48 100644 --- a/CS2-SimpleAdmin/Commands/playercommands.cs +++ b/CS2-SimpleAdmin/Commands/playercommands.cs @@ -10,12 +10,11 @@ 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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -33,7 +32,7 @@ internal static void Slay(CCSPlayerController? caller, CCSPlayerController playe if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Make the player commit suicide player.CommitSuicide(false, true); @@ -56,12 +55,11 @@ internal static void Slay(CCSPlayerController? caller, CCSPlayerController playe Helper.LogCommand(caller, command); } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -106,7 +104,7 @@ private static void GiveWeapon(CCSPlayerController? caller, CCSPlayerController if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Give weapon to the player player.GiveNamedItem(weaponName); @@ -134,7 +132,7 @@ internal static void GiveWeapon(CCSPlayerController? caller, CCSPlayerController if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Give weapon to the player player.GiveNamedItem(weapon); @@ -157,12 +155,11 @@ internal static void GiveWeapon(CCSPlayerController? caller, CCSPlayerController } } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -182,7 +179,7 @@ internal static void StripWeapons(CCSPlayerController? caller, CCSPlayerControll if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller != null ? caller.PlayerName : "Console"; + callerName ??= caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Check if player is valid, alive, and connected if (!player.IsValid || !player.PawnIsAlive || player.Connected != PlayerConnectedState.PlayerConnected) @@ -209,7 +206,6 @@ internal static void StripWeapons(CCSPlayerController? caller, CCSPlayerControll } } - [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) @@ -236,7 +232,7 @@ internal static void SetHp(CCSPlayerController? caller, CCSPlayerController play if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Set player's health player.SetHp(health); @@ -259,12 +255,11 @@ internal static void SetHp(CCSPlayerController? caller, CCSPlayerController play } } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; float.TryParse(command.GetArg(2), out var speed); var targets = GetTarget(command); @@ -289,7 +284,7 @@ internal static void SetSpeed(CCSPlayerController? caller, CCSPlayerController p if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Set player's speed player.SetSpeed(speed); @@ -317,7 +312,7 @@ internal static void SetSpeed(CCSPlayerController? caller, CCSPlayerController p [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnGravityCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; float.TryParse(command.GetArg(2), out var gravity); var targets = GetTarget(command); @@ -342,7 +337,7 @@ internal static void SetGravity(CCSPlayerController? caller, CCSPlayerController if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Set player's gravity player.SetGravity(gravity); @@ -365,12 +360,11 @@ internal static void SetGravity(CCSPlayerController? caller, CCSPlayerController } } - [ConsoleCommand("css_money")] [RequiresPermissions("@css/slay")] [CommandHelper(minArgs: 1, usage: "<#userid or name> ", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnMoneyCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; int.TryParse(command.GetArg(2), out var money); var targets = GetTarget(command); @@ -395,7 +389,7 @@ internal static void SetMoney(CCSPlayerController? caller, CCSPlayerController p if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Set player's money player.SetMoney(money); @@ -418,7 +412,6 @@ internal static void SetMoney(CCSPlayerController? caller, CCSPlayerController p } } - [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) @@ -452,7 +445,7 @@ internal static void Slap(CCSPlayerController? caller, CCSPlayerController playe if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Apply slap damage to the player player.Pawn.Value?.Slap(damage); @@ -477,14 +470,13 @@ internal static void Slap(CCSPlayerController? caller, CCSPlayerController playe } } - [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) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var teamName = command.GetArg(2).ToLower(); - var _teamName = "SPEC"; + string _teamName; var teamNum = CsTeam.Spectator; var targets = GetTarget(command); @@ -535,7 +527,7 @@ internal static void ChangeTeam(CCSPlayerController? caller, CCSPlayerController if (!caller.CanTarget(player)) return; // Set default caller name if not provided - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : _localizer?["sa_console"] ?? "Console"; // Change team based on the provided teamName and conditions if (!teamName.Equals("swap", StringComparison.OrdinalIgnoreCase)) @@ -574,13 +566,12 @@ internal static void ChangeTeam(CCSPlayerController? caller, CCSPlayerController Helper.ShowAdminActivity(activityMessageKey, callerName, adminActivityArgs); } - [ConsoleCommand("css_rename", "Rename a player.")] [CommandHelper(1, "<#userid or name> ")] [RequiresPermissions("@css/kick")] public void OnRenameCommand(CCSPlayerController? caller, CommandInfo command) { // Set default caller name if not provided - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Get the new name from the command arguments var newName = command.GetArg(2); @@ -620,13 +611,12 @@ public void OnRenameCommand(CCSPlayerController? caller, CommandInfo command) }); } - [ConsoleCommand("css_prename", "Permanent rename a player.")] [CommandHelper(1, "<#userid or name> ")] [RequiresPermissions("@css/ban")] - public void OnPRenameCommand(CCSPlayerController? caller, CommandInfo command) + public void OnPrenameCommand(CCSPlayerController? caller, CommandInfo command) { // Set default caller name if not provided - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Get the new name from the command arguments var newName = command.GetArg(2); @@ -670,12 +660,11 @@ public void OnPRenameCommand(CCSPlayerController? caller, CommandInfo command) }); } - [ConsoleCommand("css_respawn", "Respawn a dead player.")] [CommandHelper(1, "<#userid or name>")] [RequiresPermissions("@css/cheats")] public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo command) { - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; var targets = GetTarget(command); if (targets == null) return; @@ -699,7 +688,7 @@ internal static void Respawn(CCSPlayerController? caller, CCSPlayerController pl if (!caller.CanTarget(player)) return; // Set default caller name if not provided - callerName ??= caller == null ? "Console" : caller.PlayerName; + callerName ??= caller == null ? _localizer?["sa_console"] ?? "Console" : caller.PlayerName; // Ensure the player's pawn is valid before attempting to respawn if (_cBasePlayerControllerSetPawnFunc == null || player.PlayerPawn.Value == null || !player.PlayerPawn.IsValid) return; @@ -728,9 +717,6 @@ internal static void Respawn(CCSPlayerController? caller, CCSPlayerController pl Helper.ShowAdminActivity(activityMessageKey, callerName, adminActivityArgs); } - [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) @@ -764,7 +750,7 @@ public void OnGotoCommand(CCSPlayerController? caller, CommandInfo command) // Prepare message key and arguments for the teleport notification var activityMessageKey = "sa_admin_tp_message"; - var adminActivityArgs = new object[] { player.PlayerName }; + var adminActivityArgs = new object[] { "CALLER", player.PlayerName }; // Show admin activity if (!SilentPlayers.Contains(caller.Slot) && _localizer != null) @@ -774,8 +760,6 @@ public void OnGotoCommand(CCSPlayerController? caller, CommandInfo command) } } - [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) @@ -809,7 +793,7 @@ public void OnBringCommand(CCSPlayerController? caller, CommandInfo command) // Prepare message key and arguments for the bring notification var activityMessageKey = "sa_admin_bring_message"; - var adminActivityArgs = new object[] { player.PlayerName }; + var adminActivityArgs = new object[] { "CALLER", player.PlayerName }; // Show admin activity if (!SilentPlayers.Contains(caller.Slot) && _localizer != null) diff --git a/CS2-SimpleAdmin/Helper.cs b/CS2-SimpleAdmin/Helper.cs index cd23122..4fff2d0 100644 --- a/CS2-SimpleAdmin/Helper.cs +++ b/CS2-SimpleAdmin/Helper.cs @@ -33,8 +33,6 @@ internal static class Helper private static CNetworkSystemUpdatePublicIp? _networkSystemUpdatePublicIp; - internal static CS2_SimpleAdminConfig? Config { get; set; } - public static bool IsDebugBuild { get @@ -182,7 +180,7 @@ internal static void LogCommand(CCSPlayerController? caller, CommandInfo command if (CS2_SimpleAdmin._localizer == null) return; - var playerName = caller?.PlayerName ?? "Console"; + var playerName = caller?.PlayerName ?? CS2_SimpleAdmin._localizer["sa_console"]; var hostname = ConVar.Find("hostname")?.StringValue ?? CS2_SimpleAdmin._localizer["sa_unknown"]; @@ -198,7 +196,7 @@ internal static void LogCommand(CCSPlayerController? caller, string command) if (CS2_SimpleAdmin._localizer == null) return; - var playerName = caller?.PlayerName ?? "Console"; + var playerName = caller?.PlayerName ?? CS2_SimpleAdmin._localizer["sa_console"]; var hostnameCvar = ConVar.Find("hostname"); var hostname = hostnameCvar?.StringValue ?? CS2_SimpleAdmin._localizer["sa_unknown"]; @@ -246,7 +244,7 @@ private static void SendDiscordLogMessage(CCSPlayerController? caller, CommandIn if (discordWebhookClientLog == null || localizer == null) return; var communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : ""; - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console"; discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); } @@ -255,7 +253,7 @@ private static void SendDiscordLogMessage(CCSPlayerController? caller, string co if (discordWebhookClientLog == null || localizer == null) return; var communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : ""; - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console"; discordWebhookClientLog.SendMessageAsync(GenerateMessageDiscord(localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command])); } @@ -292,7 +290,7 @@ public static void ShowAdminActivity(string messageKey, string? callerName = nul currentMessageArgs[i] = CS2_SimpleAdmin.Instance.Config.OtherSettings.ShowActivityType switch { 1 => arg.Replace("CALLER", AdminManager.PlayerHasPermissions(controller, "@css/kick") || AdminManager.PlayerHasPermissions(controller, "@css/ban") ? callerName : CS2_SimpleAdmin._localizer["sa_admin"]), - 2 => arg.Replace("CALLER", callerName ?? "Console"), + 2 => arg.Replace("CALLER", callerName ?? CS2_SimpleAdmin._localizer["sa_console"]), _ => arg }; } @@ -323,7 +321,7 @@ public static void DisplayCenterMessage( formattedMessageArgs[i] = CS2_SimpleAdmin.Instance.Config.OtherSettings.ShowActivityType switch { 1 => arg.Replace("CALLER", CS2_SimpleAdmin._localizer["sa_admin"]), - 2 => arg.Replace("CALLER", callerName ?? "Console"), + 2 => arg.Replace("CALLER", callerName ?? CS2_SimpleAdmin._localizer["sa_console"]), _ => arg }; } @@ -362,7 +360,7 @@ public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPla var callerCommunityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : ""; var targetCommunityUrl = target != null ? "<" + new SteamID(target.SteamID).ToCommunityUrl() + ">" : ""; - var callerName = caller != null ? caller.PlayerName : "Console"; + var callerName = caller != null ? caller.PlayerName : CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console"; var targetName = target != null ? target.PlayerName : localizer["sa_unknown"]; var targetSteamId = target != null ? new SteamID(target.SteamID).SteamId64.ToString() : localizer["sa_unknown"]; @@ -503,7 +501,7 @@ public static void TryLogCommandOnDiscord(CCSPlayerController? caller, string co if (caller != null && caller.IsValid == false) caller = null; - var callerName = caller == null ? "Console" : caller.PlayerName; + var callerName = caller == null ? CS2_SimpleAdmin._localizer["sa_console"] : caller.PlayerName; var communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl() + ">" : ""; diff --git a/CS2-SimpleAdmin/Managers/BanManager.cs b/CS2-SimpleAdmin/Managers/BanManager.cs index 0364bbe..f9059f8 100644 --- a/CS2-SimpleAdmin/Managers/BanManager.cs +++ b/CS2-SimpleAdmin/Managers/BanManager.cs @@ -27,8 +27,8 @@ public async Task BanPlayer(PlayerInfo player, PlayerInfo? issuer, string reason playerSteamid = player.SteamId.SteamId64.ToString(), playerName = player.Name, playerIp = config.OtherSettings.BanType == 1 ? player.IpAddress : null, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", banReason = reason, duration = time, ends = futureTime, @@ -56,8 +56,8 @@ public async Task AddBanBySteamid(string playerSteamId, PlayerInfo? issuer, stri await connection.ExecuteAsync(sql, new { playerSteamid = playerSteamId, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", banReason = reason, duration = time, ends = futureTime, @@ -85,8 +85,8 @@ public async Task AddBanByIp(string playerIp, PlayerInfo? issuer, string reason, await connection.ExecuteAsync(sql, new { playerIp, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", banReason = reason, duration = time, ends = futureTime, diff --git a/CS2-SimpleAdmin/Managers/MuteManager.cs b/CS2-SimpleAdmin/Managers/MuteManager.cs index 021b3fb..d112cb4 100644 --- a/CS2-SimpleAdmin/Managers/MuteManager.cs +++ b/CS2-SimpleAdmin/Managers/MuteManager.cs @@ -29,8 +29,8 @@ public async Task MutePlayer(PlayerInfo player, PlayerInfo? issuer, string reaso { playerSteamid = player.SteamId.SteamId64.ToString(), playerName = player.Name, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", muteReason = reason, duration = time, ends = futureTime, @@ -69,8 +69,8 @@ public async Task AddMuteBySteamid(string playerSteamId, PlayerInfo? issuer, str await connection.ExecuteAsync(sql, new { playerSteamid = playerSteamId, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", muteReason = reason, duration = time, ends = futureTime, diff --git a/CS2-SimpleAdmin/Managers/PlayerManager.cs b/CS2-SimpleAdmin/Managers/PlayerManager.cs index af75b68..59b3df5 100644 --- a/CS2-SimpleAdmin/Managers/PlayerManager.cs +++ b/CS2-SimpleAdmin/Managers/PlayerManager.cs @@ -180,43 +180,12 @@ await Server.NextFrameAsync(() => } } - /* - if (CS2_SimpleAdmin._localizer != null) - { - if (mutesList[PenaltyType.Gag].Count == 0) - mutesList[PenaltyType.Gag].Add(CS2_SimpleAdmin._localizer["sa_player_penalty_info_no_active_gag"]); - if (mutesList[PenaltyType.Mute].Count == 0) - mutesList[PenaltyType.Mute].Add(CS2_SimpleAdmin._localizer["sa_player_penalty_info_no_active_mute"]); - if (mutesList[PenaltyType.Silence].Count == 0) - mutesList[PenaltyType.Silence].Add(CS2_SimpleAdmin._localizer["sa_player_penalty_info_no_active_silence"]); - } - */ - - /* - await Server.NextFrameAsync(() => - { - CS2_SimpleAdmin.Instance.AddTimer(3.0f, () => - { - player.SendLocalizedMessage(CS2_SimpleAdmin._localizer, "sa_player_penalty_info", - [ - player.PlayerName, - CS2_SimpleAdmin.PlayersInfo[userId].TotalBans, - CS2_SimpleAdmin.PlayersInfo[userId].TotalGags, - CS2_SimpleAdmin.PlayersInfo[userId].TotalMutes, - CS2_SimpleAdmin.PlayersInfo[userId].TotalSilences, - CS2_SimpleAdmin.PlayersInfo[userId].TotalWarns, - string.Join("\n", mutesList.SelectMany(kvp => kvp.Value)), - string.Join("\n", warnsList) - ]); - }); - */ - await Server.NextFrameAsync(() => { foreach (var admin in Helper.GetValidPlayers() .Where(p => (AdminManager.PlayerHasPermissions(p, "@css/kick") || AdminManager.PlayerHasPermissions(p, "@css/ban")) && - p.Connected == PlayerConnectedState.PlayerConnected)) + p.Connected == PlayerConnectedState.PlayerConnected && !CS2_SimpleAdmin.AdminDisabledJoinComms.Contains(p.SteamID))) { if (CS2_SimpleAdmin._localizer != null && admin != player) admin.SendLocalizedMessage(CS2_SimpleAdmin._localizer, "sa_admin_penalty_info", diff --git a/CS2-SimpleAdmin/Managers/WarnManager.cs b/CS2-SimpleAdmin/Managers/WarnManager.cs index 6e0ba60..fc7f281 100644 --- a/CS2-SimpleAdmin/Managers/WarnManager.cs +++ b/CS2-SimpleAdmin/Managers/WarnManager.cs @@ -22,8 +22,8 @@ public async Task WarnPlayer(PlayerInfo player, PlayerInfo? issuer, string reaso { playerSteamid = player.SteamId.SteamId64.ToString(), playerName = player.Name, - adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.SteamId64.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", muteReason = reason, duration = time, ends = futureTime, @@ -51,8 +51,8 @@ public async Task AddWarnBySteamid(string playerSteamId, PlayerInfo? issuer, str await connection.ExecuteAsync(sql, new { playerSteamid = playerSteamId, - adminSteamid = issuer?.SteamId.ToString() ?? "Console", - adminName = issuer?.Name ?? "Console", + adminSteamid = issuer?.SteamId.ToString() ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", + adminName = issuer?.Name ?? CS2_SimpleAdmin._localizer?["sa_console"] ?? "Console", muteReason = reason, duration = time, ends = futureTime, diff --git a/CS2-SimpleAdmin/VERSION b/CS2-SimpleAdmin/VERSION index ba4c966..ccf77ab 100644 --- a/CS2-SimpleAdmin/VERSION +++ b/CS2-SimpleAdmin/VERSION @@ -1 +1 @@ -1.6.0a \ No newline at end of file +1.6.1a \ No newline at end of file diff --git a/CS2-SimpleAdmin/Variables.cs b/CS2-SimpleAdmin/Variables.cs index e04363e..76da91b 100644 --- a/CS2-SimpleAdmin/Variables.cs +++ b/CS2-SimpleAdmin/Variables.cs @@ -13,32 +13,48 @@ namespace CS2_SimpleAdmin; public partial class CS2_SimpleAdmin { + // Paths + internal static string ConfigDirectory = Path.Combine(Application.RootDirectory, "configs/plugins/CS2-SimpleAdmin"); + + // Localization public static IStringLocalizer? _localizer; + + // Voting System public static readonly Dictionary VoteAnswers = []; + public static bool VoteInProgress; + + // Command and Server Settings + public static readonly bool UnlockedCommands = CoreConfig.UnlockConCommands; + internal static string IpAddress = string.Empty; public static bool ServerLoaded; + public static int? ServerId = null; + internal static readonly HashSet AdminDisabledJoinComms = []; + + // Player Management private static readonly HashSet GodPlayers = []; private static readonly HashSet SilentPlayers = []; internal static readonly ConcurrentBag BannedPlayers = []; internal static readonly Dictionary RenamedPlayers = []; - public static bool VoteInProgress; - public static int? ServerId = null; - public static readonly bool UnlockedCommands = CoreConfig.UnlockConCommands; internal static readonly Dictionary PlayersInfo = []; private static readonly List DisconnectedPlayers = []; + // Discord Integration internal static DiscordWebhookClient? DiscordWebhookClientLog; + // Database Settings internal string DbConnectionString = string.Empty; internal static Database.Database? Database; - internal static string IpAddress = string.Empty; + // Logger internal static ILogger? _logger; + + // Memory Function (Game-related) private static MemoryFunctionVoid? _cBasePlayerControllerSetPawnFunc; - // Menus + // Menu API and Capabilities internal static IMenuApi? MenuApi; private static readonly PluginCapability MenuCapability = new("menu:nfcore"); - // Shared + // Shared API private Api.CS2_SimpleAdminApi? SimpleAdminApi { get; set; } } \ No newline at end of file diff --git a/CS2-SimpleAdmin/lang/en.json b/CS2-SimpleAdmin/lang/en.json index 88e9cd1..19a8029 100644 --- a/CS2-SimpleAdmin/lang/en.json +++ b/CS2-SimpleAdmin/lang/en.json @@ -49,6 +49,7 @@ "sa_menu_disconnected_action_title": "Select action", "sa_player": "Player", + "sa_console": "Console", "sa_steamid": "SteamID", "sa_duration": "Duration", "sa_reason": "Reason", diff --git a/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs b/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs index 9cf2076..d30d249 100644 --- a/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs +++ b/CS2-SimpleAdminApi/ICS2-SimpleAdminApi.cs @@ -1,5 +1,6 @@ using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Capabilities; +using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Entities; namespace CS2_SimpleAdminApi; @@ -20,4 +21,6 @@ public interface ICS2_SimpleAdminApi public event Action? OnPlayerPenaltiedAdded; public void IssuePenalty(CCSPlayerController player, CCSPlayerController? admin, PenaltyType penaltyType, string reason, int duration = -1); + public void LogCommand(CCSPlayerController? caller, string command); + public void LogCommand(CCSPlayerController? caller, CommandInfo command); } \ No newline at end of file