예제 #1
0
        public bool RemoveClientAuthority(NetworkConnection conn)
        {
            if (!isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }

            if (connectionToClient != null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
                }
                return(false);
            }

            if (m_ClientAuthorityOwner == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + gameObject + " has no clientAuthority owner.");
                }
                return(false);
            }

            if (m_ClientAuthorityOwner != conn)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + gameObject + " has different owner.");
                }
                return(false);
            }

            m_ClientAuthorityOwner.RemoveOwnedObject(this);
            m_ClientAuthorityOwner = null;

            // server now has authority (this is only called on server)
            ForceAuthority(true);

            // send msg to that client
            var msg = new ClientAuthorityMessage();

            msg.netId     = netId;
            msg.authority = false;
            conn.Send((short)MsgType.LocalClientAuthority, msg);

            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, false);
            }
            return(true);
        }
예제 #2
0
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }
            if (!localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                }
                return(false);
            }

            if (m_ClientAuthorityOwner != null && conn != m_ClientAuthorityOwner)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return(false);
            }

            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return(false);
            }

            m_ClientAuthorityOwner = conn;
            m_ClientAuthorityOwner.AddOwnedObject(this);

            // server no longer has authority (this is called on server). Note that local client could re-acquire authority below
            ForceAuthority(false);

            // send msg to that client
            var msg = new ClientAuthorityMessage();

            msg.netId     = netId;
            msg.authority = true;
            conn.Send((short)MsgType.LocalClientAuthority, msg);

            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, true);
            }
            return(true);
        }
예제 #3
0
        internal static void OnClientAuthority(NetworkConnection _, ClientAuthorityMessage msg)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("ClientScene.OnClientAuthority for netId: " + msg.netId);
            }

            if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
            {
                identity.ForceAuthority(msg.authority);
            }
        }
예제 #4
0
        static void OnClientAuthority(NetworkMessage netMsg)
        {
            ClientAuthorityMessage msg = netMsg.ReadMessage<ClientAuthorityMessage>();

            if (LogFilter.Debug) { Debug.Log("ClientScene::OnClientAuthority for  connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId); }

            NetworkIdentity identity;
            if (NetworkIdentity.spawned.TryGetValue(msg.netId, out identity))
            {
                identity.HandleClientAuthority(msg.authority);
            }
        }
예제 #5
0
        internal static void OnClientAuthority(NetworkConnection _, ClientAuthorityMessage msg)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("ClientScene.OnClientAuthority for netId: " + msg.netId);
            }

            if (NetworkIdentity.spawned.TryGetValue(msg.netId, out NetworkIdentity identity))
            {
#if MIRROR_PROFILING
                NetworkProfiler.RecordMessage(NetworkDirection.Incoming, typeof(ClientAuthorityMessage), identity.gameObject.name, 1);
#endif
                identity.HandleClientAuthority(msg.authority);
            }
        }
예제 #6
0
        static void OnClientAuthority(NetworkMessage netMsg)
        {
            ClientAuthorityMessage msg = new ClientAuthorityMessage();

            netMsg.ReadMessage(msg);

            if (LogFilter.logDebug)
            {
                Debug.Log("ClientScene::OnClientAuthority for  connectionId=" + netMsg.conn.connectionId + " netId: " + msg.netId);
            }

            NetworkIdentity uv;

            if (s_NetworkScene.GetNetworkIdentity(msg.netId, out uv))
            {
                uv.HandleClientAuthority(msg.authority);
            }
        }