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

This commit is contained in:
mischa 2023-06-28 10:09:36 +08:00
parent 13e07f5603
commit 36d955b146
17 changed files with 92 additions and 85 deletions

View File

@ -33,7 +33,7 @@ public class NetworkLerpRigidbody : NetworkBehaviour
/// </summary> /// </summary>
bool IgnoreSync => isServer || ClientWithAuthority; bool IgnoreSync => isServer || ClientWithAuthority;
bool ClientWithAuthority => clientAuthority && isOwned; bool ClientWithAuthority => clientAuthority && isClientOwned;
protected override void OnValidate() protected override void OnValidate()
{ {

View File

@ -72,7 +72,7 @@ protected override void OnValidate()
/// <returns></returns> /// <returns></returns>
bool IgnoreSync => isServer || ClientWithAuthority; bool IgnoreSync => isServer || ClientWithAuthority;
bool ClientWithAuthority => clientAuthority && isOwned; bool ClientWithAuthority => clientAuthority && isClientOwned;
void OnVelocityChanged(Vector3 _, Vector3 newValue) void OnVelocityChanged(Vector3 _, Vector3 newValue)
{ {
@ -180,7 +180,7 @@ void SyncToClients()
[Client] [Client]
void SendToServer() void SendToServer()
{ {
if (!isOwned) if (!isClientOwned)
{ {
Debug.LogWarning("SendToServer called without authority"); Debug.LogWarning("SendToServer called without authority");
return; return;

View File

@ -69,7 +69,7 @@ protected override void OnValidate()
/// </summary> /// </summary>
bool IgnoreSync => isServer || ClientWithAuthority; bool IgnoreSync => isServer || ClientWithAuthority;
bool ClientWithAuthority => clientAuthority && isOwned; bool ClientWithAuthority => clientAuthority && isClientOwned;
void OnVelocityChanged(Vector2 _, Vector2 newValue) void OnVelocityChanged(Vector2 _, Vector2 newValue)
{ {
@ -177,7 +177,7 @@ void SyncToClients()
[Client] [Client]
void SendToServer() void SendToServer()
{ {
if (!isOwned) if (!isClientOwned)
{ {
Debug.LogWarning("SendToServer called without authority"); Debug.LogWarning("SendToServer called without authority");
return; return;

View File

@ -67,7 +67,7 @@ bool SendMessagesAllowed
return true; return true;
} }
return (isOwned && clientAuthority); return (isClientOwned && clientAuthority);
} }
} }
@ -137,7 +137,7 @@ void OnAnimatorSpeedChanged(float _, float value)
{ {
// skip if host or client with authority // skip if host or client with authority
// they will have already set the speed so don't set again // they will have already set the speed so don't set again
if (isServer || (isOwned && clientAuthority)) if (isServer || (isClientOwned && clientAuthority))
return; return;
animator.speed = value; animator.speed = value;
@ -227,7 +227,7 @@ void SendAnimationParametersMessage(byte[] parameters)
void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, float weight, NetworkReader reader) void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, float weight, NetworkReader reader)
{ {
if (isOwned && clientAuthority) if (isClientOwned && clientAuthority)
return; return;
// usually transitions will be triggered by parameters, if not, play anims directly. // usually transitions will be triggered by parameters, if not, play anims directly.
@ -245,7 +245,7 @@ void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, float weigh
void HandleAnimParamsMsg(NetworkReader reader) void HandleAnimParamsMsg(NetworkReader reader)
{ {
if (isOwned && clientAuthority) if (isClientOwned && clientAuthority)
return; return;
ReadParameters(reader); ReadParameters(reader);
@ -428,7 +428,7 @@ public void SetTrigger(int hash)
return; return;
} }
if (!isOwned) if (!isClientOwned)
{ {
Debug.LogWarning("Only the client with authority can set animations"); Debug.LogWarning("Only the client with authority can set animations");
return; return;
@ -475,7 +475,7 @@ public void ResetTrigger(int hash)
return; return;
} }
if (!isOwned) if (!isClientOwned)
{ {
Debug.LogWarning("Only the client with authority can reset animations"); Debug.LogWarning("Only the client with authority can reset animations");
return; return;
@ -543,7 +543,7 @@ void CmdOnAnimationTriggerServerMessage(int hash)
// handle and broadcast // handle and broadcast
// host should have already the trigger // host should have already the trigger
bool isHostOwner = isClient && isOwned; bool isHostOwner = isClient && isClientOwned;
if (!isHostOwner) if (!isHostOwner)
{ {
HandleAnimTriggerMsg(hash); HandleAnimTriggerMsg(hash);
@ -561,7 +561,7 @@ void CmdOnAnimationResetTriggerServerMessage(int hash)
// handle and broadcast // handle and broadcast
// host should have already the trigger // host should have already the trigger
bool isHostOwner = isClient && isOwned; bool isHostOwner = isClient && isClientOwned;
if (!isHostOwner) if (!isHostOwner)
{ {
HandleAnimResetTriggerMsg(hash); HandleAnimResetTriggerMsg(hash);
@ -600,7 +600,7 @@ void RpcOnAnimationParametersClientMessage(byte[] parameters)
void RpcOnAnimationTriggerClientMessage(int hash) void RpcOnAnimationTriggerClientMessage(int hash)
{ {
// host/owner handles this before it is sent // host/owner handles this before it is sent
if (isServer || (clientAuthority && isOwned)) return; if (isServer || (clientAuthority && isClientOwned)) return;
HandleAnimTriggerMsg(hash); HandleAnimTriggerMsg(hash);
} }
@ -609,7 +609,7 @@ void RpcOnAnimationTriggerClientMessage(int hash)
void RpcOnAnimationResetTriggerClientMessage(int hash) void RpcOnAnimationResetTriggerClientMessage(int hash)
{ {
// host/owner handles this before it is sent // host/owner handles this before it is sent
if (isServer || (clientAuthority && isOwned)) return; if (isServer || (clientAuthority && isClientOwned)) return;
HandleAnimResetTriggerMsg(hash); HandleAnimResetTriggerMsg(hash);
} }

View File

@ -87,7 +87,7 @@ protected virtual void UpdateServer()
// https://github.com/MirrorNetworking/Mirror/issues/3329 // https://github.com/MirrorNetworking/Mirror/issues/3329
if (syncDirection == SyncDirection.ClientToServer && if (syncDirection == SyncDirection.ClientToServer &&
connectionToClient != null && connectionToClient != null &&
!isOwned) !isClientOwned)
{ {
if (serverSnapshots.Count > 0) if (serverSnapshots.Count > 0)
{ {

View File

@ -165,7 +165,7 @@ void UpdateServerInterpolation()
// https://github.com/MirrorNetworking/Mirror/issues/3329 // https://github.com/MirrorNetworking/Mirror/issues/3329
if (syncDirection == SyncDirection.ClientToServer && if (syncDirection == SyncDirection.ClientToServer &&
connectionToClient != null && connectionToClient != null &&
!isOwned) !isClientOwned)
{ {
if (serverSnapshots.Count == 0) return; if (serverSnapshots.Count == 0) return;

View File

@ -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> /// <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. // 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 // 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.")] [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 => isOwned; 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> /// <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 client: if owned and if clientAuthority sync direction
@ -86,7 +89,7 @@ public abstract class NetworkBehaviour : MonoBehaviour
// another component may not be client authoritative, etc. // another component may not be client authoritative, etc.
public bool authority => public bool authority =>
isClient isClient
? syncDirection == SyncDirection.ClientToServer && isOwned ? syncDirection == SyncDirection.ClientToServer && isClientOwned
: syncDirection == SyncDirection.ServerToClient; : syncDirection == SyncDirection.ServerToClient;
/// <summary>The unique network Id of this object (unique at runtime).</summary> /// <summary>The unique network Id of this object (unique at runtime).</summary>
@ -244,7 +247,7 @@ protected void InitSyncObject(SyncObject syncObject)
// host mode: any ServerToClient and any local client owned // host mode: any ServerToClient and any local client owned
if (NetworkServer.active && NetworkClient.active) if (NetworkServer.active && NetworkClient.active)
return syncDirection == SyncDirection.ServerToClient || isOwned; return syncDirection == SyncDirection.ServerToClient || isClientOwned;
// server only: any ServerToClient // server only: any ServerToClient
if (NetworkServer.active) if (NetworkServer.active)
@ -254,7 +257,7 @@ protected void InitSyncObject(SyncObject syncObject)
if (NetworkClient.active) if (NetworkClient.active)
{ {
// spawned: only ClientToServer and owned // 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 // not spawned (character selection previews, etc.): always allow
// fixes https://github.com/MirrorNetworking/Mirror/issues/3343 // fixes https://github.com/MirrorNetworking/Mirror/issues/3343
@ -284,7 +287,7 @@ protected void InitSyncObject(SyncObject syncObject)
if (isServer) return netIdentity.observers.Count > 0; if (isServer) return netIdentity.observers.Count > 0;
// client only: only ClientToServer and owned // 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. // users may add to SyncLists before the object was spawned.
// isServer / isClient would still be false. // isServer / isClient would still be false.
@ -340,7 +343,7 @@ protected void SendCommandInternal(string functionFullName, int functionHashCode
// local players can always send commands, regardless of authority, // local players can always send commands, regardless of authority,
// other objects must have authority. // other objects must have authority.
if (!(!requiresAuthority || isLocalPlayer || isOwned)) if (!(!requiresAuthority || isLocalPlayer || isClientOwned))
{ {
Debug.LogWarning($"Command {functionFullName} called on {name} without authority.", gameObject); Debug.LogWarning($"Command {functionFullName} called on {name} without authority.", gameObject);
return; return;

View File

@ -1044,7 +1044,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage me
// the below DeserializeClient call invokes SyncVarHooks. // the below DeserializeClient call invokes SyncVarHooks.
// flags always need to be initialized before that. // flags always need to be initialized before that.
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3259 // fixes: https://github.com/MirrorNetworking/Mirror/issues/3259
identity.isOwned = message.isOwner; identity.isClientOwned = message.isOwner;
identity.netId = message.netId; identity.netId = message.netId;
if (message.isLocalPlayer) if (message.isLocalPlayer)
@ -1069,7 +1069,7 @@ internal static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage me
} }
spawned[message.netId] = identity; 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 // the initial spawn with OnObjectSpawnStarted/Finished calls all
// object's OnStartClient/OnStartLocalPlayer after they were all // object's OnStartClient/OnStartLocalPlayer after they were all
@ -1279,7 +1279,7 @@ internal static void OnHostClientSpawn(SpawnMessage message)
if (aoi != null) if (aoi != null)
aoi.SetHostVisibility(identity, true); aoi.SetHostVisibility(identity, true);
identity.isOwned = message.isOwner; identity.isClientOwned = message.isOwner;
BootstrapIdentity(identity); BootstrapIdentity(identity);
} }
} }
@ -1357,10 +1357,10 @@ internal static void ChangeOwner(NetworkIdentity identity, ChangeOwnerMessage me
} }
// set ownership flag (aka authority) // set ownership flag (aka authority)
identity.isOwned = message.isOwner; identity.isClientOwned = message.isOwner;
// Add / Remove to client's connectionToServer.owned hashset. // Add / Remove to client's connectionToServer.owned hashset.
if (identity.isOwned) if (identity.isClientOwned)
connection?.owned.Add(identity); connection?.owned.Add(identity);
else else
connection?.owned.Remove(identity); connection?.owned.Remove(identity);

View File

@ -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> /// <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. // 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 // 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.")] [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 => isOwned; public bool hasAuthority => isClientOwned;
/// <summary>The set of network connections (players) that can see this object.</summary> /// <summary>The set of network connections (players) that can see this object.</summary>
public readonly Dictionary<int, NetworkConnectionToClient> observers = public readonly Dictionary<int, NetworkConnectionToClient> observers =
@ -864,7 +868,7 @@ ulong ClientDirtyMask()
// on client, only consider owned components with SyncDirection to server // on client, only consider owned components with SyncDirection to server
NetworkBehaviour component = components[i]; NetworkBehaviour component = components[i];
if (isOwned && component.syncDirection == SyncDirection.ClientToServer) if (isClientOwned && component.syncDirection == SyncDirection.ClientToServer)
{ {
// set the n-th bit if dirty // set the n-th bit if dirty
// shifting from small to large numbers is varint-efficient. // shifting from small to large numbers is varint-efficient.
@ -1296,7 +1300,7 @@ internal void Reset()
//isLocalPlayer = false; <- cleared AFTER ClearLocalPlayer below! //isLocalPlayer = false; <- cleared AFTER ClearLocalPlayer below!
// remove authority flag. This object may be unspawned, not destroyed, on client. // remove authority flag. This object may be unspawned, not destroyed, on client.
isOwned = false; isClientOwned = false;
NotifyAuthority(); NotifyAuthority();
netId = 0; netId = 0;
@ -1323,11 +1327,11 @@ internal void Reset()
bool hadAuthority; bool hadAuthority;
internal void NotifyAuthority() internal void NotifyAuthority()
{ {
if (!hadAuthority && isOwned) if (!hadAuthority && isClientOwned)
OnStartAuthority(); OnStartAuthority();
if (hadAuthority && !isOwned) if (hadAuthority && !isClientOwned)
OnStopAuthority(); OnStopAuthority();
hadAuthority = isOwned; hadAuthority = isClientOwned;
} }
internal void OnStartAuthority() internal void OnStartAuthority()

View File

@ -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 // special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (conn is LocalConnectionToClient) if (conn is LocalConnectionToClient)
{ {
identity.isOwned = true; identity.isClientOwned = true;
NetworkClient.InternalAddPlayer(identity); NetworkClient.InternalAddPlayer(identity);
} }
@ -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 // special case, we are in host mode, set hasAuthority to true so that all overrides see it
if (conn is LocalConnectionToClient) if (conn is LocalConnectionToClient)
{ {
identity.isOwned = true; identity.isClientOwned = true;
NetworkClient.InternalAddPlayer(identity); NetworkClient.InternalAddPlayer(identity);
} }
@ -1397,7 +1397,7 @@ static void SpawnObject(GameObject obj, NetworkConnection ownerConnection)
// special case to make sure hasAuthority is set // special case to make sure hasAuthority is set
// on start server in host mode // on start server in host mode
if (ownerConnection is LocalConnectionToClient) if (ownerConnection is LocalConnectionToClient)
identity.isOwned = true; identity.isClientOwned = true;
// only call OnStartServer if not spawned yet. // only call OnStartServer if not spawned yet.
// check used to be in NetworkIdentity. may not be necessary anymore. // check used to be in NetworkIdentity. may not be necessary anymore.
@ -1515,7 +1515,7 @@ static void DestroyObject(NetworkIdentity identity, DestroyMode mode)
// The object may have been spawned with host client ownership, // The object may have been spawned with host client ownership,
// e.g. a pet so we need to clear hasAuthority and call // e.g. a pet so we need to clear hasAuthority and call
// NotifyAuthority which invokes OnStopAuthority if hasAuthority. // NotifyAuthority which invokes OnStopAuthority if hasAuthority.
identity.isOwned = false; identity.isClientOwned = false;
identity.NotifyAuthority(); identity.NotifyAuthority();
// remove from NetworkClient dictionary // remove from NetworkClient dictionary

View File

@ -252,7 +252,7 @@ IEnumerable<NetworkIdentityInfo> GetNetworkIdentityInfo(NetworkIdentity identity
infos.Add(GetString("Network ID", identity.netId.ToString())); infos.Add(GetString("Network ID", identity.netId.ToString()));
infos.Add(GetBoolean("Is Client", identity.isClient)); infos.Add(GetBoolean("Is Client", identity.isClient));
infos.Add(GetBoolean("Is Server", identity.isServer)); 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)); infos.Add(GetBoolean("Is Local Player", identity.isLocalPlayer));
} }
return infos; return infos;

View File

@ -263,7 +263,7 @@ protected void CreateNetworkedAndSpawn(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
Debug.Assert(clientIdentity.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientIdentity.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
// make sure the client really spawned it. // make sure the client really spawned it.
Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId)); Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId));
@ -286,7 +286,7 @@ protected void CreateNetworkedAndSpawn<T>(out GameObject go, out NetworkIdentity
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
Debug.Assert(component.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(component.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// create GameObject + NetworkIdentity + NetworkBehaviour in children & SPAWN // create GameObject + NetworkIdentity + NetworkBehaviour in children & SPAWN
@ -306,7 +306,7 @@ protected void CreateNetworkedChildAndSpawn<T>(out GameObject parent, out GameOb
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
Debug.Assert(component.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(component.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// create GameObject + NetworkIdentity + NetworkBehaviour & SPAWN // create GameObject + NetworkIdentity + NetworkBehaviour & SPAWN
@ -342,7 +342,7 @@ protected void CreateNetworkedAndSpawn<T>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
Debug.Assert(clientComponent.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponent.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
// make sure the client really spawned it. // make sure the client really spawned it.
Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId)); Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId));
@ -381,7 +381,7 @@ protected void CreateNetworkedChildAndSpawn<T>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
Debug.Assert(clientComponent.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponent.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
// make sure the client really spawned it. // make sure the client really spawned it.
Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId)); Assert.That(NetworkClient.spawned.ContainsKey(serverIdentity.netId));
@ -406,8 +406,8 @@ protected void CreateNetworkedAndSpawn<T, U>(out GameObject go, out NetworkIdent
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(componentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
} }
@ -430,8 +430,8 @@ protected void CreateNetworkedChildAndSpawn<T, U>(out GameObject parent, out Gam
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(componentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
} }
@ -470,8 +470,8 @@ protected void CreateNetworkedAndSpawn<T, U>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(clientComponentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// make sure the client really spawned it. // make sure the client really spawned it.
@ -513,8 +513,8 @@ protected void CreateNetworkedChildAndSpawn<T, U>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(clientComponentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// make sure the client really spawned it. // make sure the client really spawned it.
@ -541,9 +541,9 @@ protected void CreateNetworkedAndSpawn<T, U, V>(out GameObject go, out NetworkId
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(componentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentC.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentC.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
} }
@ -567,9 +567,9 @@ protected void CreateNetworkedChildAndSpawn<T, U, V>(out GameObject parent, out
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(componentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(componentC.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(componentC.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
} }
@ -609,9 +609,9 @@ protected void CreateNetworkedAndSpawn<T, U, V>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(clientComponentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentC.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentC.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// make sure the client really spawned it. // make sure the client really spawned it.
@ -654,9 +654,9 @@ protected void CreateNetworkedChildAndSpawn<T, U, V>(
// double check that we have authority if we passed an owner connection // double check that we have authority if we passed an owner connection
if (ownerConnection != null) if (ownerConnection != null)
{ {
Debug.Assert(clientComponentA.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentA.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentB.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentB.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
Debug.Assert(clientComponentC.isOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results"); Debug.Assert(clientComponentC.isClientOwned == true, $"Behaviour Had Wrong Authority when spawned, This means that the test is broken and will give the wrong results");
} }
// make sure the client really spawned it. // make sure the client really spawned it.

View File

@ -106,7 +106,7 @@ public void HasNoAuthorityByDefault()
{ {
// no authority by default // no authority by default
CreateNetworked(out _, out _, out EmptyBehaviour emptyBehaviour); CreateNetworked(out _, out _, out EmptyBehaviour emptyBehaviour);
Assert.That(emptyBehaviour.isOwned, Is.False); Assert.That(emptyBehaviour.isClientOwned, Is.False);
} }
[Test] [Test]

View File

@ -415,11 +415,11 @@ public void ApplyPayload_AppliesAuthority(bool isOwner)
}; };
// set to opposite to make sure it is changed // set to opposite to make sure it is changed
identity.isOwned = !isOwner; identity.isClientOwned = !isOwner;
NetworkClient.ApplySpawnPayload(identity, msg); NetworkClient.ApplySpawnPayload(identity, msg);
Assert.That(identity.isOwned, Is.EqualTo(isOwner)); Assert.That(identity.isClientOwned, Is.EqualTo(isOwner));
} }
[Test] [Test]

View File

@ -252,7 +252,7 @@ public void SerializeAndDeserialize_ClientToServer_NOT_OWNED()
// set to CLIENT with some unique values // set to CLIENT with some unique values
// and set connection to server to pretend we are the owner. // and set connection to server to pretend we are the owner.
identity.isOwned = false; identity.isClientOwned = false;
identity.connectionToServer = null; // NOT OWNED identity.connectionToServer = null; // NOT OWNED
comp1.syncDirection = SyncDirection.ServerToClient; comp1.syncDirection = SyncDirection.ServerToClient;
comp1.value = 12345; comp1.value = 12345;

View File

@ -379,40 +379,40 @@ public void NotifyAuthorityCallsOnStartStopAuthority()
CreateNetworked(out GameObject _, out NetworkIdentity identity, out NetworkBehaviourMock comp); CreateNetworked(out GameObject _, out NetworkIdentity identity, out NetworkBehaviourMock comp);
// set authority from false to true, which should call OnStartAuthority // set authority from false to true, which should call OnStartAuthority
identity.isOwned = true; identity.isClientOwned = true;
identity.NotifyAuthority(); identity.NotifyAuthority();
// shouldn't be touched // shouldn't be touched
Assert.That(identity.isOwned, Is.True); Assert.That(identity.isClientOwned, Is.True);
// start should be called // start should be called
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// stop shouldn't // stop shouldn't
Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(0)); Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(0));
// set it to true again, should do nothing because already true // set it to true again, should do nothing because already true
identity.isOwned = true; identity.isClientOwned = true;
identity.NotifyAuthority(); identity.NotifyAuthority();
// shouldn't be touched // shouldn't be touched
Assert.That(identity.isOwned, Is.True); Assert.That(identity.isClientOwned, Is.True);
// same as before // same as before
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// same as before // same as before
Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(0)); Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(0));
// set it to false, should call OnStopAuthority // set it to false, should call OnStopAuthority
identity.isOwned = false; identity.isClientOwned = false;
identity.NotifyAuthority(); identity.NotifyAuthority();
// should be changed // should be changed
Assert.That(identity.isOwned, Is.False); Assert.That(identity.isClientOwned, Is.False);
// same as before // same as before
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// stop should be called // stop should be called
Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStopAuthorityCalled, Is.EqualTo(1));
// set it to false again, should do nothing because already false // set it to false again, should do nothing because already false
identity.isOwned = false; identity.isClientOwned = false;
identity.NotifyAuthority(); identity.NotifyAuthority();
// shouldn't be touched // shouldn't be touched
Assert.That(identity.isOwned, Is.False); Assert.That(identity.isClientOwned, Is.False);
// same as before // same as before
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// same as before // same as before
@ -676,7 +676,7 @@ public void Reset()
Assert.That(identity.netId, Is.EqualTo(0)); Assert.That(identity.netId, Is.EqualTo(0));
Assert.That(identity.connectionToClient, Is.Null); Assert.That(identity.connectionToClient, Is.Null);
Assert.That(identity.connectionToServer, Is.Null); Assert.That(identity.connectionToServer, Is.Null);
Assert.That(identity.isOwned, Is.False); Assert.That(identity.isClientOwned, Is.False);
Assert.That(identity.observers, Is.Empty); Assert.That(identity.observers, Is.Empty);
} }

View File

@ -324,7 +324,7 @@ public void Destroy_HostMode_CallsOnStopAuthority()
NetworkServer.localConnection); NetworkServer.localConnection);
// need to have authority for this test // need to have authority for this test
Assert.That(player.isOwned, Is.True); Assert.That(player.isClientOwned, Is.True);
// destroy and ignore 'Destroy called in Edit mode' error // destroy and ignore 'Destroy called in Edit mode' error
LogAssert.ignoreFailingMessages = true; LogAssert.ignoreFailingMessages = true;
@ -1070,11 +1070,11 @@ public void UnSpawnAndClearAuthority()
go.SetActive(true); go.SetActive(true);
// set authority from false to true, which should call OnStartAuthority // set authority from false to true, which should call OnStartAuthority
identity.isOwned = true; identity.isClientOwned = true;
identity.NotifyAuthority(); identity.NotifyAuthority();
// shouldn't be touched // shouldn't be touched
Assert.That(identity.isOwned, Is.True); Assert.That(identity.isClientOwned, Is.True);
// start should be called // start should be called
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// stop shouldn't // stop shouldn't
@ -1085,7 +1085,7 @@ public void UnSpawnAndClearAuthority()
Assert.That(identity.netId, Is.Zero); Assert.That(identity.netId, Is.Zero);
// should be changed // should be changed
Assert.That(identity.isOwned, Is.False); Assert.That(identity.isClientOwned, Is.False);
// same as before // same as before
Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1)); Assert.That(comp.onStartAuthorityCalled, Is.EqualTo(1));
// stop should be called // stop should be called