From 16d2ec82b8004b301efe9895c7a4118c03566cb3 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 25 Jun 2019 18:01:47 -0500 Subject: [PATCH] make sure flags are excluded from active penalties on player profile modify how flags "expire" --- Application/IW4MServer.cs | 9 ++++++++- Plugins/Stats/Cheat/Detection.cs | 2 +- Plugins/Stats/Helpers/StatManager.cs | 2 +- SharedLibraryCore/PartialEntities/EFClient.cs | 13 ++++--------- SharedLibraryCore/Services/PenaltyService.cs | 6 +++--- WebfrontCore/Controllers/ClientController.cs | 7 ++++--- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index ef43d3ccd..ec85145fc 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -266,11 +266,18 @@ namespace IW4MAdmin else if (E.Type == GameEvent.EventType.Flag) { + DateTime? expires = null; + + if (E.Extra is TimeSpan ts) + { + expires = DateTime.UtcNow + ts; + } + // todo: maybe move this to a seperate function var newPenalty = new EFPenalty() { Type = EFPenalty.PenaltyType.Flag, - Expires = DateTime.UtcNow, + Expires = expires, Offender = E.Target, Offense = E.Data, Punisher = E.Origin, diff --git a/Plugins/Stats/Cheat/Detection.cs b/Plugins/Stats/Cheat/Detection.cs index 275b8a1aa..b4691eb69 100644 --- a/Plugins/Stats/Cheat/Detection.cs +++ b/Plugins/Stats/Cheat/Detection.cs @@ -205,7 +205,7 @@ namespace IW4MAdmin.Plugins.Stats.Cheat var lifeTimeHits = ClientStats.HitLocations.Sum(_loc => _loc.HitCount); ClientStats.AverageRecoilOffset = (ClientStats.AverageRecoilOffset * (lifeTimeHits - 1) + hitRecoilAverage) / lifeTimeHits; - if (sessionAverageRecoilAmount == 0 && HitCount > Thresholds.LowSampleMinKills) + if (sessionAverageRecoilAmount == 0 && HitCount >= Thresholds.LowSampleMinKills) { results.Add(new DetectionPenaltyResult() { diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 9f6854cf2..1734e51c5 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -650,7 +650,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers $"{penalty.Type}-{(int)penalty.Location}-{Math.Round(penalty.Value, 2)}@{penalty.HitCount}" : $"{penalty.Type}-{Math.Round(penalty.Value, 2)}@{penalty.HitCount}"; - await attacker.Flag(flagReason, penaltyClient).WaitAsync(Utilities.DefaultCommandTimeout, attacker.CurrentServer.Manager.CancellationToken); + await attacker.Flag(flagReason, penaltyClient, new TimeSpan(168, 0, 0)).WaitAsync(Utilities.DefaultCommandTimeout, attacker.CurrentServer.Manager.CancellationToken); break; } } diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 8ea67af22..8f539d846 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -232,7 +232,7 @@ namespace SharedLibraryCore.Database.Models /// reason for flagging /// client performing the flag /// game event for the flag - public GameEvent Flag(string flagReason, EFClient sender) + public GameEvent Flag(string flagReason, EFClient sender, TimeSpan? flagLength = null) { var e = new GameEvent() { @@ -240,6 +240,7 @@ namespace SharedLibraryCore.Database.Models Origin = sender, Data = flagReason, Message = flagReason, + Extra = flagLength, Target = this, Owner = sender.CurrentServer }; @@ -667,21 +668,15 @@ namespace SharedLibraryCore.Database.Models if (currentFlag != null) { CurrentServer.Logger.WriteDebug($"Flagging {this} because their AliasLink is flagged, but they are not"); - Flag(currentFlag.Offense, autoKickClient); + Flag(currentFlag.Offense, autoKickClient, currentFlag.Expires - DateTime.UtcNow); } } #endregion if (Level == Permission.Flagged) { - var currentAutoFlag = activePenalties - .Where(p => p.Type == EFPenalty.PenaltyType.Flag && p.PunisherId == 1) - .OrderByDescending(p => p.When) - .FirstOrDefault(); - // remove their auto flag status after a week - if (currentAutoFlag != null && - (DateTime.UtcNow - currentAutoFlag.When).TotalDays > 7) + if (!activePenalties.Any(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag)) { CurrentServer.Logger.WriteInfo($"Unflagging {this} because the auto flag time has expired"); Unflag(Utilities.CurrentLocalization.LocalizationIndex["SERVER_AUTOFLAG_UNFLAG"], autoKickClient); diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index 0e57cded5..671267337 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -175,11 +175,11 @@ namespace SharedLibraryCore.Services Expression> filter = (p) => (new EFPenalty.PenaltyType[] { EFPenalty.PenaltyType.TempBan, - EFPenalty.PenaltyType.Ban + EFPenalty.PenaltyType.Ban, + EFPenalty.PenaltyType.Flag }.Contains(p.Type) && p.Active && - (p.Expires == null || p.Expires > now)) || - (p.Type ==EFPenalty.PenaltyType.Flag && p.Active); + (p.Expires == null || p.Expires > now)); using (var context = new DatabaseContext(true)) { diff --git a/WebfrontCore/Controllers/ClientController.cs b/WebfrontCore/Controllers/ClientController.cs index 7871bd502..63787ac75 100644 --- a/WebfrontCore/Controllers/ClientController.cs +++ b/WebfrontCore/Controllers/ClientController.cs @@ -22,7 +22,8 @@ namespace WebfrontCore.Controllers return NotFound(); } - var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress); + var activePenalties = (await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress)) + .Where(_penalty => _penalty.Type != PenaltyType.Flag); var clientDto = new PlayerInfo() { @@ -46,8 +47,8 @@ namespace WebfrontCore.Controllers .Distinct() .OrderBy(i => i) .ToList(), - HasActivePenalty = activePenalties.Count > 0, - ActivePenaltyType = activePenalties.Count > 0 ? activePenalties.First().Type.ToString() : null, + HasActivePenalty = activePenalties.Count() > 0, + ActivePenaltyType = activePenalties.Count() > 0 ? activePenalties.First().Type.ToString() : null, Online = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null, TimeOnline = (DateTime.UtcNow - client.LastConnection).TimeSpanText(), LinkedAccounts = client.LinkedAccounts