diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index b6182f1..55598e5 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -22,12 +22,12 @@ namespace CS2_SimpleAdmin; public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { public static IStringLocalizer? _localizer; - public static ConcurrentBag gaggedPlayers = new ConcurrentBag(); + public static ConcurrentBag gaggedPlayers = new ConcurrentBag(); //public static ConcurrentBag mutedPlayers = new ConcurrentBag(); public static List loadedPlayers = new List(); public static Dictionary voteAnswers = new Dictionary(); - public static HashSet godPlayers = new HashSet(); - public static List silentPlayers = new List(); + public static HashSet godPlayers = new HashSet(); + public static List silentPlayers = new List(); public static HashSet bannedPlayers = new HashSet(); public static bool TagsDetected = false; public static bool voteInProgress = false; @@ -37,7 +37,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.7d"; + public override string ModuleVersion => "1.2.7e"; public CS2_SimpleAdminConfig Config { get; set; } = new(); @@ -266,14 +266,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig Helper.KickPlayer((ushort)player.UserId!)); } - if (caller == null || caller != null && !silentPlayers.Contains((int)caller!.Index)) + if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId)) { StringBuilder sb = new(_localizer!["sa_prefix"]); sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]); @@ -495,10 +497,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig 0 && time <= 30) { @@ -507,11 +509,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig 0 && time <= 30) { @@ -626,11 +628,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { - if (gaggedPlayers.Contains((int)player.Index)) + if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId)) { - if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index) + if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId) { gaggedPlayers.Add(removedItem); } @@ -744,7 +746,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig 0 && time <= 30) @@ -1113,7 +1115,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { - if (!godPlayers.Contains((int)player.Index)) - godPlayers.Add((int)player.Index); - else - godPlayers.Remove((int)player.Index); - - StringBuilder sb = new(_localizer!["sa_prefix"]); - - if (caller == null || caller != null && !silentPlayers.Contains((int)caller!.Index)) + if (player != null && player.UserId != null) { - sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); - Server.PrintToChatAll(sb.ToString()); + if (!godPlayers.Contains((ushort)player.UserId)) + godPlayers.Add((ushort)player.UserId); + else + godPlayers.Remove((ushort)player.UserId); + + StringBuilder sb = new(_localizer!["sa_prefix"]); + + if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller!.UserId)) + { + sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); + Server.PrintToChatAll(sb.ToString()); + } } }); } @@ -1514,7 +1519,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig 0) AddTimer(time, () => player.Pawn.Value!.Unfreeze()); - if (caller == null || caller != null && !silentPlayers.Contains((int)caller!.Index)) + if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId)) { StringBuilder sb = new(_localizer!["sa_prefix"]); sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]); @@ -1842,7 +1847,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig + net7.0 @@ -9,7 +9,7 @@ - + diff --git a/Events.cs b/Events.cs index 38be2b4..1aec8c0 100644 --- a/Events.cs +++ b/Events.cs @@ -36,7 +36,7 @@ public partial class CS2_SimpleAdmin PlayerInfo playerInfo = new PlayerInfo { UserId = player.UserId, - Index = (int)player.Index, + Index = (ushort)player.UserId, SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), Name = player?.PlayerName, IpAddress = player?.IpAddress?.Split(":")[0] @@ -63,7 +63,7 @@ public partial class CS2_SimpleAdmin { if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue; - if (gaggedPlayers.Contains((int)player.Index)) + if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId)) { return HookResult.Handled; } @@ -75,7 +75,7 @@ public partial class CS2_SimpleAdmin { if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue; - if (gaggedPlayers.Contains((int)player.Index)) + if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId)) { return HookResult.Handled; } @@ -129,7 +129,7 @@ public partial class CS2_SimpleAdmin { CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot); - if (player == null || !player.IsValid || player.IpAddress == null || loadedPlayers.Contains((int)player.Index) || player.IsBot || player.IsHLTV) + if (player == null || !player.IsValid || player.IpAddress == null || player.UserId == null || loadedPlayers.Contains((ushort)player.UserId) || player.IsBot || player.IsHLTV) return; if (bannedPlayers.Contains(player.IpAddress) || player.AuthorizedSteamID != null && bannedPlayers.Contains(player.AuthorizedSteamID.SteamId64.ToString())) @@ -138,7 +138,7 @@ public partial class CS2_SimpleAdmin PlayerInfo playerInfo = new PlayerInfo { UserId = player.UserId, - Index = (int)player.Index, + Index = (ushort)player.UserId, SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), Name = player?.PlayerName, IpAddress = player?.IpAddress.Split(":")[0] @@ -179,7 +179,7 @@ public partial class CS2_SimpleAdmin PlayerInfo playerInfo = new PlayerInfo { UserId = player.UserId, - Index = (int)player.Index, + Index = (ushort)player.Index, SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(), Name = player?.PlayerName, IpAddress = player?.IpAddress?.Split(":")[0] @@ -223,11 +223,11 @@ public partial class CS2_SimpleAdmin if (muteType == "GAG") { // Chat mute - if (!gaggedPlayers.Any(index => index == player.Index)) - gaggedPlayers.Add((int)player.Index); + if (player.UserId != null && !gaggedPlayers.Any(index => index == (ushort)player.UserId)) + gaggedPlayers.Add((ushort)player.UserId); if (TagsDetected) - NativeAPI.IssueServerCommand($"css_tag_mute {player.Index}"); + NativeAPI.IssueServerCommand($"css_tag_mute {player.UserId}"); if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30) { @@ -235,16 +235,16 @@ public partial class CS2_SimpleAdmin { if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return; - if (gaggedPlayers.Contains((int)player.Index)) + if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId)) { - if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index) + if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (int)player.UserId) { gaggedPlayers.Add(removedItem); } } if (TagsDetected) - NativeAPI.IssueServerCommand($"css_tag_unmute {player.Index}"); + NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}"); MuteManager _muteManager = new(dbConnectionString); _ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0); @@ -277,9 +277,9 @@ public partial class CS2_SimpleAdmin if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return; /* - if (mutedPlayers.Contains((int)player.Index)) + if (mutedPlayers.Contains((ushort)player.UserId)) { - if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index) + if (mutedPlayers.TryTake(out int removedItem) && removedItem != (ushort)player.UserId) { mutedPlayers.Add(removedItem); } @@ -329,8 +329,8 @@ public partial class CS2_SimpleAdmin } */ - if (!loadedPlayers.Contains((int)player.Index)) - loadedPlayers.Add((int)player.Index); + if (player.UserId != null && !loadedPlayers.Contains((ushort)player.UserId)) + loadedPlayers.Add((ushort)player.UserId); }); }); } @@ -341,36 +341,36 @@ public partial class CS2_SimpleAdmin if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return; - if (gaggedPlayers.Contains((int)player.Index)) + if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId)) { - if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index) + if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId) { gaggedPlayers.Add(removedItem); } } /* - if (mutedPlayers.Contains((int)player.Index)) + if (mutedPlayers.Contains((ushort)player.UserId)) { - if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index) + if (mutedPlayers.TryTake(out int removedItem) && removedItem != (ushort)player.UserId) { mutedPlayers.Add(removedItem); } } */ - if (silentPlayers.Contains((int)player.Index)) + if (player.UserId != null && silentPlayers.Contains((ushort)player.UserId)) { - silentPlayers.Remove((int)player.Index); + silentPlayers.Remove((ushort)player.UserId); } - if (godPlayers.Contains((int)player.Index)) + if (player.UserId != null && godPlayers.Contains((ushort)player.UserId)) { - godPlayers.Remove((int)player.Index); + godPlayers.Remove((ushort)player.UserId); } - if (loadedPlayers.Contains((int)player.Index)) - loadedPlayers.Remove((int)player.Index); + if (player.UserId != null && loadedPlayers.Contains((ushort)player.UserId)) + loadedPlayers.Remove((ushort)player.UserId); if (player.AuthorizedSteamID != null && AdminSQLManager._adminCacheSet.Contains(player.AuthorizedSteamID)) { @@ -382,7 +382,7 @@ public partial class CS2_SimpleAdmin } if (TagsDetected) - NativeAPI.IssueServerCommand($"css_tag_unmute {player!.Index}"); + NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}"); } private void OnMapStart(string mapName) @@ -433,7 +433,7 @@ public partial class CS2_SimpleAdmin if (player == null || !player.IsValid) return HookResult.Continue; - if (godPlayers.Contains((int)player.Index) && player.PawnIsAlive) + if (player.UserId != null && godPlayers.Contains((ushort)player.UserId) && player.PawnIsAlive) { player.Health = 100; player.PlayerPawn.Value!.Health = 100; diff --git a/MuteManager.cs b/MuteManager.cs index 6d68598..519ce27 100644 --- a/MuteManager.cs +++ b/MuteManager.cs @@ -147,7 +147,7 @@ namespace CS2_SimpleAdmin public async Task CheckMute(PlayerInfo player) { - if (player.Index == null) return; + if (player.UserId == null) return; string steamId = player.SteamId!; List activeMutes = await IsPlayerMuted(steamId); @@ -162,11 +162,11 @@ namespace CS2_SimpleAdmin if (muteType == "GAG") { - if (!CS2_SimpleAdmin.gaggedPlayers.Any(index => index == player.Index)) - CS2_SimpleAdmin.gaggedPlayers.Add((int)player.Index); + if (!CS2_SimpleAdmin.gaggedPlayers.Any(index => index == player.UserId)) + CS2_SimpleAdmin.gaggedPlayers.Add((ushort)player.UserId); if (CS2_SimpleAdmin.TagsDetected) - NativeAPI.IssueServerCommand($"css_tag_mute {player!.Index}"); + NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}"); /* CCSPlayerController currentPlayer = player;