Handle invalid profiles on all IOnUpdate

This commit is contained in:
Archangel
2025-08-05 17:20:49 +02:00
parent d5514c6bb4
commit c3b36f4c7d
6 changed files with 52 additions and 16 deletions
@@ -43,6 +43,11 @@ public class BtrDeliveryCallbacks(
// Process each installed profile.
foreach (var (sessionId, _) in saveServer.GetProfiles())
{
if (saveServer.IsProfileInvalidOrUnloadable(sessionId))
{
continue;
}
ProcessDeliveryByProfile(sessionId);
}
}
@@ -52,6 +52,11 @@ public class DialogueController(
var profiles = saveServer.GetProfiles();
foreach (var (sessionId, _) in profiles)
{
if (saveServer.IsProfileInvalidOrUnloadable(sessionId))
{
continue;
}
RemoveExpiredItemsFromMessages(sessionId);
}
}
@@ -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)
@@ -52,6 +52,11 @@ public class InsuranceController(
// Process each installed profile.
foreach (var (sessionId, _) in saveServer.GetProfiles())
{
if (saveServer.IsProfileInvalidOrUnloadable(sessionId))
{
continue;
}
ProcessReturnByProfile(sessionId);
}
}
@@ -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<long> 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;
}
}
@@ -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<string>() ?? "",
InvalidOrUnloadableProfile = true,
},
};
ProfileInfo = new Info
{
ProfileId = new Models.Common.MongoId(profileId),
Username = profile["info"]?["username"]?.GetValue<string>() ?? "",
InvalidOrUnloadableProfile = true,
},
};
}
return sptReadyProfile;
}