make sure flags are excluded from active penalties on player profile

modify how flags "expire"
This commit is contained in:
RaidMax 2019-06-25 18:01:47 -05:00
parent 421e90cf70
commit 16d2ec82b8
6 changed files with 21 additions and 18 deletions

View File

@ -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,

View File

@ -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()
{

View File

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

View File

@ -232,7 +232,7 @@ namespace SharedLibraryCore.Database.Models
/// <param name="flagReason">reason for flagging</param>
/// <param name="sender">client performing the flag</param>
/// <returns>game event for the flag</returns>
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);

View File

@ -175,11 +175,11 @@ namespace SharedLibraryCore.Services
Expression<Func<EFPenalty, bool>> 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))
{

View File

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