From ff8ed03d3295d1c4c25b26ef43aabb2b3e0b6936 Mon Sep 17 00:00:00 2001 From: Enrique Pelaez Date: Fri, 2 Jun 2023 16:53:06 +0700 Subject: [PATCH 1/2] Checking for both isClient and isServer to consider NetworkManagerMode.Host --- Assets/Mirror/Core/NetworkBehaviour.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Assets/Mirror/Core/NetworkBehaviour.cs b/Assets/Mirror/Core/NetworkBehaviour.cs index cb58bf3b04d..afa2dd7b29c 100644 --- a/Assets/Mirror/Core/NetworkBehaviour.cs +++ b/Assets/Mirror/Core/NetworkBehaviour.cs @@ -85,9 +85,9 @@ public abstract class NetworkBehaviour : MonoBehaviour // also note that this is a per-NetworkBehaviour flag. // another component may not be client authoritative, etc. public bool authority => - isClient - ? syncDirection == SyncDirection.ClientToServer && isOwned - : syncDirection == SyncDirection.ServerToClient; + (isClient && syncDirection == SyncDirection.ClientToServer && isOwned) + || + (isServer && syncDirection == SyncDirection.ServerToClient); /// The unique network Id of this object (unique at runtime). public uint netId => netIdentity.netId; From 65baac00545b1d663f2fe59ea090af2a6d805627 Mon Sep 17 00:00:00 2001 From: Enrique Pelaez Date: Sat, 5 Aug 2023 22:03:20 +0700 Subject: [PATCH 2/2] Added AuthorityIsTrue and AuthorityIsFalse tests --- .../NetworkBehaviour/NetworkBehaviourTests.cs | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviour/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviour/NetworkBehaviourTests.cs index b0c8f7a549b..bd58c633e07 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviour/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviour/NetworkBehaviourTests.cs @@ -109,6 +109,71 @@ public void HasNoAuthorityByDefault() Assert.That(emptyBehaviour.isOwned, Is.False); } + [Test] + public void AuthorityIsFalseVariations() + { + // has no authority as client only (both sync directions) + CreateNetworked(out _, out NetworkIdentity identity, out EmptyBehaviour emptyBehaviour); + identity.isClient = true; + identity.isServer = false; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ClientToServer; + Debug.Assert(!emptyBehaviour.authority, "Client-only isOwned=false syncDirection=ClientToServer should have no authority"); + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = true; + identity.isServer = false; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ServerToClient; + Debug.Assert(!emptyBehaviour.authority, "Client-only isOwned=false syncDirection=ServerToClient should have no authority"); + // has no authority as server only + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = false; + identity.isServer = true; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ClientToServer; + Debug.Assert(!emptyBehaviour.authority, "Server-only isOwned=false syncDirection=ClientToServer should have no authority"); + // has no authority as host, not owned and client-to-server sync + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = true; + identity.isServer = true; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ClientToServer; + Debug.Assert(!emptyBehaviour.authority, "Host isOwned=false syncDirection=ClientToServer should have no authority"); + } + + [Test] + public void AuthorityIsTrueVariations() + { + // has authority as client only + CreateNetworked(out _, out NetworkIdentity identity, out EmptyBehaviour emptyBehaviour); + identity.isClient = true; + identity.isServer = false; + identity.isOwned = true; + emptyBehaviour.syncDirection = SyncDirection.ClientToServer; + Debug.Assert(emptyBehaviour.authority, "Client-only isOwned=true syncDirection=ClientToServer should have authority"); + // has authority as server only + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = false; + identity.isServer = true; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ServerToClient; + Debug.Assert(emptyBehaviour.authority, "Server-only isOwned=false syncDirection=ServerToClient should have authority"); + // has authority as host, owned and client-to-server sync + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = true; + identity.isServer = true; + identity.isOwned = true; + emptyBehaviour.syncDirection = SyncDirection.ClientToServer; + Debug.Assert(emptyBehaviour.authority, "Host isOwned=true syncDirection=ClientToServer should have authority"); + // has authority as host, not owned and server-to-client sync + CreateNetworked(out _, out identity, out emptyBehaviour); + identity.isClient = true; + identity.isServer = true; + identity.isOwned = false; + emptyBehaviour.syncDirection = SyncDirection.ServerToClient; + Debug.Assert(emptyBehaviour.authority, "Host isOwned=false syncDirection=ServerToClient should have authority"); + } + [Test] public void HasIdentitysNetId() {