Skip to content

Commit

Permalink
fix: #3528, #3529 NetworkBehaviour.authority now evaluates correctly …
Browse files Browse the repository at this point in the history
…in host mode too
  • Loading branch information
miwarnec committed Oct 29, 2023
1 parent 97dc02e commit bdb6cd8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Assets/Mirror/Core/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public abstract class NetworkBehaviour : MonoBehaviour
public bool hasAuthority => isOwned;

/// <summary>authority is true if we are allowed to modify this component's state. On server, it's true if SyncDirection is ServerToClient. On client, it's true if SyncDirection is ClientToServer and(!) if this object is owned by the client.</summary>
// on the client: if owned and if clientAuthority sync direction
// on the server: if serverAuthority sync direction
// on the client: if Client->Server SyncDirection and owned
// on the server: if Server->Client SyncDirection
// on the host: if Server->Client SyncDirection (= server owns it), or if Client->Server and owned (=host client owns it)
// in host mode: always true because either server or client always has authority, and host is both.
//
// for example, NetworkTransform:
// client may modify position if ClientAuthority mode and owned
Expand All @@ -84,10 +86,20 @@ 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;
public bool authority
{
get
{
// host mode needs to be checked explicitly
if (isClient && isServer) return syncDirection == SyncDirection.ServerToClient || isOwned;

// client-only
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;

// server-only
return syncDirection == SyncDirection.ServerToClient;
}
}

/// <summary>The unique network Id of this object (unique at runtime).</summary>
public uint netId => netIdentity.netId;
Expand Down

0 comments on commit bdb6cd8

Please sign in to comment.