Example #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);
        }
Example #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);
        }
Example #3
0
        /// <summary>
        /// <para>This assigns control of an object to a client via the client's NetworkConnection.</para>
        /// </summary>
        /// <param name="conn">The connection of the client to assign authority to.</param>
        /// <returns>
        /// <para>True if authority was assigned.</para>
        /// </returns>
        public bool AssignClientAuthority(NetworkConnection conn)
        {
            if (!this.isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }
            if (!this.localPlayerAuthority)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
                }
                return(false);
            }
            if ((this.m_ClientAuthorityOwner != null) && (conn != this.m_ClientAuthorityOwner))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return(false);
            }
            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return(false);
            }
            this.m_ClientAuthorityOwner = conn;
            this.m_ClientAuthorityOwner.AddOwnedObject(this);
            this.ForceAuthority(false);
            ClientAuthorityMessage msg = new ClientAuthorityMessage {
                netId     = this.netId,
                authority = true
            };

            conn.Send(15, msg);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, true);
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// <para>Removes ownership for an object for a client by its conneciton.</para>
        /// </summary>
        /// <param name="conn">The connection of the client to remove authority for.</param>
        /// <returns>
        /// <para>True if authority is removed.</para>
        /// </returns>
        public bool RemoveClientAuthority(NetworkConnection conn)
        {
            if (!this.isServer)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects.");
                }
                return(false);
            }
            if (this.connectionToClient != null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
                }
                return(false);
            }
            if (this.m_ClientAuthorityOwner == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has no clientAuthority owner.");
                }
                return(false);
            }
            if (this.m_ClientAuthorityOwner != conn)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has different owner.");
                }
                return(false);
            }
            this.m_ClientAuthorityOwner.RemoveOwnedObject(this);
            this.m_ClientAuthorityOwner = null;
            this.ForceAuthority(true);
            ClientAuthorityMessage msg = new ClientAuthorityMessage {
                netId     = this.netId,
                authority = false
            };

            conn.Send(15, msg);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, false);
            }
            return(true);
        }
Example #5
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 " + base.gameObject + " already has an owner. Use RemoveClientAuthority() first.");
                }
                return(false);
            }
            if (conn == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
                }
                return(false);
            }
            m_ClientAuthorityOwner = conn;
            m_ClientAuthorityOwner.AddOwnedObject(this);
            ForceAuthority(authority: false);
            ClientAuthorityMessage clientAuthorityMessage = new ClientAuthorityMessage();

            clientAuthorityMessage.netId     = netId;
            clientAuthorityMessage.authority = true;
            conn.Send(15, clientAuthorityMessage);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, authorityState: true);
            }
            return(true);
        }
Example #6
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 " + base.gameObject + " has no clientAuthority owner.");
                }
                return(false);
            }
            if (m_ClientAuthorityOwner != conn)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has different owner.");
                }
                return(false);
            }
            m_ClientAuthorityOwner.RemoveOwnedObject(this);
            m_ClientAuthorityOwner = null;
            ForceAuthority(authority: true);
            ClientAuthorityMessage clientAuthorityMessage = new ClientAuthorityMessage();

            clientAuthorityMessage.netId     = netId;
            clientAuthorityMessage.authority = false;
            conn.Send(15, clientAuthorityMessage);
            if (clientAuthorityCallback != null)
            {
                clientAuthorityCallback(conn, this, authorityState: false);
            }
            return(true);
        }
        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);
            }
        }