diff --git a/Assets/Mirror/Core/NetworkBehaviour.cs b/Assets/Mirror/Core/NetworkBehaviour.cs index b94b826b8..97c887119 100644 --- a/Assets/Mirror/Core/NetworkBehaviour.cs +++ b/Assets/Mirror/Core/NetworkBehaviour.cs @@ -412,7 +412,7 @@ protected void SendTargetRPCInternal(NetworkConnection conn, string functionFull // { // int oldValue = health; // SetSyncVar(value, ref health, 1uL); - // if (NetworkServer.localClientActive && !GetSyncVarHookGuard(1uL)) + // if (NetworkServer.activeHost && !GetSyncVarHookGuard(1uL)) // { // SetSyncVarHookGuard(1uL, value: true); // OnChanged(oldValue, value); @@ -436,7 +436,7 @@ public void GeneratedSyncVarSetter(T value, ref T field, ulong dirtyBit, Acti // in client-only mode, OnDeserialize would call it. // we use hook guard to protect against deadlock where hook // changes syncvar, calling hook again. - if (NetworkServer.localClientActive && !GetSyncVarHookGuard(dirtyBit)) + if (NetworkServer.activeHost && !GetSyncVarHookGuard(dirtyBit)) { SetSyncVarHookGuard(dirtyBit, true); OnChanged(oldValue, value); @@ -463,7 +463,7 @@ public void GeneratedSyncVarSetter_GameObject(GameObject value, ref GameObject f // in client-only mode, OnDeserialize would call it. // we use hook guard to protect against deadlock where hook // changes syncvar, calling hook again. - if (NetworkServer.localClientActive && !GetSyncVarHookGuard(dirtyBit)) + if (NetworkServer.activeHost && !GetSyncVarHookGuard(dirtyBit)) { SetSyncVarHookGuard(dirtyBit, true); OnChanged(oldValue, value); @@ -490,7 +490,7 @@ public void GeneratedSyncVarSetter_NetworkIdentity(NetworkIdentity value, ref Ne // in client-only mode, OnDeserialize would call it. // we use hook guard to protect against deadlock where hook // changes syncvar, calling hook again. - if (NetworkServer.localClientActive && !GetSyncVarHookGuard(dirtyBit)) + if (NetworkServer.activeHost && !GetSyncVarHookGuard(dirtyBit)) { SetSyncVarHookGuard(dirtyBit, true); OnChanged(oldValue, value); @@ -518,7 +518,7 @@ public void GeneratedSyncVarSetter_NetworkBehaviour(T value, ref T field, ulo // in client-only mode, OnDeserialize would call it. // we use hook guard to protect against deadlock where hook // changes syncvar, calling hook again. - if (NetworkServer.localClientActive && !GetSyncVarHookGuard(dirtyBit)) + if (NetworkServer.activeHost && !GetSyncVarHookGuard(dirtyBit)) { SetSyncVarHookGuard(dirtyBit, true); OnChanged(oldValue, value); diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index 27347dfbd..2a5be478c 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -36,7 +36,8 @@ public static partial class NetworkServer public static NetworkConnectionToClient localConnection { get; private set; } /// True is a local client is currently active on the server - public static bool localClientActive => localConnection != null; + [Obsolete("NetworkServer.localClientActive was renamed to .activeHost to be more obvious")] // DEPRECATED 2022-12-12 + public static bool localClientActive => activeHost; /// Dictionary of all server connections, with connectionId as key public static Dictionary connections = @@ -55,9 +56,12 @@ public static partial class NetworkServer // see also: https://github.com/vis2k/Mirror/pull/2595 public static bool dontListen; - /// active checks if the server has been started + /// active checks if the server has been started either has standalone or as host server. public static bool active { get; internal set; } + /// active checks if the server has been started in host mode. + public static bool activeHost => localConnection != null; + // scene loading public static bool isLoadingScene; @@ -1439,7 +1443,7 @@ static void DestroyObject(NetworkIdentity identity, DestroyMode mode) identity.ClearObservers(); // in host mode, call OnStopClient/OnStopLocalPlayer manually - if (NetworkClient.active && localClientActive) + if (NetworkClient.active && activeHost) { if (identity.isLocalPlayer) identity.OnStopLocalPlayer(); diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index 1e8965ae2..5642f6611 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -223,15 +223,15 @@ public void RemoveLocalConnection() } [Test] - public void LocalClientActive() + public void ActiveHost() { // listen NetworkServer.Listen(1); - Assert.That(NetworkServer.localClientActive, Is.False); + Assert.That(NetworkServer.activeHost, Is.False); // set local connection NetworkServer.SetLocalConnection(new LocalConnectionToClient()); - Assert.That(NetworkServer.localClientActive, Is.True); + Assert.That(NetworkServer.activeHost, Is.True); } [Test] @@ -1181,7 +1181,7 @@ public void ShutdownCleanup() Assert.That(NetworkServer.spawned.Count, Is.EqualTo(0)); Assert.That(NetworkServer.localConnection, Is.Null); - Assert.That(NetworkServer.localClientActive, Is.False); + Assert.That(NetworkServer.activeHost, Is.False); Assert.That(NetworkServer.OnConnectedEvent, Is.Null); Assert.That(NetworkServer.OnDisconnectedEvent, Is.Null); diff --git a/Assets/Mirror/Tests/Editor/SyncVarAttributeHook_HostModeTest.cs b/Assets/Mirror/Tests/Editor/SyncVarAttributeHook_HostModeTest.cs index b0c7c3887..0a6de890b 100644 --- a/Assets/Mirror/Tests/Editor/SyncVarAttributeHook_HostModeTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncVarAttributeHook_HostModeTest.cs @@ -32,8 +32,8 @@ public void StaticMethod_HookCalledFromSyncVarSetter() const int serverValue = 24; - // hooks setters are only called if localClientActive - Assert.That(NetworkServer.localClientActive, Is.True); + // hooks setters are only called if activeHost + Assert.That(NetworkServer.activeHost, Is.True); int hookcallCount = 0; StaticHookBehaviour.HookCalled += (oldValue, newValue) => @@ -60,8 +60,8 @@ public void VirtualHook_HookCalledWhenSyncingChangedValued() const int serverValue = 24; - // hooks setters are only called if localClientActive - Assert.That(NetworkServer.localClientActive, Is.True); + // hooks setters are only called if activeHost + Assert.That(NetworkServer.activeHost, Is.True); int baseCallCount = 0; comp.BaseHookCalled += (oldValue, newValue) => @@ -88,8 +88,8 @@ public void VirtualOverrideHook_HookCalledWhenSyncingChangedValued() const int serverValue = 24; - // hooks setters are only called if localClientActive - Assert.That(NetworkServer.localClientActive, Is.True); + // hooks setters are only called if activeHost + Assert.That(NetworkServer.activeHost, Is.True); // hook should change it on client int overrideCallCount = 0;