From ec478d2aac7a2e1626a78c479d1000cb1ea28904 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 26 Apr 2023 22:10:11 +0100 Subject: [PATCH] fix #609 --- QSB/ClientServerStateSync/ServerStateManager.cs | 11 ++++++++--- QSB/TimeSync/WakeUpSync.cs | 15 ++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/QSB/ClientServerStateSync/ServerStateManager.cs b/QSB/ClientServerStateSync/ServerStateManager.cs index 4de2a60d..01bf1d47 100644 --- a/QSB/ClientServerStateSync/ServerStateManager.cs +++ b/QSB/ClientServerStateSync/ServerStateManager.cs @@ -3,6 +3,7 @@ using QSB.DeathSync.Messages; using QSB.Messaging; using QSB.Player; using QSB.Player.TransformSync; +using QSB.TimeSync; using QSB.Utility; using System.Linq; using UnityEngine; @@ -32,7 +33,7 @@ internal class ServerStateManager : MonoBehaviour QSBSceneManager.OnPostSceneLoad += OnPostSceneLoad; GlobalMessenger.AddListener("TriggerSupernova", OnTriggerSupernova); - Delay.RunWhen(() => PlayerTransformSync.LocalInstance != null, + Delay.RunWhen(() => PlayerTransformSync.LocalInstance != null && WakeUpSync.LocalInstance != null, () => new ServerStateMessage(ForceGetCurrentState()).Send()); } @@ -77,7 +78,7 @@ internal class ServerStateManager : MonoBehaviour } else { - new ServerStateMessage(ServerState.InSolarSystem).Send(); + new ServerStateMessage(ServerState.NotLoaded).Send(); } break; @@ -118,7 +119,11 @@ internal class ServerStateManager : MonoBehaviour switch (currentScene) { case OWScene.SolarSystem: - return ServerState.InSolarSystem; + if (WakeUpSync.LocalInstance.HasWokenUp) + { + return ServerState.InSolarSystem; + } + return ServerState.NotLoaded; case OWScene.EyeOfTheUniverse: return ServerState.InEye; default: diff --git a/QSB/TimeSync/WakeUpSync.cs b/QSB/TimeSync/WakeUpSync.cs index ae2c0a3b..9b1c4442 100644 --- a/QSB/TimeSync/WakeUpSync.cs +++ b/QSB/TimeSync/WakeUpSync.cs @@ -35,7 +35,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart private float _sendTimer; private float _serverTime; private int _serverLoopCount; - private bool _hasWokenUp; + public bool HasWokenUp; public void OnDisconnect() { @@ -75,10 +75,11 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart DebugLog.DebugWrite($"OnWakeUp", MessageType.Info); if (QSBCore.IsHost) { + new ServerStateMessage(ServerState.InSolarSystem).Send(); RespawnOnDeath.Instance.Init(); } - _hasWokenUp = true; + HasWokenUp = true; } public void OnDestroy() @@ -89,12 +90,12 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isInUniverse) { - _hasWokenUp = false; + HasWokenUp = false; if (isInUniverse) { if (newScene == OWScene.EyeOfTheUniverse) { - _hasWokenUp = true; + HasWokenUp = true; } LocalInstance = this; @@ -124,7 +125,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart else { // dont bother sleeping, just wake up - if (!_hasWokenUp) + if (!HasWokenUp) { Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, WakeUp); } @@ -178,7 +179,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart else { // should only happen from Init so we gotta wait - if (!_hasWokenUp) + if (!HasWokenUp) { Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, WakeUp); } @@ -248,7 +249,7 @@ public class WakeUpSync : MonoBehaviour, IAddComponentOnStart QSBInputManager.Instance.SetInputsEnabled(true); - if (!_hasWokenUp) + if (!HasWokenUp) { WakeUp(); }