diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 27a89df..55d5ec3 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -38,7 +38,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 & Dliix66"; - public override string ModuleVersion => "1.3.4a"; + public override string ModuleVersion => "1.3.5a"; public CS2_SimpleAdminConfig Config { get; set; } = new(); diff --git a/Commands/basechat.cs b/Commands/basechat.cs index 7e03d6e..6cee028 100644 --- a/Commands/basechat.cs +++ b/Commands/basechat.cs @@ -78,6 +78,8 @@ public void OnAdminSayCommand(CCSPlayerController? caller, CommandInfo command) [RequiresPermissions("@css/chat")] public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo command) { + string callerName = caller == null ? "Console" : caller.PlayerName; + TargetResult? targets = GetTarget(command); if (targets == null) return; List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -92,7 +94,7 @@ public void OnAdminPrivateSayCommand(CCSPlayerController? caller, CommandInfo co playersToTarget.ForEach(player => { - player.PrintToChat(StringExtensions.ReplaceColorTags($"({caller!.PlayerName}) {utf8String}")); + player.PrintToChat(StringExtensions.ReplaceColorTags($"({callerName}) {utf8String}")); }); command.ReplyToCommand(StringExtensions.ReplaceColorTags($" Private message sent!")); diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index 7449f08..526a6d0 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -29,9 +29,11 @@ public void OnSaUpgradeCommand(CCSPlayerController? caller, CommandInfo command) using var connection = await _database.GetConnectionAsync(); var commandText = "ALTER TABLE `sa_mutes` CHANGE `type` `type` ENUM('GAG','MUTE', 'SILENCE', '') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'GAG';"; - using var command = connection.CreateCommand(); - command.CommandText = commandText; - await command.ExecuteNonQueryAsync(); + using var commandSql = connection.CreateCommand(); + commandSql.CommandText = commandText; + await commandSql.ExecuteNonQueryAsync(); + + command.ReplyToCommand("Successfully updated the database"); } catch (Exception ex) { @@ -42,7 +44,7 @@ public void OnSaUpgradeCommand(CCSPlayerController? caller, CommandInfo command) [ConsoleCommand("css_admin")] [RequiresPermissions("@css/generic")] - [CommandHelper(minArgs: 0, usage: "", whoCanExecute: CommandUsage.CLIENT_ONLY)] + [CommandHelper(whoCanExecute: CommandUsage.CLIENT_ONLY)] public void OnAdminCommand(CCSPlayerController? caller, CommandInfo command) { if (caller == null || caller.IsValid == false) diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index b97b104..95ba1c1 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -260,6 +260,8 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; string callerName = caller == null ? "Console" : caller.PlayerName; + string foundPlayerName = string.Empty; + string foundPlayerSteamId64 = string.Empty; if (command.GetArg(1).Length <= 1) { @@ -282,11 +284,6 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - Task.Run(async () => - { - await _muteManager.UnmutePlayer(pattern, 0); // Unmute by type 0 (gag) - }); - if (Helper.IsValidSteamID64(pattern)) { List matches = Helper.GetPlayerFromSteamid64(pattern); @@ -301,6 +298,8 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } @@ -320,10 +319,24 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) pattern = player!.SteamID.ToString(); found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } + if (found) + { + Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 0); }); // Unmute by type 0 (gag) + command.ReplyToCommand($"Ungaged player {foundPlayerName}."); + } + else + { + Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 0); }); // Unmute by type 0 (gag) + command.ReplyToCommand($"Ungaged offline player with pattern {pattern}."); + } + + /* TargetResult? targets = GetTarget(command); if (targets == null) return; List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -352,7 +365,7 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) command.ReplyToCommand($"Ungaged player with pattern {pattern}."); return; - } + */ } [ConsoleCommand("css_mute")] @@ -591,6 +604,8 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; string callerName = caller == null ? "Console" : caller.PlayerName; + string foundPlayerName = string.Empty; + string foundPlayerSteamId64 = string.Empty; if (command.GetArg(1).Length <= 1) { @@ -611,11 +626,6 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) MuteManager _muteManager = new(_database); PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - Task.Run(async () => - { - await _muteManager.UnmutePlayer(pattern, 1); // Unmute by type 1 (mute) - }); - if (Helper.IsValidSteamID64(pattern)) { List matches = Helper.GetPlayerFromSteamid64(pattern); @@ -627,6 +637,8 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); player.VoiceFlags = VoiceFlags.Normal; found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } @@ -642,16 +654,24 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) player.VoiceFlags = VoiceFlags.Normal; pattern = player.SteamID.ToString(); found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } if (found) { - command.ReplyToCommand($"Unmuted player with pattern {pattern}."); - return; + Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 1); }); // Unmute by type 1 (mute) + command.ReplyToCommand($"Unmuted player {foundPlayerName}."); + } + else + { + Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 1); }); // Unmute by type 1 (mute) + command.ReplyToCommand($"Unmuted offline player with pattern {pattern}."); } + /* TargetResult? targets = GetTarget(command); if (targets == null) return; List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -674,10 +694,8 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute); player.VoiceFlags = VoiceFlags.Normal; }); + */ - command.ReplyToCommand($"Unmuted player with pattern {pattern}."); - return; - } } [ConsoleCommand("css_silence")] @@ -926,6 +944,8 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) { if (_database == null) return; string callerName = caller == null ? "Console" : caller.PlayerName; + string foundPlayerName = string.Empty; + string foundPlayerSteamId64 = string.Empty; if (command.GetArg(1).Length <= 1) { @@ -946,11 +966,6 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) MuteManager _muteManager = new(_database); PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); - Task.Run(async () => - { - await _muteManager.UnmutePlayer(pattern, 2); // Unmute by type 2 (silence) - }); - if (Helper.IsValidSteamID64(pattern)) { List matches = Helper.GetPlayerFromSteamid64(pattern); @@ -965,6 +980,8 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence); player.VoiceFlags = VoiceFlags.Normal; found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } @@ -983,17 +1000,25 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) player.VoiceFlags = VoiceFlags.Normal; pattern = player.SteamID.ToString(); found = true; + foundPlayerName = player.PlayerName; + foundPlayerSteamId64 = player.SteamID.ToString(); } } } if (found) { - //Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 2); }); // Unmute by type 2 (silence) - command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); + Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 2); }); // Unmute by type 2 (silence) + command.ReplyToCommand($"Unsilenced player {foundPlayerName}."); return; } - + else + { + Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 2); }); // Unmute by type 2 (silence) + command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}."); + return; + } + /* TargetResult? targets = GetTarget(command); if (targets == null) return; List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -1019,7 +1044,7 @@ public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command) command.ReplyToCommand($"Unsilenced player with pattern {pattern}."); return; - } + */ } } } \ No newline at end of file diff --git a/Config.cs b/Config.cs index a21dcaa..3faf684 100644 --- a/Config.cs +++ b/Config.cs @@ -24,7 +24,7 @@ public class CustomServerCommandData public class CS2_SimpleAdminConfig : BasePluginConfig { - [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 7; + [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 8; [JsonPropertyName("DatabaseHost")] public string DatabaseHost { get; set; } = ""; diff --git a/Events.cs b/Events.cs index 773bd3c..32ddc60 100644 --- a/Events.cs +++ b/Events.cs @@ -254,32 +254,37 @@ private void OnMapStart(string mapName) Server.NextFrame(() => { - foreach (CCSPlayerController player in Helper.GetValidPlayers()) + try { - if (playerPenaltyManager.IsSlotInPenalties(player.Slot)) - { - if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) - player.VoiceFlags = VoiceFlags.Normal; - if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) + foreach (CCSPlayerController player in Helper.GetValidPlayers()) + { + if (playerPenaltyManager.IsSlotInPenalties(player.Slot)) { - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); - } + if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) + player.VoiceFlags = VoiceFlags.Normal; - if ( - !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) && - !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && - !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) - ) - { - player.VoiceFlags = VoiceFlags.Normal; + if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) + { + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + } - if (TagsDetected) - Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + if ( + !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) && + !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && + !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) + ) + { + player.VoiceFlags = VoiceFlags.Normal; + + if (TagsDetected) + Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); + } } } } + catch (Exception) { } }); playerPenaltyManager.RemoveExpiredPenalties(); diff --git a/Helper.cs b/Helper.cs index 6771f48..5f2463d 100644 --- a/Helper.cs +++ b/Helper.cs @@ -25,7 +25,7 @@ internal class Helper public static List GetPlayerFromName(string name) { - return Utilities.GetPlayers().FindAll(x => x.PlayerName.Contains(name, StringComparison.OrdinalIgnoreCase)); + return Utilities.GetPlayers().FindAll(x => x.PlayerName.Equals(name, StringComparison.OrdinalIgnoreCase)); } public static List GetPlayerFromSteamid64(string steamid) diff --git a/Managers/PlayerPenaltyManager.cs b/Managers/PlayerPenaltyManager.cs index 9a925f9..b69bb6e 100644 --- a/Managers/PlayerPenaltyManager.cs +++ b/Managers/PlayerPenaltyManager.cs @@ -37,7 +37,7 @@ public bool IsPenalized(int slot, PenaltyType penaltyType) { //Console.WriteLine($"Found penalties for player with slot {slot} and penalty type {penaltyType}"); - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; // Check if any active penalties exist foreach (var penalty in penaltiesList.ToList()) @@ -115,7 +115,7 @@ public void RemovePenaltiesByType(int slot, PenaltyType penaltyType) // Remove all expired penalties for all players and penalty types public void RemoveExpiredPenalties() { - DateTime now = DateTime.Now; + DateTime now = DateTime.UtcNow; foreach (var kvp in penalties.ToList()) // Use ToList to avoid modification while iterating { var playerSlot = kvp.Key;