diff --git a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs index a16ab9c..23a403c 100644 --- a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs @@ -22,7 +22,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)"); public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy"; - public override string ModuleVersion => "1.8.2b-zio14"; + public override string ModuleVersion => "1.8.2b-zio15"; public override void Load(bool hotReload) { diff --git a/CS2-SimpleAdmin/Managers/MuteManager.cs b/CS2-SimpleAdmin/Managers/MuteManager.cs index 01d83df..6f9b65b 100644 --- a/CS2-SimpleAdmin/Managers/MuteManager.cs +++ b/CS2-SimpleAdmin/Managers/MuteManager.cs @@ -212,7 +212,15 @@ internal class MuteManager(IDatabaseProvider? databaseProvider) foreach (var muteRecord in muteRecords) { DateTime endDateTime = muteRecord.ends; - PlayerPenaltyManager.RemovePenaltiesByDateTime(slot, endDateTime); + // zio: match by type and approximate end time; see RemovePenaltiesByDateTime. + string muteType = muteRecord.type; + var penaltyType = muteType switch + { + "MUTE" => PenaltyType.Mute, + "SILENCE" => PenaltyType.Silence, + _ => PenaltyType.Gag + }; + PlayerPenaltyManager.RemovePenaltiesByDateTime(slot, penaltyType, endDateTime); } } diff --git a/CS2-SimpleAdmin/Managers/PlayerPenaltyManager.cs b/CS2-SimpleAdmin/Managers/PlayerPenaltyManager.cs index 7931fe3..9acdc04 100644 --- a/CS2-SimpleAdmin/Managers/PlayerPenaltyManager.cs +++ b/CS2-SimpleAdmin/Managers/PlayerPenaltyManager.cs @@ -95,9 +95,11 @@ public static class PlayerPenaltyManager if (CS2_SimpleAdmin.Instance.Config.OtherSettings.TimeMode == 0) { - if (penaltiesList.Count == 0) return false; - - endDateTime = penaltiesList.First().EndDateTime; + // zio: a penalty marked passed is over, even before RemoveExpiredPenalties drops it. + var active = penaltiesList.FirstOrDefault(p => !p.Passed || p.Duration == 0); + if (active == default) return false; + + endDateTime = active.EndDateTime; return true; } @@ -255,6 +257,26 @@ public static class PlayerPenaltyManager } } + /// + /// zio: marks a penalty of one type as passed when its end is within a few seconds of the + /// database's. A penalty added in game keeps the end time from the command, which has + /// sub-second precision and is taken a moment before the one the database stores (to the + /// second), so an exact match never finds it and the penalty outlives its database row. + /// + public static void RemovePenaltiesByDateTime(int slot, PenaltyType penaltyType, DateTime dateTime) + { + if (!Penalties.TryGetValue(slot, out var penaltyDict) || + !penaltyDict.TryGetValue(penaltyType, out var penaltiesList)) return; + + for (var i = 0; i < penaltiesList.Count; i++) + { + if ((penaltiesList[i].EndDateTime - dateTime).Duration() > TimeSpan.FromSeconds(5)) continue; + var penalty = penaltiesList[i]; + penalty.Passed = true; + penaltiesList[i] = penalty; + } + } + /// /// Removes or expires penalties automatically across all players based on their duration or "passed" flag. /// diff --git a/README.md b/README.md index 4a2bdb0..ee39a72 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ from the `build-1.8.2b` tag). Changes, all marked `zio:` in the code: highest-immunity group, and who changed it) to `sa_rank_log`, the table simpleadmin-web creates and lists as the public promotions/demotions log. If the table is missing, it warns once in the log and the admin change goes ahead. +- With `TimeMode` 0 (online time only), a gag, mute or silence given in game now ends when its + database row expires. Upstream matched the two by exact end time, which never matched for one + given in game (the database stores the time to the second), so it lasted until the player + reconnected. A penalty marked passed also stops applying at once, not on the next 61-second tick. Publish with `FORGEJO_TOKEN=... ./release.sh v` (ModuleVersion is `1.8.2b-zioN`). It rebuilds from the committed source and uploads `SimpleAdmin-.tar.gz` to git.zio.sh