From d751bdadbdd44f5546a55c2132e40cbefd383b1f Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Wed, 17 Jan 2024 23:08:52 +0100 Subject: [PATCH] 1.2.7b - Back to net7 - SilentMode for admins - Adding global admins via command --- .github/workflows/build.yml | 4 +- AdminSQLManager.cs | 22 ++- CS2-SimpleAdmin.cs | 326 +++++++++++++++++++++++++----------- CS2-SimpleAdmin.csproj | 4 +- Events.cs | 5 + 5 files changed, 256 insertions(+), 105 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6a20dea..c93c496 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: 7.0.x - name: Restore run: dotnet restore - name: Build @@ -42,7 +42,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 8.0.x + dotnet-version: 7.0.x - name: Restore run: dotnet restore - name: Build diff --git a/AdminSQLManager.cs b/AdminSQLManager.cs index 0577aa5..91782e5 100644 --- a/AdminSQLManager.cs +++ b/AdminSQLManager.cs @@ -238,7 +238,7 @@ namespace CS2_SimpleAdmin } } - public async Task DeleteAdminBySteamId(string playerSteamId) + public async Task DeleteAdminBySteamId(string playerSteamId, bool globalDelete = false) { if (string.IsNullOrEmpty(playerSteamId)) return; @@ -247,11 +247,21 @@ namespace CS2_SimpleAdmin await using var connection = _dbConnection; await connection.OpenAsync(); - string sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID"; - await connection.ExecuteAsync(sql, new { PlayerSteamID = playerSteamId }); + string sql = ""; + + if (globalDelete) + { + sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID"; + } + else + { + sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID AND server_id = @ServerId"; + } + + await connection.ExecuteAsync(sql, new { PlayerSteamID = playerSteamId, ServerId = CS2_SimpleAdmin.ServerId }); } - public async Task AddAdminBySteamId(string playerSteamId, string playerName, string flags, int immunity = 0, int time = 0) + public async Task AddAdminBySteamId(string playerSteamId, string playerName, string flags, int immunity = 0, int time = 0, bool globalAdmin = false) { if (string.IsNullOrEmpty(playerSteamId)) return; @@ -270,6 +280,8 @@ namespace CS2_SimpleAdmin var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`, `server_id`) " + "VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)"; + int? serverId = globalAdmin ? null : CS2_SimpleAdmin.ServerId; + await connection.ExecuteAsync(sql, new { playerSteamId, @@ -278,7 +290,7 @@ namespace CS2_SimpleAdmin immunity, ends = futureTime, created = now, - serverid = CS2_SimpleAdmin.ServerId + serverid = serverId }); } diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index d81e55b..6ed3f81 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -27,6 +27,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig loadedPlayers = new List(); public static Dictionary voteAnswers = new Dictionary(); public static List GodPlayers = new List(); + public static List SilentPlayers = new List(); public static bool TagsDetected = false; public static bool voteInProgress = false; public static int? ServerId = null; @@ -35,7 +36,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin"; public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy"; - public override string ModuleVersion => "1.2.7a"; + public override string ModuleVersion => "1.2.7b"; public CS2_SimpleAdminConfig Config { get; set; } = new(); @@ -182,20 +183,21 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { @@ -254,7 +257,24 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Helper.KickPlayer((ushort)player.UserId!)); } - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -486,16 +510,24 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Helper.KickPlayer((ushort)player!.UserId!)); + if (time == 0) { player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); + Server.PrintToChatAll(sb.ToString()); + } } else { player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - Server.PrintToChatAll(sb.ToString()); - } - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!)); + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); + Server.PrintToChatAll(sb.ToString()); + } + } }); } @@ -1087,23 +1151,30 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Helper.KickPlayer((ushort)player.UserId!)); if (time == 0) { player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); + Server.PrintToChatAll(sb.ToString()); + } } else { player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); - Server.PrintToChatAll(sb.ToString()); - } - AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!)); + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]); + Server.PrintToChatAll(sb.ToString()); + } + } } } @@ -1165,16 +1236,24 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Helper.KickPlayer((ushort)player.UserId!, "Banned")); @@ -1221,9 +1300,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { player.CommitSuicide(false, true); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_slay_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -1265,9 +1348,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { player.GiveNamedItem(weaponName); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_give_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, weaponName]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -1285,8 +1372,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { @@ -1644,9 +1763,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { player!.Pawn.Value!.ToggleNoclip(); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -1668,9 +1791,12 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig 0) AddTimer(time, () => player.Pawn.Value!.Unfreeze()); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -1685,9 +1811,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { player!.Pawn.Value!.Unfreeze(); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_unfreeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } }); } @@ -1702,9 +1832,13 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { player!.Respawn(); - StringBuilder sb = new(_localizer!["sa_prefix"]); - sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + + if (!SilentPlayers.Contains((int)caller!.Index)) + { + StringBuilder sb = new(_localizer!["sa_prefix"]); + sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } }); } diff --git a/CS2-SimpleAdmin.csproj b/CS2-SimpleAdmin.csproj index 7dc2678..4276839 100644 --- a/CS2-SimpleAdmin.csproj +++ b/CS2-SimpleAdmin.csproj @@ -1,7 +1,7 @@ - net8.0 + net7.0 CS2_SimpleAdmin enable enable @@ -9,7 +9,7 @@ - + diff --git a/Events.cs b/Events.cs index 307e163..eaa1513 100644 --- a/Events.cs +++ b/Events.cs @@ -338,6 +338,11 @@ public partial class CS2_SimpleAdmin } } + if (SilentPlayers.Contains((int)player.Index)) + { + SilentPlayers.Remove((int)player.Index); + } + if (GodPlayers.Contains((int)player.Index)) { GodPlayers.Remove((int)player.Index);