From a01543c89b8671296f61a1ceaff03c5c7c2aadf8 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Thu, 30 Sep 2021 10:28:04 -0500 Subject: [PATCH] deactivate penalties while unlinking an account if implicit account linking is disabled --- SharedLibraryCore/Services/ClientService.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index 5bdfaf14e..e74857130 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -842,6 +842,24 @@ namespace SharedLibraryCore.Services await ctx.Aliases.Where(_alias => _alias.IPAddress == client.CurrentAlias.IPAddress && _alias.IPAddress != null) .ForEachAsync(_alias => _alias.LinkId = newLink.AliasLinkId); + if (!_appConfig.EnableImplicitAccountLinking) + { + var clientIdsByIp = await ctx.Clients.Where(c => + client.CurrentAlias.IPAddress != null && + c.CurrentAlias.IPAddress == client.CurrentAlias.IPAddress) + .Select(c => c.ClientId) + .ToListAsync(); + + await ctx.Penalties.Where(penalty => + clientIdsByIp.Contains(penalty.OffenderId) + && new[] + { + EFPenalty.PenaltyType.Ban, EFPenalty.PenaltyType.TempBan, EFPenalty.PenaltyType.Flag + }.Contains(penalty.Type) + && penalty.Expires == null) + .ForEachAsync(penalty => penalty.Expires = DateTime.UtcNow); + } + await ctx.SaveChangesAsync(); }