Skip to content

Commit

Permalink
Additional commands
Browse files Browse the repository at this point in the history
  • Loading branch information
daffyyyy committed Dec 2, 2023
1 parent 68a446a commit 35e6a52
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 11 deletions.
99 changes: 98 additions & 1 deletion CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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, "<cvar> <value>")]
[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, "<command>")]
[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)
{
Expand Down
12 changes: 11 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mapname> - Change map\n- css_say <message> - Say message as admin in chat\n" +
"- css_psay <#userid or name> <message> - Sends private message to player\n- css_csay <message> - Say message as admin in center\n- css_hsay <message> - Say message as admin in hud";
"- css_psay <#userid or name> <message> - Sends private message to player\n- css_csay <message> - Say message as admin in center\n- css_hsay <message> - 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 <cvar> <value> - Change cvar value\n- css_rcon <command> - Run command as server";
}

public class CS2_SimpleAdminConfig : BasePluginConfig
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mapname> - Change map
- css_say <message> - Say message as admin in chat
- css_psay <#userid or name> <message> - Sends private message to player
- css_csay <message> - Say message as admin in center
- css_hsay <message> - 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 <mapname> - Change map // @css/map
- css_say <message> - Say message as admin in chat // @css/chat
- css_psay <#userid or name> <message> - Sends private message to player // @css/chat
- css_csay <message> - Say message as admin in center // @css/chat
- css_hsay <message> - 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 <cvar> <value> - Change cvar value // @css/cvar
- css_rcon <command> - Run command as server // @css/rcon


### Requirments
Expand Down

0 comments on commit 35e6a52

Please sign in to comment.