diff --git a/Libraries/SPTarkov.Server.Core/Controllers/MatchController.cs b/Libraries/SPTarkov.Server.Core/Controllers/MatchController.cs index db615725..11a701f1 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/MatchController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/MatchController.cs @@ -100,11 +100,7 @@ public class MatchController( request.IsNightRaid = _weatherHelper.IsNightTime(request.TimeVariant, request.Location); // Store request data for access during bot generation - ProfileActivityRaidData raidData = _profileActivityService.GetProfileActivityRaidData( - sessionId - ); - if (raidData != null) - raidData.RaidConfiguration = request; + _profileActivityService.GetProfileActivityRaidData(sessionId).RaidConfiguration = request; // TODO: add code to strip PMC of equipment now they've started the raid diff --git a/Libraries/SPTarkov.Server.Core/Services/ProfileActivityService.cs b/Libraries/SPTarkov.Server.Core/Services/ProfileActivityService.cs index 31815589..cdf0ab9b 100644 --- a/Libraries/SPTarkov.Server.Core/Services/ProfileActivityService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/ProfileActivityService.cs @@ -31,6 +31,16 @@ public class ProfileActivityService(TimeUtil timeUtil) ); } + public bool ContainsActiveProfile(string sessionId) + { + if (_activeProfiles.ContainsKey(sessionId)) + { + return true; + } + + return false; + } + // Yes this is terrible, the other alternative is re-doing half of bot-gen which is currently doing guess-work anyway public ProfileActivityRaidData? GetFirstProfileActivityRaidData() { @@ -42,8 +52,14 @@ public class ProfileActivityService(TimeUtil timeUtil) return null; } - public ProfileActivityRaidData? GetProfileActivityRaidData(string sessionId) + public ProfileActivityRaidData GetProfileActivityRaidData(string sessionId) { + // Handle edge cases where people might close the server but keep the client alive + if (!ContainsActiveProfile(sessionId)) + { + AddActiveProfile(sessionId, timeUtil.GetTimeStamp()); + } + if (_activeProfiles.TryGetValue(sessionId, out var currentActiveProfile)) { currentActiveProfile.RaidData ??= new(); @@ -51,7 +67,7 @@ public class ProfileActivityService(TimeUtil timeUtil) return currentActiveProfile.RaidData; } - return null; + throw new Exception($"Unable to retrieve active profile for session: {sessionId}"); } ///