From e8af8914d25674296a8ab0559dc9d346a0262afa Mon Sep 17 00:00:00 2001 From: RaidMax Date: Tue, 11 Jun 2019 08:00:14 -0500 Subject: [PATCH] add a check to make sure we're not breaking EFClient entries when updating make sure the alias is updated before banning the player as we want to link them together update CoD4x parser to fix their breaking change --- Application/Application.csproj | 6 +- Application/IW4MServer.cs | 60 +++++++++----------- Plugins/ScriptPlugins/ParserCoD4x.js | 4 +- Plugins/Stats/Commands/MostPlayed.cs | 2 +- Plugins/Tests/ClientTests.cs | 2 +- SharedLibraryCore/Commands/NativeCommands.cs | 2 +- SharedLibraryCore/Services/ClientService.cs | 26 ++++----- 7 files changed, 46 insertions(+), 56 deletions(-) diff --git a/Application/Application.csproj b/Application/Application.csproj index 55733d0c..6c97a4e4 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -6,7 +6,7 @@ 2.2.2 false RaidMax.IW4MAdmin.Application - 2.2.7.5 + 2.2.7.6 RaidMax Forever None IW4MAdmin @@ -32,8 +32,8 @@ true true - 2.2.7.5 - 2.2.7.5 + 2.2.7.6 + 2.2.7.6 7.1 diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index d3ed9406..93ddc1f6 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -84,18 +84,18 @@ namespace IW4MAdmin if (client.ClientNumber >= 0) { #endif - Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting..."); - Clients[client.ClientNumber] = null; - await client.OnDisconnect(); + Logger.WriteInfo($"Client {client} [{client.State.ToString().ToLower()}] disconnecting..."); + Clients[client.ClientNumber] = null; + await client.OnDisconnect(); - var e = new GameEvent() - { - Origin = client, - Owner = this, - Type = GameEvent.EventType.Disconnect - }; + var e = new GameEvent() + { + Origin = client, + Owner = this, + Type = GameEvent.EventType.Disconnect + }; - Manager.GetEventHandler().AddEvent(e); + Manager.GetEventHandler().AddEvent(e); #if DEBUG == true } #endif @@ -571,22 +571,9 @@ namespace IW4MAdmin { try { -#region SHUTDOWN + #region SHUTDOWN if (Manager.CancellationToken.IsCancellationRequested) { - foreach (var client in GetClientsAsList()) - { - var e = new GameEvent() - { - Type = GameEvent.EventType.PreDisconnect, - Origin = client, - Owner = this, - }; - - Manager.GetEventHandler().AddEvent(e); - await e.WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken); - } - foreach (var plugin in SharedLibraryCore.Plugins.PluginImporter.ActivePlugins) { await plugin.OnUnloadAsync(); @@ -594,7 +581,7 @@ namespace IW4MAdmin return true; } -#endregion + #endregion try { @@ -705,14 +692,14 @@ namespace IW4MAdmin lastCount = DateTime.Now; // update the player history - if ((lastCount - playerCountStart).TotalMinutes >= SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) + if ((lastCount - playerCountStart).TotalMinutes >= PlayerHistory.UpdateInterval) { - while (ClientHistory.Count > ((60 / SharedLibraryCore.Helpers.PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours + while (ClientHistory.Count > ((60 / PlayerHistory.UpdateInterval) * 12)) // 12 times a hour for 12 hours { ClientHistory.Dequeue(); } - ClientHistory.Enqueue(new SharedLibraryCore.Helpers.PlayerHistory(ClientNum)); + ClientHistory.Enqueue(new PlayerHistory(ClientNum)); playerCountStart = DateTime.Now; } @@ -1017,13 +1004,20 @@ namespace IW4MAdmin else { #if !DEBUG - string formattedString = String.Format(RconParser.Configuration.CommandPrefixes.Kick, targetClient.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{reason} ^7{loc["SERVER_BAN_APPEAL"].FormatExt(Website)}^7"); + string formattedString = string.Format(RconParser.Configuration.CommandPrefixes.Kick, targetClient.ClientNumber, $"{loc["SERVER_BAN_TEXT"]} - ^5{reason} ^7{loc["SERVER_BAN_APPEAL"].FormatExt(Website)}^7"); await targetClient.CurrentServer.ExecuteCommandAsync(formattedString); #else await targetClient.CurrentServer.OnClientDisconnected(targetClient); #endif } + // this should link evading clients + if (isEvade) + { + Logger.WriteInfo($"updating alias for banned client {targetClient}"); + await Manager.GetClientService().UpdateAlias(targetClient); + } + EFPenalty newPenalty = new EFPenalty() { Type = EFPenalty.PenaltyType.Ban, @@ -1061,10 +1055,10 @@ namespace IW4MAdmin override public void InitializeTokens() { - Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("TOTALPLAYERS", (Server s) => Task.Run(async () => (await Manager.GetClientService().GetTotalClientsAsync()).ToString()))); - Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("VERSION", (Server s) => Task.FromResult(Application.Program.Version.ToString()))); - Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s))); - Manager.GetMessageTokens().Add(new SharedLibraryCore.Helpers.MessageToken("ADMINS", (Server s) => Task.FromResult(SharedLibraryCore.Commands.CListAdmins.OnlineAdmins(s)))); + Manager.GetMessageTokens().Add(new MessageToken("TOTALPLAYERS", (Server s) => Task.Run(async () => (await Manager.GetClientService().GetTotalClientsAsync()).ToString()))); + Manager.GetMessageTokens().Add(new MessageToken("VERSION", (Server s) => Task.FromResult(Application.Program.Version.ToString()))); + Manager.GetMessageTokens().Add(new MessageToken("NEXTMAP", (Server s) => SharedLibraryCore.Commands.CNextMap.GetNextMap(s))); + Manager.GetMessageTokens().Add(new MessageToken("ADMINS", (Server s) => Task.FromResult(SharedLibraryCore.Commands.CListAdmins.OnlineAdmins(s)))); } } } diff --git a/Plugins/ScriptPlugins/ParserCoD4x.js b/Plugins/ScriptPlugins/ParserCoD4x.js index ff6c5caa..4e81fd90 100644 --- a/Plugins/ScriptPlugins/ParserCoD4x.js +++ b/Plugins/ScriptPlugins/ParserCoD4x.js @@ -3,7 +3,7 @@ var eventParser; var plugin = { author: 'FrenchFry, RaidMax', - version: 0.3, + version: 0.4, name: 'CoD4x Parser', isParser: true, @@ -14,7 +14,7 @@ var plugin = { rconParser = manager.GenerateDynamicRConParser(); eventParser = manager.GenerateDynamicEventParser(); - rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16}|(?:[a-z]|[0-9]){32}|bot[0-9]+|(?:[0-9]+)) *(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$' + rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +-?([0-9]+) +((?:[A-Z]+|[0-9]+)) +((?:[a-z]|[0-9]){16,32}|(?:[a-z]|[0-9]){32}|bot[0-9]+) ([0-9+]) *(.{0,32}) +([0-9]+) +(\\d+\\.\\d+\\.\\d+.\\d+\\:-*\\d{1,5}|0+.0+:-*\\d{1,5}|loopback) +(-*[0-9]+) +([0-9]+) *$' rconParser.Configuration.Status.AddMapping(104, 6); // RConName rconParser.Configuration.Status.AddMapping(105, 8); // RConIPAddress diff --git a/Plugins/Stats/Commands/MostPlayed.cs b/Plugins/Stats/Commands/MostPlayed.cs index 98776da2..ccb8872c 100644 --- a/Plugins/Stats/Commands/MostPlayed.cs +++ b/Plugins/Stats/Commands/MostPlayed.cs @@ -23,7 +23,7 @@ namespace IW4MAdmin.Plugins.Stats.Commands $"^5--{Utilities.CurrentLocalization.LocalizationIndex["PLUGINS_STATS_COMMANDS_MOSTPLAYED_TEXT"]}--" }; - using (var db = new DatabaseContext()) + using (var db = new DatabaseContext(true)) { db.ChangeTracker.AutoDetectChangesEnabled = false; db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; diff --git a/Plugins/Tests/ClientTests.cs b/Plugins/Tests/ClientTests.cs index f1935c8d..efcea2b0 100644 --- a/Plugins/Tests/ClientTests.cs +++ b/Plugins/Tests/ClientTests.cs @@ -249,7 +249,7 @@ namespace Tests unbanCommand.ExecuteAsync(new GameEvent() { Origin = new EFClient() { ClientId = 1, Level = EFClient.Permission.Console, CurrentServer = client.CurrentServer }, - Target = Manager.GetClientService().Find(c => c.NetworkId == client.NetworkId).Result.First(), + //Target = Manager.GetClientService().Find(c => c.NetworkId == client.NetworkId).Result.First(), Data = "test unban", Type = GameEvent.EventType.Command, Owner = client.CurrentServer diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index bb712d1a..98f205dc 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -1115,7 +1115,7 @@ namespace SharedLibraryCore.Commands .Where(c => c.Level > EFClient.Permission.Flagged && c.Level <= EFClient.Permission.Moderator) .Where(c => c.LastConnection < lastActive) .ToListAsync(); - inactiveUsers.ForEach(c => c.SetLevel(EFClient.Permission.User, E.Origin)); + inactiveUsers.ForEach(c => c.SetLevel(Permission.User, E.Origin)); await context.SaveChangesAsync(); } E.Origin.Tell(Utilities.CurrentLocalization.LocalizationIndex["COMMANDS_PRUNE_SUCCESS"].FormatExt(inactiveUsers.Count)); diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index da224181..9e319b72 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -48,7 +48,7 @@ namespace SharedLibraryCore.Services }; context.Clients.Add(client); - + // they're just using a new GUID if (aliasId.HasValue) { @@ -272,18 +272,9 @@ namespace SharedLibraryCore.Services } } - public async Task> Find(Func e) + public Task> Find(Func e) { - return await Task.Run(() => - { - using (var context = new DatabaseContext(true)) - { - return context.Clients - .Include(c => c.CurrentAlias) - .Include(c => c.AliasLink.Children) - .Where(e).ToList(); - } - }); + throw new NotImplementedException(); } public async Task Get(int entityID) @@ -369,6 +360,11 @@ namespace SharedLibraryCore.Services { using (var context = new DatabaseContext()) { + if (temporalClient.LastConnection == DateTime.MinValue || temporalClient.Connections == 0 || temporalClient.TotalConnectionTime == 0) + { + throw new InvalidOperationException($"client {temporalClient} trying to update but parameters are invalid"); + } + // grab the context version of the entity var entity = context.Clients .First(client => client.ClientId == temporalClient.ClientId); @@ -407,7 +403,7 @@ namespace SharedLibraryCore.Services { using (var ctx = new DatabaseContext(true)) { - return await ctx.Clients.AsNoTracking() + return await ctx.Clients .CountAsync(_client => _client.Level == Permission.Owner); } } @@ -489,7 +485,7 @@ namespace SharedLibraryCore.Services { iqClients = iqClients.Where(_client => linkIds.Contains(_client.AliasLinkId)); } - + // we want to project our results var iqClientProjection = iqClients.OrderByDescending(_client => _client.LastConnection) .Select(_client => new PlayerInfo() @@ -503,7 +499,7 @@ namespace SharedLibraryCore.Services var iqClientsSql = iqClients.ToSql(); #endif var clients = await iqClientProjection.ToListAsync(); - + // this is so we don't try to evaluate this in the linq to entities query foreach (var client in clients) {