From 042fde971e50f890c205f3502506ad5cf58387aa Mon Sep 17 00:00:00 2001 From: RaidMax Date: Thu, 26 Dec 2019 18:17:49 -0600 Subject: [PATCH] (potentially) fixed object disposed issue with semaphore fix random issue where we were trying to reset a session for a player that has not fully connected --- Application/IW4MServer.cs | 1 - Plugins/Stats/Helpers/StatManager.cs | 2 +- SharedLibraryCore/PartialEntities/EFClient.cs | 12 ++++++------ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index f46ea07f..edb1a358 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -57,7 +57,6 @@ namespace IW4MAdmin Logger.WriteInfo($"Client {client} connected..."); // Do the player specific stuff - client.ProcessingEvent = clientFromLog.ProcessingEvent; client.ClientNumber = clientFromLog.ClientNumber; client.Score = clientFromLog.Score; client.Ping = clientFromLog.Ping; diff --git a/Plugins/Stats/Helpers/StatManager.cs b/Plugins/Stats/Helpers/StatManager.cs index 695afc5e..b74fb464 100644 --- a/Plugins/Stats/Helpers/StatManager.cs +++ b/Plugins/Stats/Helpers/StatManager.cs @@ -1072,7 +1072,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers foreach (var stat in sv.GetClientsAsList() .Select(_client => _client.GetAdditionalProperty(CLIENT_STATS_KEY))) { - stat.StartNewSession(); + stat?.StartNewSession(); } } diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index 6fc04c6a..0e58cf13 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -82,12 +82,12 @@ namespace SharedLibraryCore.Database.Models { "_reportCount", 0 } }; ReceivedPenalties = new List(); - ProcessingEvent = new SemaphoreSlim(1, 1); + _processingEvent = new SemaphoreSlim(1, 1); } ~EFClient() { - ProcessingEvent.Dispose(); + _processingEvent.Dispose(); } public override string ToString() @@ -674,11 +674,11 @@ namespace SharedLibraryCore.Database.Models }; [NotMapped] - public SemaphoreSlim ProcessingEvent; + private readonly SemaphoreSlim _processingEvent; public async Task Lock() { - bool result = await ProcessingEvent.WaitAsync(Utilities.DefaultCommandTimeout); + bool result = await _processingEvent.WaitAsync(Utilities.DefaultCommandTimeout); #if DEBUG if (!result) @@ -690,9 +690,9 @@ namespace SharedLibraryCore.Database.Models public void Unlock() { - if (ProcessingEvent.CurrentCount == 0) + if (_processingEvent.CurrentCount == 0) { - ProcessingEvent.Release(1); + _processingEvent.Release(1); } }