From 318eabb190e44d06003a2e5ae31fcebfbe712a3d Mon Sep 17 00:00:00 2001 From: Extremelyd1 Date: Sun, 17 Dec 2023 17:15:29 +0100 Subject: [PATCH] Check for null or empty scene on client enter scene --- HKMP/Game/Server/ServerManager.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/HKMP/Game/Server/ServerManager.cs b/HKMP/Game/Server/ServerManager.cs index 7c6efb7..85ad812 100644 --- a/HKMP/Game/Server/ServerManager.cs +++ b/HKMP/Game/Server/ServerManager.cs @@ -321,6 +321,16 @@ private void OnClientEnterScene(ServerPlayerData playerData) { var enterSceneList = new List(); var alreadyPlayersInScene = false; + // Edge case where the scene of the player is empty (uninitialized) and we don't want to match with other + // uninitialized players. Otherwise, it causes issues where other parts of the player data for other players + // could be null and result in NREs further down the line + if (string.IsNullOrEmpty(playerData.CurrentScene)) { + _netServer.GetUpdateManagerForClient(playerData.Id)?.AddPlayerAlreadyInSceneData( + enterSceneList, + true + ); + } + foreach (var idPlayerDataPair in _playerData) { // Skip source player if (idPlayerDataPair.Key == playerData.Id) {