diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index f3de1b6..44b13db 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -12,7 +12,7 @@ namespace CS2_SimpleAdmin; -[MinimumApiVersion(178)] +[MinimumApiVersion(191)] public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { public static CS2_SimpleAdmin Instance { get; private set; } = new(); @@ -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.6a"; + public override string ModuleVersion => "1.3.6b"; public CS2_SimpleAdminConfig Config { get; set; } = new(); diff --git a/CS2-SimpleAdmin.csproj b/CS2-SimpleAdmin.csproj index efc1da2..dc0a740 100644 --- a/CS2-SimpleAdmin.csproj +++ b/CS2-SimpleAdmin.csproj @@ -10,7 +10,7 @@ - + diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 87be2f3..1a56e49 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -358,7 +358,6 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command) await _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag) }); - if (TagsDetected) Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}"); }); @@ -695,7 +694,6 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command) player.VoiceFlags = VoiceFlags.Normal; }); */ - } [ConsoleCommand("css_silence")] diff --git a/Config.cs b/Config.cs index 3faf684..5b83208 100644 --- a/Config.cs +++ b/Config.cs @@ -16,8 +16,10 @@ public class CustomServerCommandData { [JsonPropertyName("Flag")] public string Flag { get; set; } = "@css/generic"; + [JsonPropertyName("DisplayName")] public string DisplayName { get; set; } = ""; + [JsonPropertyName("Command")] public string Command { get; set; } = ""; } diff --git a/Events.cs b/Events.cs index d3d980f..e7c1045 100644 --- a/Events.cs +++ b/Events.cs @@ -4,6 +4,7 @@ using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Cvars; +using CounterStrikeSharp.API.Modules.Entities; using Dapper; using Microsoft.Extensions.Logging; using System.Data; @@ -17,13 +18,13 @@ public partial class CS2_SimpleAdmin private void RegisterEvents() { RegisterListener(OnMapStart); - RegisterListener(OnClientConnected); - RegisterListener(OnClientDisconnectPost); + //RegisterListener(OnClientConnected); + RegisterListener(OnClientDisconnect); AddCommandListener("say", OnCommandSay); AddCommandListener("say_team", OnCommandTeamSay); } - private void OnClientDisconnectPost(int playerSlot) + private void OnClientDisconnect(int playerSlot) { CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot); @@ -31,7 +32,7 @@ private void OnClientDisconnectPost(int playerSlot) Logger.LogCritical("[OnClientDisconnect] Before"); #endif - if (player is null || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17) return; + if (player is null || !player.IsValid || string.IsNullOrEmpty(player.CrosshairCodes) || player.IsBot || player.IsHLTV || !player.UserId.HasValue) return; #if DEBUG Logger.LogCritical("[OnClientDisconnect] After Check"); @@ -47,23 +48,40 @@ private void OnClientDisconnectPost(int playerSlot) if (godPlayers.Contains(player.Slot)) RemoveFromConcurrentBag(godPlayers, player.Slot); - if (player.AuthorizedSteamID == null) return; + SteamID? authorizedSteamID = player.AuthorizedSteamID; - if (AdminSQLManager._adminCache.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime) - && expirationTime <= DateTime.Now) + if (authorizedSteamID == null) return; + + Task.Run(() => { - AdminManager.ClearPlayerPermissions(player.AuthorizedSteamID); - AdminManager.RemovePlayerAdminData(player.AuthorizedSteamID); - } - } + if (AdminSQLManager._adminCache.TryGetValue(authorizedSteamID, out DateTime? expirationTime) + && expirationTime <= DateTime.Now) + { + AdminManager.ClearPlayerPermissions(authorizedSteamID); + AdminManager.RemovePlayerAdminData(authorizedSteamID); + } + }); - private void OnClientConnected(int playerSlot) + //if (player.AuthorizedSteamID == null) return; + + //if (AdminSQLManager._adminCache.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime) + // && expirationTime <= DateTime.Now) + //{ + // AdminManager.ClearPlayerPermissions(player.AuthorizedSteamID); + // AdminManager.RemovePlayerAdminData(player.AuthorizedSteamID); + //} + } + [GameEventHandler] + public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info) { - CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot); + CCSPlayerController? player = @event.Userid; #if DEBUG Logger.LogCritical($"[OnPlayerConnect] Before check {player.PlayerName} : {player.IpAddress}"); #endif - if (player is null || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 || string.IsNullOrEmpty(player.IpAddress)) return; + if (player is null || string.IsNullOrEmpty(player.CrosshairCodes) + || string.IsNullOrEmpty(player.IpAddress) + || player.IsBot || player.IsHLTV || !player.UserId.HasValue) return HookResult.Continue; + #if DEBUG Logger.LogCritical("[OnPlayerConnect] After Check"); #endif @@ -71,13 +89,13 @@ private void OnClientConnected(int playerSlot) if (bannedPlayers.Contains(ipAddress) || bannedPlayers.Contains(player.SteamID.ToString())) { - if (!player.UserId.HasValue) return; + if (!player.UserId.HasValue) return HookResult.Continue; Helper.KickPlayer(player.UserId.Value, "Banned"); - return; + return HookResult.Continue; } if (_database == null || !player.UserId.HasValue || player.UserId == null) - return; + return HookResult.Continue; PlayerInfo playerInfo = new PlayerInfo { @@ -159,6 +177,8 @@ private void OnClientConnected(int playerSlot) } } }); + + return HookResult.Continue; } [GameEventHandler] @@ -224,15 +244,12 @@ private HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo inf [GameEventHandler] public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info) { - - return HookResult.Continue; } [GameEventHandler] public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info) { - return HookResult.Continue; } */ @@ -273,7 +290,6 @@ private void OnMapStart(string mapName) { try { - foreach (CCSPlayerController player in Helper.GetValidPlayers()) { if (playerPenaltyManager.IsSlotInPenalties(player.Slot)) diff --git a/Managers/AdminSQLManager.cs b/Managers/AdminSQLManager.cs index 1ba6550..871f54f 100644 --- a/Managers/AdminSQLManager.cs +++ b/Managers/AdminSQLManager.cs @@ -4,6 +4,7 @@ using System.Collections.Concurrent; namespace CS2_SimpleAdmin; + public class AdminSQLManager { private readonly Database _database; @@ -222,4 +223,4 @@ public async Task DeleteOldAdmins() CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired admins"); } } -} +} \ No newline at end of file diff --git a/Managers/BanManager.cs b/Managers/BanManager.cs index 44752e3..208aed8 100644 --- a/Managers/BanManager.cs +++ b/Managers/BanManager.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; namespace CS2_SimpleAdmin; + internal class BanManager { private readonly Database _database; @@ -188,14 +189,14 @@ public async Task ExpireOldBans() */ string sql = @" - UPDATE sa_bans - SET + UPDATE sa_bans + SET status = 'EXPIRED' - WHERE - status = 'ACTIVE' - AND - `duration` > 0 - AND + WHERE + status = 'ACTIVE' + AND + `duration` > 0 + AND ends <= @currentTime"; await connection.ExecuteAsync(sql, new { currentTime }); @@ -205,21 +206,20 @@ UPDATE sa_bans DateTime ipBansTime = currentTime.AddDays(-_config.ExpireOldIpBans).ToLocalTime(); sql = @" - UPDATE sa_bans - SET + UPDATE sa_bans + SET player_ip = NULL - WHERE - status = 'ACTIVE' - AND + WHERE + status = 'ACTIVE' + AND ends <= @ipBansTime"; await connection.ExecuteAsync(sql, new { ipBansTime }); } - } catch (Exception) { CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired bans"); } } -} +} \ No newline at end of file diff --git a/Managers/MuteManager.cs b/Managers/MuteManager.cs index 7ab82dc..da693ea 100644 --- a/Managers/MuteManager.cs +++ b/Managers/MuteManager.cs @@ -2,6 +2,7 @@ using Microsoft.Extensions.Logging; namespace CS2_SimpleAdmin; + internal class MuteManager { private readonly Database _database; @@ -160,5 +161,4 @@ public async Task ExpireOldMutes() CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired mutes"); } } - -} +} \ No newline at end of file diff --git a/Managers/PlayerPenaltyManager.cs b/Managers/PlayerPenaltyManager.cs index 85ae3fe..f50cba9 100644 --- a/Managers/PlayerPenaltyManager.cs +++ b/Managers/PlayerPenaltyManager.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; namespace CS2_SimpleAdmin; + public enum PenaltyType { Mute, @@ -134,4 +135,4 @@ public void RemoveExpiredPenalties() } } } -} +} \ No newline at end of file diff --git a/lang/pl.json b/lang/pl.json index 5620864..1746cb8 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -47,5 +47,4 @@ "sa_adminchat_template_player": "{SILVER}(GRACZ) {lightred}{0}{default}: {lightred}{1}{default}", "sa_discord_log_command": "**{0}** użył komendy `{1}` na serwerze `HOSTNAME`" - } \ No newline at end of file