From fdbf1b1a5cb6a44debf7139b009315f219af73f9 Mon Sep 17 00:00:00 2001 From: daffyyyy Date: Wed, 6 Dec 2023 01:55:30 +0100 Subject: [PATCH] Respecting immunity and css_team command --- CS2-SimpleAdmin.cs | 159 ++++++++++++++++++++++++++++++++++++++------- Events.cs | 7 +- PlayerInfo.cs | 8 +-- PlayerUtils.cs | 6 ++ README.md | 1 + 5 files changed, 148 insertions(+), 33 deletions(-) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index da52c81..7011eb4 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -22,7 +22,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin"; public override string ModuleDescription => ""; public override string ModuleAuthor => "daffyy"; - public override string ModuleVersion => "1.0.4c"; + public override string ModuleVersion => "1.0.5"; public CS2_SimpleAdminConfig Config { get; set; } = new(); @@ -126,9 +126,15 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) { - if (!GetTarget(command, out var player)) + if (!GetTarget(command, out var player) || player == null || !player.IsValid) return; + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + player!.Pawn.Value!.Freeze(); string reason = "Unknown"; @@ -153,10 +159,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnGagCommand(CCSPlayerController? caller, CommandInfo command) { - if (!GetTarget(command, out var player)) + if (!GetTarget(command, out var player) || player == null || !player.IsValid) return; - if (command.ArgCount < 2) + + if (!caller!.CanTarget(player) || command.ArgCount < 2) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); return; + } int time = 0; string reason = "Unknown"; @@ -252,14 +262,18 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig matches = Helper.GetPlayerFromSteamid64(steamid); if (matches.Count == 1) { CCSPlayerController? player = matches.FirstOrDefault(); if (player != null) { + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + if (time == 0) { player!.PrintToCenter($"{Config.Messages.PlayerGagMessagePerm}".Replace("{REASON}", reason).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName)); @@ -291,6 +305,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig [time in minutes/0 perm] [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnBanCommand(CCSPlayerController? caller, CommandInfo command) { - if (!GetTarget(command, out var player)) + if (!GetTarget(command, out var player) || command.ArgCount < 2) return; if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return; - if (command.ArgCount < 2) + + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); return; + } int time = 0; string reason = "Unknown"; @@ -465,11 +484,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig - { - BanManager _banManager = new(dbConnectionString); - await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time); - }); List matches = Helper.GetPlayerFromSteamid64(steamid); if (matches.Count == 1) @@ -477,6 +491,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig + { + BanManager _banManager = new(dbConnectionString); + await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time); + }); + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!)); } } @@ -523,12 +549,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig - { - BanManager _banManager = new(dbConnectionString); - await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time); - }); - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3) @@ -540,6 +560,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig + { + BanManager _banManager = new(dbConnectionString); + await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time); + }); + AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, "Banned")); } } @@ -584,8 +616,15 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnSlayCommand(CCSPlayerController? caller, CommandInfo command) { - if (!GetTarget(command, out CCSPlayerController? player)) + if (!GetTarget(command, out CCSPlayerController? player) || player == null || !player.IsValid) return; + + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + if (!player!.PawnIsAlive) return; @@ -599,8 +638,15 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig [damage]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] public void OnSlapCommand(CCSPlayerController? caller, CommandInfo command) { - if (!GetTarget(command, out CCSPlayerController? player)) + if (!GetTarget(command, out CCSPlayerController? player) || player == null || !player.IsValid) return; + + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + if (!player!.PawnIsAlive) return; @@ -616,6 +662,53 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig []", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] + public void OnTeamCommand(CCSPlayerController? caller, CommandInfo command) + { + if (!GetTarget(command, out CCSPlayerController? player) || player == null || !player.IsValid) + return; + + if (!caller!.CanTarget(player)) + { + command.ReplyToCommand($"{player.PlayerName} is more powerful than you!"); + return; + } + + string teamName = command.GetArg(2).ToLower(); + CsTeam teamNum = CsTeam.Spectator; + + switch (teamName) + { + case "ct": + case "counterterrorist": + teamNum = CsTeam.CounterTerrorist; + break; + case "t": + case "tt": + case "terrorist": + teamNum = CsTeam.Terrorist; + break; + default: + teamNum = CsTeam.Spectator; + break; + } + + if (player.TeamNum == ((byte)teamNum)) + { + command.ReplyToCommand($"{player.PlayerName} is already in selected team!"); + return; + } + + if (player.PawnIsAlive && teamNum != CsTeam.Spectator) + player.SwitchTeam(teamNum); + else + player.ChangeTeam(teamNum); + + command.ReplyToCommand($"Successfully changed team for {player.PlayerName}"); + } + [ConsoleCommand("css_map")] [RequiresPermissions("@css/changemap")] [CommandHelper(minArgs: 1, usage: "", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)] @@ -703,9 +796,15 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { @@ -60,7 +63,7 @@ namespace CS2_SimpleAdmin bool isBanned = await _banManager.IsPlayerBanned(playerInfo); MuteManager _muteManager = new(dbConnectionString); - List activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId); + List activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId!); Server.NextFrame(() => { diff --git a/PlayerInfo.cs b/PlayerInfo.cs index 60e40f0..13e55c2 100644 --- a/PlayerInfo.cs +++ b/PlayerInfo.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CS2_SimpleAdmin +namespace CS2_SimpleAdmin { public class PlayerInfo { diff --git a/PlayerUtils.cs b/PlayerUtils.cs index b5e4295..0156b0c 100644 --- a/PlayerUtils.cs +++ b/PlayerUtils.cs @@ -1,4 +1,5 @@ using CounterStrikeSharp.API.Core; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Utils; namespace CS2_SimpleAdmin; @@ -10,6 +11,11 @@ public static class PlayerUtils PerformSlap(pawn, damage); } + public static bool CanTarget(this CCSPlayerController controller, CCSPlayerController target) + { + return AdminManager.CanPlayerTarget(controller, target); + } + public static void Bury(this CBasePlayerPawn pawn, float depth = 10f) { var newPos = new Vector(pawn.AbsOrigin!.X, pawn.AbsOrigin.Y, diff --git a/README.md b/README.md index 6ecb7aa..17333c7 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ It's only plugin base, I don't have much time for more extensive development, so - css_unmute - Kill player // @css/slay - css_slap <#userid or name> [damage] - Slap player // @css/slay +- css_team <#userid or name> [] - Change player team // @css/kick - css_map - Change map // @css/changemap - css_wsmap - Change workshop map // @css/changemap - css_say - Say message as admin in chat // @css/chat