clean up some penalty stuff

force log file to be written if none supplied
fix issue with not all meta loading
This commit is contained in:
RaidMax 2019-06-27 20:06:30 -05:00
parent 16d2ec82b8
commit 3d468e32b9
4 changed files with 89 additions and 189 deletions

View File

@ -302,8 +302,9 @@ namespace IW4MAdmin
Link = E.Target.AliasLink
};
await Manager.GetPenaltyService().Create(unflagPenalty);
E.Target.SetLevel(Permission.User, E.Origin);
await Manager.GetPenaltyService().RemoveActivePenalties(E.Target.AliasLinkId);
await Manager.GetPenaltyService().Create(unflagPenalty);
}
else if (E.Type == GameEvent.EventType.Report)
@ -541,6 +542,7 @@ namespace IW4MAdmin
/// lists the connecting and disconnecting clients via RCon response
/// array index 0 = connecting clients
/// array index 1 = disconnecting clients
/// array index 2 = updated clients
/// </summary>
/// <returns></returns>
async Task<IList<EFClient>[]> PollPlayersAsync()
@ -832,15 +834,31 @@ namespace IW4MAdmin
this.Gametype = gametype;
this.IP = ip.Value == "localhost" ? ServerConfig.IPAddress : ip.Value ?? ServerConfig.IPAddress;
if ((logsync.Value == 0 || logfile.Value == string.Empty) && RconParser.CanGenerateLogPath)
if (RconParser.CanGenerateLogPath)
{
bool needsRestart = false;
if (logsync.Value == 0)
{
// this DVAR isn't set until the a map is loaded
await this.SetDvarAsync("logfile", 2);
await this.SetDvarAsync("g_logsync", 2); // set to 2 for continous in other games, clamps to 1 for IW4
//await this.SetDvarAsync("g_log", "games_mp.log");
needsRestart = true;
}
if (string.IsNullOrWhiteSpace(logfile.Value))
{
logfile.Value = "games_mp.log";
await this.SetDvarAsync("g_log", logfile.Value);
needsRestart = true;
}
if (needsRestart)
{
Logger.WriteWarning("Game log file not properly initialized, restarting map...");
await this.ExecuteCommandAsync("map_restart");
logfile = await this.GetDvarAsync<string>("g_log");
}
// this DVAR isn't set until the a map is loaded
await this.SetDvarAsync("logfile", 2);
}
CustomCallback = await ScriptLoaded();
@ -1026,11 +1044,6 @@ namespace IW4MAdmin
#endif
}
if (isEvade)
{
Logger.WriteInfo($"updating alias for banned client {targetClient}");
}
EFPenalty newPenalty = new EFPenalty()
{
Type = EFPenalty.PenaltyType.Ban,
@ -1052,7 +1065,7 @@ namespace IW4MAdmin
var unbanPenalty = new EFPenalty()
{
Type = EFPenalty.PenaltyType.Unban,
Expires = null,
Expires = DateTime.Now,
Offender = Target,
Offense = reason,
Punisher = Origin,
@ -1061,9 +1074,9 @@ namespace IW4MAdmin
Link = Target.AliasLink
};
await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId, Origin);
await Manager.GetPenaltyService().Create(unbanPenalty);
Target.SetLevel(Permission.User, Origin);
await Manager.GetPenaltyService().RemoveActivePenalties(Target.AliasLink.AliasLinkId);
await Manager.GetPenaltyService().Create(unbanPenalty);
}
override public void InitializeTokens()

View File

@ -549,141 +549,54 @@ namespace SharedLibraryCore.Database.Models
var loc = Utilities.CurrentLocalization.LocalizationIndex;
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer);
#region CLIENT_GUID_BAN
// kick them as their level is banned
if (Level == Permission.Banned)
{
var profileBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Expires == null && _penalty.Active && _penalty.Type == EFPenalty.PenaltyType.Ban);
if (profileBan == null)
{
// this is from the old system before bans were applied to all accounts
profileBan = (await CurrentServer.Manager
.GetPenaltyService()
.GetActivePenaltiesAsync(AliasLinkId))
.OrderByDescending(_penalty => _penalty.When)
.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban);
CurrentServer.Logger.WriteWarning($"Client {this} is GUID banned, but no previous penalty exists for their ban");
if (profileBan == null)
{
profileBan = new EFPenalty() { Offense = loc["SERVER_BAN_UNKNOWN"] };
CurrentServer.Logger.WriteWarning($"Client {this} is GUID banned, but we could not find the penalty on any linked accounts");
}
// hack: re apply the automated offense to the reban
if (profileBan.AutomatedOffense != null)
{
autoKickClient.AdministeredPenalties?.Add(new EFPenalty()
{
AutomatedOffense = profileBan.AutomatedOffense
});
}
// this is a reban of the new GUID and IP
Ban($"{profileBan.Offense}", autoKickClient, false);
return false;
}
CurrentServer.Logger.WriteDebug($"Kicking {this} because they are banned");
Kick(loc["SERVER_BAN_PREV"].FormatExt(profileBan?.Offense), autoKickClient);
return false;
}
#endregion
#region CLIENT_GUID_TEMPBAN
else
{
var profileTempBan = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan &&
_penalty.Active &&
_penalty.Expires > DateTime.UtcNow);
// they have an active tempban tied to their GUID
if (profileTempBan != null)
{
CurrentServer.Logger.WriteDebug($"Kicking {this} because their GUID is temporarily banned");
Kick($"{loc["SERVER_TB_REMAIN"]} ({(profileTempBan.Expires.Value - DateTime.UtcNow).TimeSpanText()} {loc["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]})", autoKickClient);
return false;
}
}
#endregion
// we want to get any penalties that are tied to their IP or AliasLink (but not necessarily their GUID)
var activePenalties = await CurrentServer.Manager.GetPenaltyService().GetActivePenaltiesAsync(AliasLinkId, ipAddress);
#region CLIENT_LINKED_BAN
var currentBan = activePenalties.FirstOrDefault(p => p.Type == EFPenalty.PenaltyType.Ban);
var banPenalty = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban);
var tempbanPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan);
var flagPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag);
// they have a perm ban tied to their AliasLink/profile
if (currentBan != null)
// we want to kick them if any account is banned
if (banPenalty != null)
{
CurrentServer.Logger.WriteInfo($"Banned client {this} trying to evade...");
// reban the "evading" guid
if (Level != Permission.Banned)
if (Level == Permission.Banned)
{
CurrentServer.Logger.WriteInfo($"Banned client {this} connected using a new GUID");
// hack: re apply the automated offense to the reban
if (currentBan.AutomatedOffense != null)
{
autoKickClient.AdministeredPenalties?.Add(new EFPenalty()
{
AutomatedOffense = currentBan.AutomatedOffense
});
}
// this is a reban of the new GUID and IP
Ban($"{currentBan.Offense}", autoKickClient, true);
CurrentServer.Logger.WriteDebug($"Kicking {this} because they are banned");
Kick(loc["SERVER_BAN_PREV"].FormatExt(banPenalty?.Offense), autoKickClient);
return false;
}
else
{
CurrentServer.Logger.WriteError($"Banned client {this} is banned but, no ban penalty was found (2)");
}
CurrentServer.Logger.WriteWarning($"Client {this} is GUID banned, but no previous penalty exists for their ban");
Ban(loc["SERVER_BAN_UNKNOWN"], autoKickClient, false);
return false;
}
#endregion
}
#region CLIENT_LINKED_TEMPBAN
var tempBan = activePenalties
.OrderByDescending(_penalty => _penalty.When)
.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan);
// they have an active tempban tied to their AliasLink
if (tempBan != null)
// we want to kick them if any account is tempbanned
if (tempbanPenalty != null)
{
CurrentServer.Logger.WriteDebug($"Tempbanning {this} because their AliasLink is temporarily banned, but they are not");
TempBan(tempBan.Offense, DateTime.UtcNow - (tempBan.Expires ?? DateTime.UtcNow), autoKickClient);
CurrentServer.Logger.WriteDebug($"Kicking {this} because their GUID is temporarily banned");
Kick($"{loc["SERVER_TB_REMAIN"]} ({(tempbanPenalty.Expires.Value - DateTime.UtcNow).TimeSpanText()} {loc["WEBFRONT_PENALTY_TEMPLATE_REMAINING"]})", autoKickClient);
return false;
}
#endregion
#region CLIENT_LINKED_FLAG
if (Level != Permission.Flagged)
// if we found a flag, we need to make sure all the accounts are flagged
if (flagPenalty != null && Level != Permission.Flagged)
{
var currentFlag = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag);
if (currentFlag != null)
{
CurrentServer.Logger.WriteDebug($"Flagging {this} because their AliasLink is flagged, but they are not");
Flag(currentFlag.Offense, autoKickClient, currentFlag.Expires - DateTime.UtcNow);
SetLevel(Permission.Flagged, autoKickClient);
}
}
#endregion
if (Level == Permission.Flagged)
// remove their auto flag
if (Level == Permission.Flagged && !activePenalties.Any(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag))
{
// remove their auto flag status after a week
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);
}
}
return true && OnConnect();
return OnConnect();
}
[NotMapped]

View File

@ -32,37 +32,6 @@ namespace SharedLibraryCore.Services
context.Penalties.Add(penalty);
await context.SaveChangesAsync();
// certain penalties we want to save across all profiles
if (penalty.Type.ShouldPenaltyApplyToAllProfiles())
{
var iqLinkedProfiles = context.Clients
.Where(_client => _client.AliasLinkId == newEntity.Link.AliasLinkId)
.Where(_client => _client.Level != EFClient.Permission.Banned)
// prevent adding the penalty twice to the same profile
.Where(_client => _client.ClientId != penalty.OffenderId);
await iqLinkedProfiles.ForEachAsync(_client =>
{
newEntity.Punisher.CurrentServer?.Logger.WriteDebug($"Applying penalty to linked client {_client.ClientId}");
var linkedPenalty = new EFPenalty()
{
OffenderId = _client.ClientId,
PunisherId = newEntity.Punisher.ClientId,
LinkId = newEntity.Link.AliasLinkId,
Type = newEntity.Type,
Expires = newEntity.Expires,
Offense = newEntity.Offense,
When = DateTime.UtcNow,
AutomatedOffense = newEntity.AutomatedOffense,
IsEvadedOffense = newEntity.IsEvadedOffense
};
context.Penalties.Add(linkedPenalty);
});
await context.SaveChangesAsync();
}
}
return newEntity;
@ -137,10 +106,14 @@ namespace SharedLibraryCore.Services
{
using (var ctx = new DatabaseContext(true))
{
var linkId = await ctx.Clients.AsNoTracking()
.Where(_penalty => _penalty.ClientId == clientId)
.Select(_penalty => _penalty.AliasLinkId)
.FirstOrDefaultAsync();
var iqPenalties = ctx.Penalties.AsNoTracking()
//.Where(_penalty => _penalty.Active)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId)
.Where(_penalty => _penalty.When < startAt)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId || _penalty.LinkId == linkId)
.Where(_penalty => _penalty.When <= startAt)
.OrderByDescending(_penalty => _penalty.When)
.Skip(offset)
.Take(count)
@ -188,7 +161,7 @@ namespace SharedLibraryCore.Services
.Where(filter);
var iqIPPenalties = context.Aliases
.Where(a => a.IPAddress != null & a.IPAddress == ip)
.Where(a => a.IPAddress != null && a.IPAddress == ip)
.SelectMany(a => a.Link.ReceivedPenalties)
.Where(filter);
@ -206,20 +179,18 @@ namespace SharedLibraryCore.Services
}
}
public async Task RemoveActivePenalties(int aliasLinkId, EFClient origin)
public async Task RemoveActivePenalties(int aliasLinkId)
{
using (var context = new DatabaseContext())
{
var now = DateTime.UtcNow;
var penalties = context.Penalties
.Include(p => p.Link.Children)
await context.Penalties
.Where(p => p.LinkId == aliasLinkId)
.Where(p => p.Expires > now || p.Expires == null);
await penalties.ForEachAsync(p =>
.Where(p => p.Expires > now || p.Expires == null)
.ForEachAsync(p =>
{
p.Active = false;
p.Expires = now;
});
await context.SaveChangesAsync();

View File

@ -10,6 +10,9 @@
}
});
/* set the end time for initial event query */
startAt = $('#profile_events').children().last().data('time');
/*
* load context of chat
*/