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

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

View File

@ -549,141 +549,54 @@ namespace SharedLibraryCore.Database.Models
var loc = Utilities.CurrentLocalization.LocalizationIndex; var loc = Utilities.CurrentLocalization.LocalizationIndex;
var autoKickClient = Utilities.IW4MAdminClient(CurrentServer); 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) // 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); var activePenalties = await CurrentServer.Manager.GetPenaltyService().GetActivePenaltiesAsync(AliasLinkId, ipAddress);
#region CLIENT_LINKED_BAN var banPenalty = ReceivedPenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban);
var currentBan = activePenalties.FirstOrDefault(p => p.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 // we want to kick them if any account is banned
if (currentBan != null) if (banPenalty != null)
{ {
CurrentServer.Logger.WriteInfo($"Banned client {this} trying to evade..."); if (Level == Permission.Banned)
// reban the "evading" guid
if (Level != Permission.Banned)
{ {
CurrentServer.Logger.WriteInfo($"Banned client {this} connected using a new GUID"); CurrentServer.Logger.WriteDebug($"Kicking {this} because they are banned");
Kick(loc["SERVER_BAN_PREV"].FormatExt(banPenalty?.Offense), autoKickClient);
// hack: re apply the automated offense to the reban return false;
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);
} }
else 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;
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)
{
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);
return false;
}
#endregion
#region CLIENT_LINKED_FLAG
if (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);
} }
} }
#endregion
if (Level == Permission.Flagged) // we want to kick them if any account is tempbanned
if (tempbanPenalty != null)
{
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;
}
// if we found a flag, we need to make sure all the accounts are flagged
if (flagPenalty != null && Level != Permission.Flagged)
{
SetLevel(Permission.Flagged, autoKickClient);
}
// remove their auto flag
if (Level == Permission.Flagged && !activePenalties.Any(_penalty => _penalty.Type == EFPenalty.PenaltyType.Flag))
{ {
// remove their auto flag status after a week // 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);
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] [NotMapped]

View File

@ -32,37 +32,6 @@ namespace SharedLibraryCore.Services
context.Penalties.Add(penalty); context.Penalties.Add(penalty);
await context.SaveChangesAsync(); 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; return newEntity;
@ -137,10 +106,14 @@ namespace SharedLibraryCore.Services
{ {
using (var ctx = new DatabaseContext(true)) 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() var iqPenalties = ctx.Penalties.AsNoTracking()
//.Where(_penalty => _penalty.Active) .Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId || _penalty.LinkId == linkId)
.Where(_penalty => _penalty.OffenderId == clientId || _penalty.PunisherId == clientId) .Where(_penalty => _penalty.When <= startAt)
.Where(_penalty => _penalty.When < startAt)
.OrderByDescending(_penalty => _penalty.When) .OrderByDescending(_penalty => _penalty.When)
.Skip(offset) .Skip(offset)
.Take(count) .Take(count)
@ -188,7 +161,7 @@ namespace SharedLibraryCore.Services
.Where(filter); .Where(filter);
var iqIPPenalties = context.Aliases 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) .SelectMany(a => a.Link.ReceivedPenalties)
.Where(filter); .Where(filter);
@ -206,21 +179,19 @@ namespace SharedLibraryCore.Services
} }
} }
public async Task RemoveActivePenalties(int aliasLinkId, EFClient origin) public async Task RemoveActivePenalties(int aliasLinkId)
{ {
using (var context = new DatabaseContext()) using (var context = new DatabaseContext())
{ {
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var penalties = context.Penalties await context.Penalties
.Include(p => p.Link.Children)
.Where(p => p.LinkId == aliasLinkId) .Where(p => p.LinkId == aliasLinkId)
.Where(p => p.Expires > now || p.Expires == null); .Where(p => p.Expires > now || p.Expires == null)
.ForEachAsync(p =>
await penalties.ForEachAsync(p => {
{ p.Active = false;
p.Active = false; p.Expires = now;
});
});
await context.SaveChangesAsync(); 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 * load context of chat
*/ */