diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index f373ee9..fcada0b 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -3,8 +3,10 @@ using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; +using CounterStrikeSharp.API.Modules.Cvars; using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Utils; +using Microsoft.Extensions.Logging; using MySqlConnector; using static System.Net.Mime.MediaTypeNames; @@ -188,7 +190,6 @@ public void OnSlapCommand(CCSPlayerController? caller, CommandInfo command) int damage = 0; - if (command.ArgCount >= 2) { int.TryParse(command.GetArg(2), out damage); @@ -262,6 +263,102 @@ public void OnAdminHudSayCommand(CCSPlayerController? caller, CommandInfo comman 0, 0, 0, 0); } + [ConsoleCommand("css_noclip", "Noclip a player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/cheats")] + public void OnNoclipCommand(CCSPlayerController? caller, CommandInfo command) + { + if (!GetTarget(command, out var player)) + return; + + player!.Pawn.Value!.ToggleNoclip(); + + Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminNoclipMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName))); + } + + [ConsoleCommand("css_freeze", "Freeze a player.")] + [CommandHelper(1, "<#userid or name> [duration]")] + [RequiresPermissions("@css/slay")] + public void OnFreezeCommand(CCSPlayerController? caller, CommandInfo command) + { + if (!GetTarget(command, out var player)) + return; + + int time = 0; + int.TryParse(command.GetArg(2), out time); + + player!.Pawn.Value!.Freeze(); + + if (time > 0) + AddTimer(time, () => player.Pawn.Value!.Unfreeze()); + + Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminFreezeMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName))); + } + + [ConsoleCommand("css_unfreeze", "Unfreeze a player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/slay")] + public void OnUnfreezeCommand(CCSPlayerController? caller, CommandInfo command) + { + if (!GetTarget(command, out var player)) + return; + + player!.Pawn.Value!.Unfreeze(); + + Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminUnFreezeMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName))); + } + + [ConsoleCommand("css_respawn", "Respawn a dead player.")] + [CommandHelper(1, "<#userid or name>")] + [RequiresPermissions("@css/cheats")] + public void OnRespawnCommand(CCSPlayerController? caller, CommandInfo command) + { + if (!GetTarget(command, out var player)) + return; + + player!.Respawn(); + + Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminRespawnMessage}".Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName))); + } + + [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)); + + if (cvar == null) + { + command.ReplyToCommand($"Cvar \"{command.GetArg(1)}\" not found."); + return; + } + + if (cvar.Name.Equals("sv_cheats") && !AdminManager.PlayerHasPermissions(caller, "@css/cheats")) + { + command.ReplyToCommand($"You don't have permissions to change \"{command.GetArg(1)}\"."); + return; + } + + var value = command.GetArg(2); + + Server.ExecuteCommand($"{cvar.Name} {value}"); + + command.ReplyToCommand($"{caller!.PlayerName} changed cvar {cvar.Name} to {value}."); + Logger.LogInformation($"{caller.PlayerName} changed cvar {cvar.Name} to {value}."); + } + + [ConsoleCommand("css_rcon", "Run a server console command.")] + [CommandHelper(1, "")] + [RequiresPermissions("@css/rcon")] + public void OnRcomCommand(CCSPlayerController? caller, CommandInfo command) + { + Server.ExecuteCommand(command.ArgString); + + Logger.LogInformation($"{caller!.PlayerName} executed command ({command.ArgString})."); + } + + private static bool GetTarget(CommandInfo command, out CCSPlayerController? player) { diff --git a/Config.cs b/Config.cs index 1d0601c..569b434 100644 --- a/Config.cs +++ b/Config.cs @@ -24,12 +24,22 @@ public class Messages public string AdminSlapMessage { get; set; } = "Admin {ADMIN} slapped {PLAYER}!"; [JsonPropertyName("AdminChangeMap")] public string AdminChangeMap { get; set; } = "Admin {ADMIN} changed map to {MAP}!"; + [JsonPropertyName("AdminNoclipMessage")] + public string AdminNoclipMessage { get; set; } = "Admin {ADMIN} toggled noclip for {PLAYER}!"; + [JsonPropertyName("AdminFreezeMessage")] + public string AdminFreezeMessage { get; set; } = "Admin {ADMIN} freezed {PLAYER}!"; + [JsonPropertyName("AdminUnFreezeMessage")] + public string AdminUnFreezeMessage { get; set; } = "Admin {ADMIN} unfreezed {PLAYER}!"; + [JsonPropertyName("AdminRespawnMessage")] + public string AdminRespawnMessage { get; set; } = "Admin {ADMIN} respawned {PLAYER}!"; [JsonPropertyName("AdminSayPrefix")] public string AdminSayPrefix { get; set; } = "{RED}ADMIN: {DEFAULT}"; [JsonPropertyName("AdminHelpCommand")] public string AdminHelpCommand { get; set; } = "{GREEN}[ CS2-SimpleAdmin HELP ]{DEFAULT}\n- css_ban <#userid or name> [time in minutes/0 perm] [reason] - Ban player\n- css_kick <#userid or name> [reason] - Kick player\n" + "- css_slay <#userid or name> - Kill player\n- css_slap <#userid or name> [damage] - Slap player\n- css_map - Change map\n- css_say - Say message as admin in chat\n" + - "- css_psay <#userid or name> - Sends private message to player\n- css_csay - Say message as admin in center\n- css_hsay - Say message as admin in hud"; + "- css_psay <#userid or name> - Sends private message to player\n- css_csay - Say message as admin in center\n- css_hsay - Say message as admin in hud\n" + + "- css_noclip <#userid or name> - Toggle noclip for player\n- css_freeze <#userid or name> [duration] - Freeze player\n- css_unfreeze <#userid or name> - Unfreeze player\n" + + "- css_respawn <#userid or name> - Respawn player\n- css_cvar - Change cvar value\n- css_rcon - Run command as server"; } public class CS2_SimpleAdminConfig : BasePluginConfig diff --git a/README.md b/README.md index 76f08fb..dd3661d 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,22 @@ Manage your Counter-Strike 2 server by simple commands :) It's only plugin base, I don't have much time for more extensive development, so if you want to help, do it :) ### Commands -- css_ban <#userid or name> [time in minutes/0 perm] [reason] - Ban player -- css_kick <#userid or name> [reason] - Kick player -- css_slay <#userid or name> - Kill player -- css_slap <#userid or name> [damage] - Slap player -- css_map - Change map -- css_say - Say message as admin in chat -- css_psay <#userid or name> - Sends private message to player -- css_csay - Say message as admin in center -- css_hsay - Say message as admin in hud +- css_admin - Display all admin commands // @css/generic +- css_ban <#userid or name> [time in minutes/0 perm] [reason] - Ban player // @css/ban +- css_kick <#userid or name> [reason] - Kick player / @css/kick +- css_slay <#userid or name> - Kill player // @css/slay +- css_slap <#userid or name> [damage] - Slap player // @css/slay +- css_map - Change map // @css/map +- css_say - Say message as admin in chat // @css/chat +- css_psay <#userid or name> - Sends private message to player // @css/chat +- css_csay - Say message as admin in center // @css/chat +- css_hsay - Say message as admin in hud // @css/chat +- css_noclip <#userid or name> - Toggle noclip for player // @css/cheats +- css_freeze <#userid or name> [duration] - Freeze player // @css/slay +- css_unfreeze <#userid or name> - Unfreeze player // @css/slay +- css_respawn <#userid or name> - Respawn player // @css/cheats +- css_cvar - Change cvar value // @css/cvar +- css_rcon - Run command as server // @css/rcon ### Requirments