From c3b36f4c7d072fc957bb7166501c124f2ce3fb3b Mon Sep 17 00:00:00 2001 From: Archangel Date: Tue, 5 Aug 2025 17:20:49 +0200 Subject: [PATCH] Handle invalid profiles on all IOnUpdate --- .../Callbacks/BtrDeliveryCallbacks.cs | 5 ++++ .../Controllers/DialogueController.cs | 5 ++++ .../Controllers/HideoutController.cs | 5 ++++ .../Controllers/InsuranceController.cs | 5 ++++ .../Servers/SaveServer.cs | 23 +++++++++++------ .../Services/ProfileValidatorService.cs | 25 +++++++++++++------ 6 files changed, 52 insertions(+), 16 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Callbacks/BtrDeliveryCallbacks.cs b/Libraries/SPTarkov.Server.Core/Callbacks/BtrDeliveryCallbacks.cs index 32e7e53f..d531d4e3 100644 --- a/Libraries/SPTarkov.Server.Core/Callbacks/BtrDeliveryCallbacks.cs +++ b/Libraries/SPTarkov.Server.Core/Callbacks/BtrDeliveryCallbacks.cs @@ -43,6 +43,11 @@ public class BtrDeliveryCallbacks( // Process each installed profile. foreach (var (sessionId, _) in saveServer.GetProfiles()) { + if (saveServer.IsProfileInvalidOrUnloadable(sessionId)) + { + continue; + } + ProcessDeliveryByProfile(sessionId); } } diff --git a/Libraries/SPTarkov.Server.Core/Controllers/DialogueController.cs b/Libraries/SPTarkov.Server.Core/Controllers/DialogueController.cs index 997b32d6..bd573baa 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/DialogueController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/DialogueController.cs @@ -52,6 +52,11 @@ public class DialogueController( var profiles = saveServer.GetProfiles(); foreach (var (sessionId, _) in profiles) { + if (saveServer.IsProfileInvalidOrUnloadable(sessionId)) + { + continue; + } + RemoveExpiredItemsFromMessages(sessionId); } } diff --git a/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs b/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs index 29fac533..d88e7abe 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs @@ -1514,6 +1514,11 @@ public class HideoutController( { foreach (var (sessionId, profile) in saveServer.GetProfiles()) { + if (saveServer.IsProfileInvalidOrUnloadable(sessionId)) + { + continue; + } + if ( profile.CharacterData?.PmcData?.Hideout is not null && profileActivityService.ActiveWithinLastMinutes(sessionId, _hideoutConfig.UpdateProfileHideoutWhenActiveWithinMinutes) diff --git a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs index 9c02bfce..621887ea 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs @@ -52,6 +52,11 @@ public class InsuranceController( // Process each installed profile. foreach (var (sessionId, _) in saveServer.GetProfiles()) { + if (saveServer.IsProfileInvalidOrUnloadable(sessionId)) + { + continue; + } + ProcessReturnByProfile(sessionId); } } diff --git a/Libraries/SPTarkov.Server.Core/Servers/SaveServer.cs b/Libraries/SPTarkov.Server.Core/Servers/SaveServer.cs index 6451e69f..ae116209 100644 --- a/Libraries/SPTarkov.Server.Core/Servers/SaveServer.cs +++ b/Libraries/SPTarkov.Server.Core/Servers/SaveServer.cs @@ -215,10 +215,7 @@ public class SaveServer( } // We don't proceed further here as only one object in the profile has data in it. - if ( - profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile is not null - && profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile!.Value - ) + if (IsProfileInvalidOrUnloadable(sessionID)) { return; } @@ -239,10 +236,7 @@ public class SaveServer( public async Task SaveProfileAsync(MongoId sessionID) { // No need to save profiles that have been marked as invalid - if ( - profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile is not null - && profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile!.Value - ) + if (IsProfileInvalidOrUnloadable(sessionID)) { return 0; } @@ -297,4 +291,17 @@ public class SaveServer( return !fileUtil.FileExists(file); } + + public bool IsProfileInvalidOrUnloadable(MongoId sessionID) + { + if ( + profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile is not null + && profiles[sessionID].ProfileInfo!.InvalidOrUnloadableProfile!.Value + ) + { + return true; + } + + return false; + } } diff --git a/Libraries/SPTarkov.Server.Core/Services/ProfileValidatorService.cs b/Libraries/SPTarkov.Server.Core/Services/ProfileValidatorService.cs index be80ac8c..5866cf43 100644 --- a/Libraries/SPTarkov.Server.Core/Services/ProfileValidatorService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/ProfileValidatorService.cs @@ -56,7 +56,7 @@ public class ProfileValidatorService( } } - SptProfile sptReadyProfile; + SptProfile? sptReadyProfile = null; try { @@ -76,15 +76,24 @@ public class ProfileValidatorService( logger.Critical(ex.StackTrace); } - sptReadyProfile = new() + // If profile has passed deserialization, but caught an exception on CheckForOrphanedModdedItems + if (sptReadyProfile?.ProfileInfo is not null) { - ProfileInfo = new Info + sptReadyProfile.ProfileInfo.InvalidOrUnloadableProfile = true; + } + else + { + // Profile couldn't deserialize, make a small 'mock' profile to emulate it. + sptReadyProfile = new() { - ProfileId = new Models.Common.MongoId(profileId), - Username = profile["info"]?["username"]?.GetValue() ?? "", - InvalidOrUnloadableProfile = true, - }, - }; + ProfileInfo = new Info + { + ProfileId = new Models.Common.MongoId(profileId), + Username = profile["info"]?["username"]?.GetValue() ?? "", + InvalidOrUnloadableProfile = true, + }, + }; + } return sptReadyProfile; }