From 8730a3fab80f9d1fedf032635cb2c00c507b96be Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 28 Jan 2022 15:33:21 -0600 Subject: [PATCH] fix issue with certain penalties not linking --- Application/Misc/ScriptPlugin.cs | 5 +++-- SharedLibraryCore/Commands/NativeCommands.cs | 11 ++++++----- SharedLibraryCore/PartialEntities/EFClient.cs | 4 ++-- SharedLibraryCore/Services/PenaltyService.cs | 18 +++++++++++++++--- .../Controllers/Client/ClientController.cs | 2 +- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Application/Misc/ScriptPlugin.cs b/Application/Misc/ScriptPlugin.cs index dfbf91f83..fc6943749 100644 --- a/Application/Misc/ScriptPlugin.cs +++ b/Application/Misc/ScriptPlugin.cs @@ -172,9 +172,10 @@ namespace IW4MAdmin.Application.Misc { if (pluginObject.isParser) { + await OnLoadAsync(manager); IsParser = true; - IEventParser eventParser = (IEventParser)_scriptEngine.GetValue("eventParser").ToObject(); - IRConParser rconParser = (IRConParser)_scriptEngine.GetValue("rconParser").ToObject(); + var eventParser = (IEventParser)_scriptEngine.GetValue("eventParser").ToObject(); + var rconParser = (IRConParser)_scriptEngine.GetValue("rconParser").ToObject(); manager.AdditionalEventParsers.Add(eventParser); manager.AdditionalRConParsers.Add(rconParser); } diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index dce657858..9dadbea7a 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -381,9 +381,10 @@ namespace SharedLibraryCore.Commands public override async Task ExecuteAsync(GameEvent E) { // todo: don't do the lookup here - var penalties = await E.Owner.Manager.GetPenaltyService().GetActivePenaltiesAsync(E.Target.AliasLinkId); - if (penalties.Where(p => p.Type == EFPenalty.PenaltyType.Ban || p.Type == EFPenalty.PenaltyType.TempBan) - .FirstOrDefault() != null) + var penalties = await E.Owner.Manager.GetPenaltyService().GetActivePenaltiesAsync(E.Target.AliasLinkId, E.Target.CurrentAliasId); + if (penalties + .FirstOrDefault(p => + p.Type == EFPenalty.PenaltyType.Ban || p.Type == EFPenalty.PenaltyType.TempBan) != null) { switch ((await E.Target.Unban(E.Data, E.Origin) .WaitAsync(Utilities.DefaultCommandTimeout, E.Owner.Manager.CancellationToken)).FailReason) @@ -897,7 +898,7 @@ namespace SharedLibraryCore.Commands public override async Task ExecuteAsync(GameEvent E) { var existingPenalties = await E.Owner.Manager.GetPenaltyService() - .GetActivePenaltiesAsync(E.Target.AliasLinkId, E.Target.IPAddress); + .GetActivePenaltiesAsync(E.Target.AliasLinkId, E.Target.CurrentAliasId, E.Target.IPAddress); var penalty = existingPenalties.FirstOrDefault(b => b.Type > EFPenalty.PenaltyType.Kick); if (penalty == null) @@ -1247,4 +1248,4 @@ namespace SharedLibraryCore.Commands E.Origin.Tell(await GetNextMap(E.Owner, _translationLookup)); } } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 798ae3476..e03dd15c2 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -653,7 +653,7 @@ namespace SharedLibraryCore.Database.Models // 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); + .GetActivePenaltiesAsync(AliasLinkId, CurrentAliasId, ipAddress); var banPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.Ban); var tempbanPenalty = activePenalties.FirstOrDefault(_penalty => _penalty.Type == EFPenalty.PenaltyType.TempBan); @@ -740,4 +740,4 @@ namespace SharedLibraryCore.Database.Models return IsBot ? ClientNumber : (int)NetworkId; } } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/Services/PenaltyService.cs b/SharedLibraryCore/Services/PenaltyService.cs index e8dfd2826..5fed597a1 100644 --- a/SharedLibraryCore/Services/PenaltyService.cs +++ b/SharedLibraryCore/Services/PenaltyService.cs @@ -148,7 +148,7 @@ namespace SharedLibraryCore.Services return await iqPenalties.Distinct().ToListAsync(); } - public async Task> GetActivePenaltiesAsync(int linkId, int? ip = null, + public async Task> GetActivePenaltiesAsync(int linkId, int currentAliasId, int? ip = null, bool includePunisherName = false) { var now = DateTime.UtcNow; @@ -178,7 +178,7 @@ namespace SharedLibraryCore.Services } else { - var aliasIps = await context.Aliases.Where(alias => alias.LinkId == linkId && alias.IPAddress != null) + /* var aliasIps = await context.Aliases.Where(alias => (alias.LinkId == linkId || alias.AliasId == currentAliasId) && alias.IPAddress != null) .Select(alias => alias.IPAddress) .ToListAsync(); @@ -205,7 +205,19 @@ namespace SharedLibraryCore.Services else { iqIpPenalties = Enumerable.Empty().AsQueryable(); - } + }*/ + + var usedIps = await context.Aliases.AsNoTracking() + .Where(alias => (alias.LinkId == linkId || alias.AliasId == currentAliasId) && alias.IPAddress != null) + .Select(alias => alias.IPAddress).ToListAsync(); + + var aliasedIds = await context.Aliases.AsNoTracking().Where(alias => usedIps.Contains(alias.IPAddress)) + .Select(alias => alias.LinkId) + .ToListAsync(); + + iqIpPenalties = context.Penalties.AsNoTracking() + .Where(penalty => aliasedIds.Contains(penalty.LinkId)) + .Where(filter); } var activeLinkPenalties = await iqLinkPenalties.ToListAsync(); diff --git a/WebfrontCore/Controllers/Client/ClientController.cs b/WebfrontCore/Controllers/Client/ClientController.cs index ce9d63230..a78b29863 100644 --- a/WebfrontCore/Controllers/Client/ClientController.cs +++ b/WebfrontCore/Controllers/Client/ClientController.cs @@ -37,7 +37,7 @@ namespace WebfrontCore.Controllers return NotFound(); } - var activePenalties = (await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress)); + var activePenalties = await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.CurrentAliasId, client.IPAddress); var tag = await _metaService.GetPersistentMeta(EFMeta.ClientTag, client); if (tag?.LinkedMeta != null)