prevent autoflag from running player has been manually unflagged

This commit is contained in:
RaidMax 2021-03-23 10:34:44 -05:00
parent 824b1c0990
commit e2ed57f674
3 changed files with 15 additions and 7 deletions

View File

@ -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"]

View File

@ -669,22 +669,30 @@ namespace SharedLibraryCore.Services
}
/// <summary>
/// indicates if the given clientid has been autoflagged
/// indicates if the given clientid can be autoflagged
/// </summary>
/// <param name="clientId"></param>
/// <returns></returns>
public async Task<bool> IsAutoFlagged(int clientId)
public async Task<bool> 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;
}
/// <summary>

View File

@ -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";