From e2ed57f67454f1cd0c2ac872ed3ceb24803c72c2 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 23 Mar 2021 10:34:44 -0500 Subject: [PATCH] prevent autoflag from running player has been manually unflagged --- Application/IW4MServer.cs | 6 +++--- SharedLibraryCore/Services/ClientService.cs | 14 +++++++++++--- .../Views/Client/Statistics/Advanced.cshtml | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index c3d103be8..deee085d0 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -481,10 +481,10 @@ namespace IW4MAdmin await Manager.GetPenaltyService().Create(newReport); - int reportNum = await Manager.GetClientService().GetClientReportCount(E.Target.ClientId); - bool isAutoFlagged = await Manager.GetClientService().IsAutoFlagged(E.Target.ClientId); + var reportNum = await Manager.GetClientService().GetClientReportCount(E.Target.ClientId); + var canBeAutoFlagged = await Manager.GetClientService().CanBeAutoFlagged(E.Target.ClientId); - if (!E.Target.IsPrivileged() && reportNum >= REPORT_FLAG_COUNT && !isAutoFlagged) + if (!E.Target.IsPrivileged() && reportNum >= REPORT_FLAG_COUNT && canBeAutoFlagged) { E.Target.Flag( Utilities.CurrentLocalization.LocalizationIndex["SERVER_AUTO_FLAG_REPORT"] diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 9de5bc087..8180f61af 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -669,22 +669,30 @@ namespace SharedLibraryCore.Services } /// - /// indicates if the given clientid has been autoflagged + /// indicates if the given clientid can be autoflagged /// /// /// - public async Task IsAutoFlagged(int clientId) + public async Task CanBeAutoFlagged(int clientId) { await using var context = _contextFactory.CreateContext(false); var now = DateTime.UtcNow; - return await context.Penalties + var hasExistingAutoFlag = await context.Penalties .Where(_penalty => _penalty.Active) .Where(_penalty => _penalty.OffenderId == clientId) .Where(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag) .Where(_penalty => _penalty.PunisherId == 1) .Where(_penalty => _penalty.Expires == null || _penalty.Expires > now) .AnyAsync(); + + var hasUnflag = await context.Penalties + .Where(_penalty => _penalty.Active) + .Where(_penalty => _penalty.OffenderId == clientId) + .Where(_penalty => _penalty.Type == EFPenalty.PenaltyType.Unflag) + .AnyAsync(); + + return !hasExistingAutoFlag && !hasUnflag; } /// diff --git a/WebfrontCore/Views/Client/Statistics/Advanced.cshtml b/WebfrontCore/Views/Client/Statistics/Advanced.cshtml index 9501a2bbb..86d85966a 100644 --- a/WebfrontCore/Views/Client/Statistics/Advanced.cshtml +++ b/WebfrontCore/Views/Client/Statistics/Advanced.cshtml @@ -9,7 +9,7 @@ @model Stats.Dtos.AdvancedStatsInfo @{ ViewBag.Title = "Advanced Client Statistics"; - ViewBag.Description = Model.ClientName; + ViewBag.Description = Model.ClientName.StripColors(); const int maxItems = 5; const string headshotKey = "MOD_HEAD_SHOT";