diff --git a/Application/GameEventHandler.cs b/Application/GameEventHandler.cs index a082e5881..1023a94c0 100644 --- a/Application/GameEventHandler.cs +++ b/Application/GameEventHandler.cs @@ -1,8 +1,6 @@ using SharedLibraryCore; using SharedLibraryCore.Events; using SharedLibraryCore.Interfaces; -using System.Collections.Generic; -using System.Linq; using System.Threading; namespace IW4MAdmin.Application @@ -17,6 +15,11 @@ namespace IW4MAdmin.Application public void AddEvent(GameEvent gameEvent) { +#if DEBUG + ThreadPool.GetMaxThreads(out int workerThreads, out int n); + ThreadPool.GetAvailableThreads(out int availableThreads, out int m); + gameEvent.Owner.Logger.WriteDebug($"There are {workerThreads - availableThreads} active threading tasks"); +#endif Manager.OnServerEvent?.Invoke(gameEvent.Owner, new GameEventArgs(null, false, gameEvent)); } } diff --git a/Application/IO/GameLogEventDetection.cs b/Application/IO/GameLogEventDetection.cs index 18a351d16..3b89ccfb6 100644 --- a/Application/IO/GameLogEventDetection.cs +++ b/Application/IO/GameLogEventDetection.cs @@ -72,7 +72,6 @@ namespace IW4MAdmin.Application.IO foreach (var ev in events) { _server.Manager.GetEventHandler().AddEvent(ev); - await ev.WaitAsync(Utilities.DefaultCommandTimeout, ev.Owner.Manager.CancellationToken); } previousFileSize = fileSize; diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 2d5389525..98e635e0b 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -641,8 +641,12 @@ namespace IW4MAdmin // because we don't want to try to fill up a slot that's not empty yet waiterList.Add(e); } + // wait for all the disconnect tasks to finish - await Task.WhenAll(waiterList.Select(e => e.WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken))); + foreach (var waiter in waiterList) + { + waiter.Wait(); + } waiterList.Clear(); // this are our new connecting clients @@ -666,7 +670,10 @@ namespace IW4MAdmin } // wait for all the connect tasks to finish - await Task.WhenAll(waiterList.Select(e => e.WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken))); + foreach (var waiter in waiterList) + { + waiter.Wait(); + } waiterList.Clear(); // these are the clients that have updated @@ -683,7 +690,10 @@ namespace IW4MAdmin waiterList.Add(e); } - await Task.WhenAll(waiterList.Select(e => e.WaitAsync(Utilities.DefaultCommandTimeout, Manager.CancellationToken))); + foreach (var waiter in waiterList) + { + waiter.Wait(); + } if (ConnectionErrors > 0) { diff --git a/Application/Misc/Logger.cs b/Application/Misc/Logger.cs index d19b1f0ec..d08349a4e 100644 --- a/Application/Misc/Logger.cs +++ b/Application/Misc/Logger.cs @@ -54,9 +54,9 @@ namespace IW4MAdmin.Application } } - async Task Write(string msg, LogType type) + void Write(string msg, LogType type) { - await OnLogWriting.WaitAsync(); + OnLogWriting.Wait(); string stringType = type.ToString(); @@ -73,7 +73,7 @@ namespace IW4MAdmin.Application #if DEBUG // lets keep it simple and dispose of everything quickly as logging wont be that much (relatively) Console.WriteLine(LogLine); - await File.AppendAllTextAsync(FileName, $"{LogLine}{Environment.NewLine}"); + File.AppendAllText(FileName, $"{LogLine}{Environment.NewLine}"); //Debug.WriteLine(msg); #else if (type == LogType.Error || type == LogType.Verbose) diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs index bd25d0d4d..4dac83b9a 100644 --- a/SharedLibraryCore/Events/GameEvent.cs +++ b/SharedLibraryCore/Events/GameEvent.cs @@ -229,5 +229,11 @@ namespace SharedLibraryCore return this; }); } + + public GameEvent Wait() + { + OnProcessed.Wait(); + return this; + } } } diff --git a/SharedLibraryCore/Services/ClientService.cs b/SharedLibraryCore/Services/ClientService.cs index a238f3f8b..afbadc1a2 100644 --- a/SharedLibraryCore/Services/ClientService.cs +++ b/SharedLibraryCore/Services/ClientService.cs @@ -144,6 +144,19 @@ namespace SharedLibraryCore.Services .Where(_client => _client.AliasLinkId == oldAliasLink.AliasLinkId) .ForEachAsync(_client => _client.AliasLinkId = newAliasLink.AliasLinkId); + // we also need to update all the penalties or they get deleted + // scenario + // link1 joins with ip1 + // link2 joins with ip2, + // link2 receives penalty + // link2 joins with ip1 + // pre existing link for link2 detected + // link2 is deleted + // link2 penalties are orphaned + await context.Penalties + .Where(_penalty => _penalty.LinkId == oldAliasLink.AliasLinkId) + .ForEachAsync(_penalty => _penalty.LinkId = newAliasLink.AliasLinkId); + entity.AliasLink = newAliasLink; entity.AliasLinkId = newAliasLink.AliasLinkId;