From 40f50ac90832808d17c4492aba2862955c3e2e93 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Wed, 30 Oct 2019 10:13:25 -0700 Subject: [PATCH] breaking: Remove localPlayerAuthority (#1192) * breaking: Remove localPlayerAuthority (#1188) * breaking: Remove localPlayerAuthority This flag does not do anything useful in anything but NetworkAnimator so NetworkAnimator can keep it's own flag. * Add tooltip with explanation * Editor should no longer access localPlayerAuthority property --- Assets/Mirror/Components/NetworkAnimator.cs | 12 +++--- Assets/Mirror/Editor/NetworkIdentityEditor.cs | 19 +-------- Assets/Mirror/Runtime/ClientScene.cs | 2 +- Assets/Mirror/Runtime/NetworkBehaviour.cs | 5 --- Assets/Mirror/Runtime/NetworkIdentity.cs | 39 ++----------------- Assets/Mirror/Runtime/NetworkServer.cs | 10 +---- 6 files changed, 14 insertions(+), 73 deletions(-) diff --git a/Assets/Mirror/Components/NetworkAnimator.cs b/Assets/Mirror/Components/NetworkAnimator.cs index 036105127..7b9e4cab6 100644 --- a/Assets/Mirror/Components/NetworkAnimator.cs +++ b/Assets/Mirror/Components/NetworkAnimator.cs @@ -34,17 +34,19 @@ public class NetworkAnimator : NetworkBehaviour int[] transitionHash; float sendTimer; + [Tooltip("Set to true if animations come from owner client, set to false if animations always come from server")] + public bool clientAuthority; + bool sendMessagesAllowed { get { if (isServer) { - if (!localPlayerAuthority) + if (!clientAuthority) return true; - // This is a special case where we have localPlayerAuthority set - // on a NetworkIdentity but we have not assigned the client who has + // This is a special case where we have client authority but we have not assigned the client who has // authority over it, no animator data will be sent over the network by the server. // // So we check here for a clientAuthorityOwner and if it is null we will @@ -360,7 +362,7 @@ public void SetTrigger(string triggerName) /// Hash id of trigger (from the Animator). public void SetTrigger(int hash) { - if (hasAuthority && localPlayerAuthority) + if (hasAuthority && clientAuthority) { if (ClientScene.readyConnection != null) { @@ -369,7 +371,7 @@ public void SetTrigger(int hash) return; } - if (isServer && !localPlayerAuthority) + if (isServer && !clientAuthority) { RpcOnAnimationTriggerClientMessage(hash); } diff --git a/Assets/Mirror/Editor/NetworkIdentityEditor.cs b/Assets/Mirror/Editor/NetworkIdentityEditor.cs index 8df4b25f8..818701325 100644 --- a/Assets/Mirror/Editor/NetworkIdentityEditor.cs +++ b/Assets/Mirror/Editor/NetworkIdentityEditor.cs @@ -9,10 +9,8 @@ namespace Mirror public class NetworkIdentityEditor : Editor { SerializedProperty serverOnlyProperty; - SerializedProperty localPlayerAuthorityProperty; readonly GUIContent serverOnlyLabel = new GUIContent("Server Only", "True if the object should only exist on the server."); - readonly GUIContent localPlayerAuthorityLabel = new GUIContent("Local Player Authority", "True if this object will be controlled by a player on a client."); readonly GUIContent spawnLabel = new GUIContent("Spawn Object", "This causes an unspawned server object to be spawned on clients"); NetworkIdentity networkIdentity; @@ -25,7 +23,6 @@ void Init() networkIdentity = target as NetworkIdentity; serverOnlyProperty = serializedObject.FindProperty("serverOnly"); - localPlayerAuthorityProperty = serializedObject.FindProperty("localPlayerAuthority"); } } @@ -35,21 +32,7 @@ public override void OnInspectorGUI() serializedObject.Update(); - if (serverOnlyProperty.boolValue) - { - EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel); - EditorGUILayout.LabelField("Local Player Authority cannot be set for server-only objects"); - } - else if (localPlayerAuthorityProperty.boolValue) - { - EditorGUILayout.LabelField("Server Only cannot be set for Local Player Authority objects"); - EditorGUILayout.PropertyField(localPlayerAuthorityProperty, localPlayerAuthorityLabel); - } - else - { - EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel); - EditorGUILayout.PropertyField(localPlayerAuthorityProperty, localPlayerAuthorityLabel); - } + EditorGUILayout.PropertyField(serverOnlyProperty, serverOnlyLabel); serializedObject.ApplyModifiedProperties(); diff --git a/Assets/Mirror/Runtime/ClientScene.cs b/Assets/Mirror/Runtime/ClientScene.cs index a4f19be6d..84c3ee25c 100644 --- a/Assets/Mirror/Runtime/ClientScene.cs +++ b/Assets/Mirror/Runtime/ClientScene.cs @@ -719,7 +719,7 @@ internal static void OnClientAuthority(NetworkConnection _, ClientAuthorityMessa if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity)) { - identity.HandleClientAuthority(msg.authority); + identity.ForceAuthority(msg.authority); } } diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index c1511aaeb..1c1e654de 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -36,11 +36,6 @@ public class NetworkBehaviour : MonoBehaviour /// [HideInInspector] public float syncInterval = 0.1f; - /// - /// This value is set on the NetworkIdentity and is accessible here for convenient access for scripts. - /// - public bool localPlayerAuthority => netIdentity.localPlayerAuthority; - /// /// Returns true if this object is active on an active server. /// This is only true if the object has been spawned. This is different from NetworkServer.active, which is true if the server itself is active rather than this object being active. diff --git a/Assets/Mirror/Runtime/NetworkIdentity.cs b/Assets/Mirror/Runtime/NetworkIdentity.cs index 817ccc1ff..ad285ded6 100644 --- a/Assets/Mirror/Runtime/NetworkIdentity.cs +++ b/Assets/Mirror/Runtime/NetworkIdentity.cs @@ -108,13 +108,6 @@ public bool isServer [FormerlySerializedAs("m_ServerOnly")] public bool serverOnly; - /// - /// localPlayerAuthority means that the client of the "owning" player has authority over their own player object. - /// Authority for this object will be on the player's client. So hasAuthority will be true on that client - and false on the server and on other clients. - /// - [FormerlySerializedAs("m_LocalPlayerAuthority")] - public bool localPlayerAuthority; - /// /// The client that has authority for this object. This will be null if no client has authority. /// This is set for player objects with localPlayerAuthority, and for objects set with AssignClientAuthority, and spawned with SpawnWithClientAuthority. @@ -294,12 +287,6 @@ void Awake() void OnValidate() { #if UNITY_EDITOR - if (serverOnly && localPlayerAuthority) - { - Debug.LogWarning("Disabling Local Player Authority for " + gameObject + " because it is server-only."); - localPlayerAuthority = false; - } - SetupIDs(); #endif } @@ -562,7 +549,7 @@ internal void OnStartClient() { isClient = true; - if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId + " localPlayerAuthority:" + localPlayerAuthority); + if (LogFilter.Debug) Debug.Log("OnStartClient " + gameObject + " netId:" + netId); foreach (NetworkBehaviour comp in NetworkBehaviours) { try @@ -836,18 +823,6 @@ internal void OnDeserializeAllSafely(NetworkReader reader, bool initialState) } } - // happens on client - internal void HandleClientAuthority(bool authority) - { - if (!localPlayerAuthority) - { - Debug.LogError("HandleClientAuthority " + gameObject + " does not have localPlayerAuthority"); - return; - } - - ForceAuthority(authority); - } - // helper function to handle SyncEvent/Command/Rpc void HandleRemoteCall(int componentIndex, int functionHash, MirrorInvokeType invokeType, NetworkReader reader) { @@ -904,16 +879,13 @@ internal void SetLocalPlayer() // or it will be called twice for this object, but that state is lost by the time OnStartAuthority // is called below, so the original value is cached here to be checked below. bool originAuthority = hasAuthority; - if (localPlayerAuthority) - { - hasAuthority = true; - } + hasAuthority = true; foreach (NetworkBehaviour comp in networkBehavioursCache) { comp.OnStartLocalPlayer(); - if (localPlayerAuthority && !originAuthority) + if (!originAuthority) { comp.OnStartAuthority(); } @@ -1135,11 +1107,6 @@ public bool AssignClientAuthority(NetworkConnection conn) Debug.LogError("AssignClientAuthority can only be called on the server for spawned objects."); return false; } - if (!localPlayerAuthority) - { - Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity components with LocalPlayerAuthority set."); - return false; - } if (clientAuthorityOwner != null && conn != clientAuthorityOwner) { diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index a1d9b6dcb..64aa922e9 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -821,10 +821,7 @@ public static bool AddPlayerForConnection(NetworkConnection conn, GameObject pla if (LogFilter.Debug) Debug.Log("Adding new playerGameObject object netId: " + identity.netId + " asset ID " + identity.assetId); FinishPlayerForConnection(identity, player); - if (identity.localPlayerAuthority) - { - identity.SetClientOwner(conn); - } + identity.SetClientOwner(conn); return true; } @@ -910,10 +907,7 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn, if (LogFilter.Debug) Debug.Log("Replacing playerGameObject object netId: " + player.GetComponent().netId + " asset ID " + player.GetComponent().assetId); FinishPlayerForConnection(identity, player); - if (identity.localPlayerAuthority) - { - identity.SetClientOwner(conn); - } + identity.SetClientOwner(conn); return true; }