From 307071fa9f63d01875f9aca335c5598d14ef17d9 Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 29 Aug 2025 09:48:14 +0100 Subject: [PATCH] Moved GC to later in map gen Store Mongoid correctly --- .../Servers/Ws/SptWebSocketConnectionHandler.cs | 13 +++++++------ .../Services/LocationLifecycleService.cs | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Servers/Ws/SptWebSocketConnectionHandler.cs b/Libraries/SPTarkov.Server.Core/Servers/Ws/SptWebSocketConnectionHandler.cs index ca7f74dc..1c66d586 100644 --- a/Libraries/SPTarkov.Server.Core/Servers/Ws/SptWebSocketConnectionHandler.cs +++ b/Libraries/SPTarkov.Server.Core/Servers/Ws/SptWebSocketConnectionHandler.cs @@ -3,6 +3,7 @@ using System.Text; using Microsoft.AspNetCore.Http; using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Helpers; +using SPTarkov.Server.Core.Models.Common; using SPTarkov.Server.Core.Models.Eft.Ws; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Servers.Ws.Message; @@ -21,7 +22,7 @@ public class SptWebSocketConnectionHandler( IEnumerable messageHandlers ) : IWebSocketConnectionHandler { - protected readonly Dictionary> _sockets = new(); + protected readonly Dictionary> _sockets = new(); protected readonly Lock _socketsLock = new(); public string GetHookUrl() @@ -37,12 +38,12 @@ public class SptWebSocketConnectionHandler( public Task OnConnection(WebSocket ws, HttpContext context, string sessionIdContext) { var splitUrl = context.Request.Path.Value.Split("/"); - var sessionID = splitUrl.Last(); + var sessionID = new MongoId(splitUrl.Last()); var playerProfile = profileHelper.GetFullProfile(sessionID); var playerInfoText = $"{playerProfile.ProfileInfo.Username} ({sessionID})"; if (logger.IsLogEnabled(LogLevel.Debug)) { - logger.Debug($"[WS] Websocket connect for player {playerInfoText} started with context {sessionIdContext}"); + logger.Debug($"[WS] Websocket connect for player: {playerInfoText} started with context: {sessionIdContext}"); } lock (_socketsLock) @@ -159,7 +160,7 @@ public class SptWebSocketConnectionHandler( } } - public void SendMessage(string sessionID, WsNotificationEvent output) + public void SendMessage(MongoId sessionID, WsNotificationEvent output) { try { @@ -211,7 +212,7 @@ public class SptWebSocketConnectionHandler( } } - public bool IsWebSocketConnected(string sessionID) + public bool IsWebSocketConnected(MongoId sessionID) { lock (_socketsLock) { @@ -219,7 +220,7 @@ public class SptWebSocketConnectionHandler( } } - public IEnumerable GetSessionWebSocket(string sessionID) + public IEnumerable GetSessionWebSocket(MongoId sessionID) { lock (_socketsLock) { diff --git a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs index 3f28178d..2fe105ab 100644 --- a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs @@ -141,18 +141,18 @@ public class LocationLifecycleService( // Clear bot cache ready for bot generation call that occurs after this botNameService.ClearNameCache(); - GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); - // Handle Player Inventory Wiping checks for alt-f4 prevention HandlePreRaidInventoryChecks(request.PlayerSide, playerProfile.CharacterData.PmcData, sessionId); + GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true); + return result; } /// /// Handle Pre Raid checks Alt-F4 Prevention and player inventory wiping /// - protected void HandlePreRaidInventoryChecks(string playerSide, PmcData pmcData, string sessionId) + protected void HandlePreRaidInventoryChecks(string playerSide, PmcData pmcData, MongoId sessionId) { // If config enabled, remove players equipped items to prevent alt-F4 from persisting items if (!IsSide(playerSide) || !_lostOnDeathConfig.WipeOnRaidStart)