Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: NetworkIdentity.isOwned renamed to isClientOwned to properly indicate that it's a client-side flag #3532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class NetworkLerpRigidbody : NetworkBehaviour
/// </summary>
bool IgnoreSync => isServer || ClientWithAuthority;

bool ClientWithAuthority => clientAuthority && isOwned;
bool ClientWithAuthority => clientAuthority && isClientOwned;

protected override void OnValidate()
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Components/Experimental/NetworkRigidbody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override void OnValidate()
/// <returns></returns>
bool IgnoreSync => isServer || ClientWithAuthority;

bool ClientWithAuthority => clientAuthority && isOwned;
bool ClientWithAuthority => clientAuthority && isClientOwned;

void OnVelocityChanged(Vector3 _, Vector3 newValue)
{
Expand Down Expand Up @@ -180,7 +180,7 @@ void SyncToClients()
[Client]
void SendToServer()
{
if (!isOwned)
if (!isClientOwned)
{
Debug.LogWarning("SendToServer called without authority");
return;
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Components/Experimental/NetworkRigidbody2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected override void OnValidate()
/// </summary>
bool IgnoreSync => isServer || ClientWithAuthority;

bool ClientWithAuthority => clientAuthority && isOwned;
bool ClientWithAuthority => clientAuthority && isClientOwned;

void OnVelocityChanged(Vector2 _, Vector2 newValue)
{
Expand Down Expand Up @@ -177,7 +177,7 @@ void SyncToClients()
[Client]
void SendToServer()
{
if (!isOwned)
if (!isClientOwned)
{
Debug.LogWarning("SendToServer called without authority");
return;
Expand Down
20 changes: 10 additions & 10 deletions Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ bool SendMessagesAllowed
return true;
}

return (isOwned && clientAuthority);
return (isClientOwned && clientAuthority);
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ void OnAnimatorSpeedChanged(float _, float value)
{
// skip if host or client with authority
// they will have already set the speed so don't set again
if (isServer || (isOwned && clientAuthority))
if (isServer || (isClientOwned && clientAuthority))
return;

animator.speed = value;
Expand Down Expand Up @@ -227,7 +227,7 @@ void SendAnimationParametersMessage(byte[] parameters)

void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, float weight, NetworkReader reader)
{
if (isOwned && clientAuthority)
if (isClientOwned && clientAuthority)
return;

// usually transitions will be triggered by parameters, if not, play anims directly.
Expand All @@ -245,7 +245,7 @@ void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, float weigh

void HandleAnimParamsMsg(NetworkReader reader)
{
if (isOwned && clientAuthority)
if (isClientOwned && clientAuthority)
return;

ReadParameters(reader);
Expand Down Expand Up @@ -428,7 +428,7 @@ public void SetTrigger(int hash)
return;
}

if (!isOwned)
if (!isClientOwned)
{
Debug.LogWarning("Only the client with authority can set animations");
return;
Expand Down Expand Up @@ -475,7 +475,7 @@ public void ResetTrigger(int hash)
return;
}

if (!isOwned)
if (!isClientOwned)
{
Debug.LogWarning("Only the client with authority can reset animations");
return;
Expand Down Expand Up @@ -543,7 +543,7 @@ void CmdOnAnimationTriggerServerMessage(int hash)

// handle and broadcast
// host should have already the trigger
bool isHostOwner = isClient && isOwned;
bool isHostOwner = isClient && isClientOwned;
if (!isHostOwner)
{
HandleAnimTriggerMsg(hash);
Expand All @@ -561,7 +561,7 @@ void CmdOnAnimationResetTriggerServerMessage(int hash)

// handle and broadcast
// host should have already the trigger
bool isHostOwner = isClient && isOwned;
bool isHostOwner = isClient && isClientOwned;
if (!isHostOwner)
{
HandleAnimResetTriggerMsg(hash);
Expand Down Expand Up @@ -600,7 +600,7 @@ void RpcOnAnimationParametersClientMessage(byte[] parameters)
void RpcOnAnimationTriggerClientMessage(int hash)
{
// host/owner handles this before it is sent
if (isServer || (clientAuthority && isOwned)) return;
if (isServer || (clientAuthority && isClientOwned)) return;

HandleAnimTriggerMsg(hash);
}
Expand All @@ -609,7 +609,7 @@ void RpcOnAnimationTriggerClientMessage(int hash)
void RpcOnAnimationResetTriggerClientMessage(int hash)
{
// host/owner handles this before it is sent
if (isServer || (clientAuthority && isOwned)) return;
if (isServer || (clientAuthority && isClientOwned)) return;

HandleAnimResetTriggerMsg(hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected virtual void UpdateServer()
// https://github.com/MirrorNetworking/Mirror/issues/3329
if (syncDirection == SyncDirection.ClientToServer &&
connectionToClient != null &&
!isOwned)
!isClientOwned)
{
if (serverSnapshots.Count > 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void UpdateServerInterpolation()
// https://github.com/MirrorNetworking/Mirror/issues/3329
if (syncDirection == SyncDirection.ClientToServer &&
connectionToClient != null &&
!isOwned)
!isClientOwned)
{
if (serverSnapshots.Count == 0) return;

Expand Down
19 changes: 11 additions & 8 deletions Assets/Mirror/Core/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ public abstract class NetworkBehaviour : MonoBehaviour

/// <summary>isOwned is true on the client if this NetworkIdentity is one of the .owned entities of our connection on the server.</summary>
// for example: main player & pets are owned. monsters & npcs aren't.
public bool isOwned => netIdentity.isOwned;
public bool isClientOwned => netIdentity.isClientOwned;

[Obsolete(".isOwned was renamed to .isClientOwned to reflect that it's a client-only flag.")]
public bool isOwned => isClientOwned;

// Deprecated 2022-10-13
[Obsolete(".hasAuthority was renamed to .isOwned. This is easier to understand and prepares for SyncDirection, where there is a difference betwen isOwned and authority.")]
public bool hasAuthority => isOwned;
[Obsolete(".hasAuthority was renamed to .isClientOwned. This is easier to understand and prepares for SyncDirection, where there is a difference betwen isOwned and authority.")]
public bool hasAuthority => isClientOwned;

/// <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
Expand All @@ -86,7 +89,7 @@ public abstract class NetworkBehaviour : MonoBehaviour
// another component may not be client authoritative, etc.
public bool authority =>
isClient
? syncDirection == SyncDirection.ClientToServer && isOwned
? syncDirection == SyncDirection.ClientToServer && isClientOwned
: syncDirection == SyncDirection.ServerToClient;

/// <summary>The unique network Id of this object (unique at runtime).</summary>
Expand Down Expand Up @@ -244,7 +247,7 @@ protected void InitSyncObject(SyncObject syncObject)

// host mode: any ServerToClient and any local client owned
if (NetworkServer.active && NetworkClient.active)
return syncDirection == SyncDirection.ServerToClient || isOwned;
return syncDirection == SyncDirection.ServerToClient || isClientOwned;

// server only: any ServerToClient
if (NetworkServer.active)
Expand All @@ -254,7 +257,7 @@ protected void InitSyncObject(SyncObject syncObject)
if (NetworkClient.active)
{
// spawned: only ClientToServer and owned
if (netId != 0) return syncDirection == SyncDirection.ClientToServer && isOwned;
if (netId != 0) return syncDirection == SyncDirection.ClientToServer && isClientOwned;

// not spawned (character selection previews, etc.): always allow
// fixes https://github.com/MirrorNetworking/Mirror/issues/3343
Expand Down Expand Up @@ -284,7 +287,7 @@ protected void InitSyncObject(SyncObject syncObject)
if (isServer) return netIdentity.observers.Count > 0;

// client only: only ClientToServer and owned
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
if (isClient) return syncDirection == SyncDirection.ClientToServer && isClientOwned;

// users may add to SyncLists before the object was spawned.
// isServer / isClient would still be false.
Expand Down Expand Up @@ -340,7 +343,7 @@ protected void SendCommandInternal(string functionFullName, int functionHashCode

// local players can always send commands, regardless of authority,
// other objects must have authority.
if (!(!requiresAuthority || isLocalPlayer || isOwned))
if (!(!requiresAuthority || isLocalPlayer || isClientOwned))
{
Debug.LogWarning($"Command {functionFullName} called on {name} without authority.", gameObject);
return;
Expand Down
10 changes: 5 additions & 5 deletions Assets/Mirror/Core/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage me
// the below DeserializeClient call invokes SyncVarHooks.
// flags always need to be initialized before that.
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3259
identity.isOwned = message.isOwner;
identity.isClientOwned = message.isOwner;
identity.netId = message.netId;

if (message.isLocalPlayer)
Expand All @@ -1069,7 +1069,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage me
}

spawned[message.netId] = identity;
if (identity.isOwned) connection?.owned.Add(identity);
if (identity.isClientOwned) connection?.owned.Add(identity);

// the initial spawn with OnObjectSpawnStarted/Finished calls all
// object's OnStartClient/OnStartLocalPlayer after they were all
Expand Down Expand Up @@ -1279,7 +1279,7 @@ internal static void OnHostClientSpawn(SpawnMessage message)
if (aoi != null)
aoi.SetHostVisibility(identity, true);

identity.isOwned = message.isOwner;
identity.isClientOwned = message.isOwner;
BootstrapIdentity(identity);
}
}
Expand Down Expand Up @@ -1357,10 +1357,10 @@ internal static void ChangeOwner(NetworkIdentity identity, ChangeOwnerMessage me
}

// set ownership flag (aka authority)
identity.isOwned = message.isOwner;
identity.isClientOwned = message.isOwner;

// Add / Remove to client's connectionToServer.owned hashset.
if (identity.isOwned)
if (identity.isClientOwned)
connection?.owned.Add(identity);
else
connection?.owned.Remove(identity);
Expand Down
20 changes: 12 additions & 8 deletions Assets/Mirror/Core/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ public sealed class NetworkIdentity : MonoBehaviour

/// <summary>isOwned is true on the client if this NetworkIdentity is one of the .owned entities of our connection on the server.</summary>
// for example: main player & pets are owned. monsters & npcs aren't.
public bool isOwned { get; internal set; }
// this flag is client-only, not for the server.
public bool isClientOwned { get; internal set; }

[Obsolete(".isOwned was renamed to .isClientOwned to reflect that it's a client-only flag.")]
public bool isOwned => isClientOwned;

// Deprecated 2022-10-13
[Obsolete(".hasAuthority was renamed to .isOwned. This is easier to understand and prepares for SyncDirection, where there is a difference betwen isOwned and authority.")]
public bool hasAuthority => isOwned;
[Obsolete(".hasAuthority was renamed to .isClientOwned. This is easier to understand and prepares for SyncDirection, where there is a difference betwen isOwned and authority.")]
public bool hasAuthority => isClientOwned;

/// <summary>The set of network connections (players) that can see this object.</summary>
public readonly Dictionary<int, NetworkConnectionToClient> observers =
Expand Down Expand Up @@ -864,7 +868,7 @@ ulong ClientDirtyMask()

// on client, only consider owned components with SyncDirection to server
NetworkBehaviour component = components[i];
if (isOwned && component.syncDirection == SyncDirection.ClientToServer)
if (isClientOwned && component.syncDirection == SyncDirection.ClientToServer)
{
// set the n-th bit if dirty
// shifting from small to large numbers is varint-efficient.
Expand Down Expand Up @@ -1296,7 +1300,7 @@ internal void Reset()
//isLocalPlayer = false; <- cleared AFTER ClearLocalPlayer below!

// remove authority flag. This object may be unspawned, not destroyed, on client.
isOwned = false;
isClientOwned = false;
NotifyAuthority();

netId = 0;
Expand All @@ -1323,11 +1327,11 @@ internal void Reset()
bool hadAuthority;
internal void NotifyAuthority()
{
if (!hadAuthority && isOwned)
if (!hadAuthority && isClientOwned)
OnStartAuthority();
if (hadAuthority && !isOwned)
if (hadAuthority && !isClientOwned)
OnStopAuthority();
hadAuthority = isOwned;
hadAuthority = isClientOwned;
}

internal void OnStartAuthority()
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Core/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ public static bool AddPlayerForConnection(NetworkConnectionToClient conn, GameOb
// special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (conn is LocalConnectionToClient)
{
identity.isOwned = true;
identity.isClientOwned = true;
NetworkClient.InternalAddPlayer(identity);
}

Expand Down Expand Up @@ -983,7 +983,7 @@ public static bool ReplacePlayerForConnection(NetworkConnectionToClient conn, Ga
// special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (conn is LocalConnectionToClient)
{
identity.isOwned = true;
identity.isClientOwned = true;
NetworkClient.InternalAddPlayer(identity);
}

Expand Down Expand Up @@ -1397,7 +1397,7 @@ static void SpawnObject(GameObject obj, NetworkConnection ownerConnection)
// special case to make sure hasAuthority is set
// on start server in host mode
if (ownerConnection is LocalConnectionToClient)
identity.isOwned = true;
identity.isClientOwned = true;

// only call OnStartServer if not spawned yet.
// check used to be in NetworkIdentity. may not be necessary anymore.
Expand Down Expand Up @@ -1515,7 +1515,7 @@ static void DestroyObject(NetworkIdentity identity, DestroyMode mode)
// The object may have been spawned with host client ownership,
// e.g. a pet so we need to clear hasAuthority and call
// NotifyAuthority which invokes OnStopAuthority if hasAuthority.
identity.isOwned = false;
identity.isClientOwned = false;
identity.NotifyAuthority();

// remove from NetworkClient dictionary
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Editor/NetworkInformationPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ IEnumerable<NetworkIdentityInfo> GetNetworkIdentityInfo(NetworkIdentity identity
infos.Add(GetString("Network ID", identity.netId.ToString()));
infos.Add(GetBoolean("Is Client", identity.isClient));
infos.Add(GetBoolean("Is Server", identity.isServer));
infos.Add(GetBoolean("Is Owned", identity.isOwned));
infos.Add(GetBoolean("Is Owned", identity.isClientOwned));
infos.Add(GetBoolean("Is Local Player", identity.isLocalPlayer));
}
return infos;
Expand Down