public bool AssignClientAuthority(NetworkConnection conn) { bool result; if (!this.isServer) { if (LogFilter.logError) { Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects."); } result = false; } else if (!this.localPlayerAuthority) { if (LogFilter.logError) { Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set."); } result = false; } else 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."); } result = false; } else if (conn == null) { if (LogFilter.logError) { Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead."); } result = false; } else { this.m_ClientAuthorityOwner = conn; this.m_ClientAuthorityOwner.AddOwnedObject(this); this.ForceAuthority(false); conn.Send(15, new ClientAuthorityMessage { netId = this.netId, authority = true }); if (NetworkIdentity.clientAuthorityCallback != null) { NetworkIdentity.clientAuthorityCallback(conn, this, true); } result = true; } return(result); }
public bool RemoveClientAuthority(NetworkConnection conn) { bool result; if (!this.isServer) { if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects."); } result = false; } else if (this.connectionToClient != null) { if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority cannot remove authority for a player object"); } result = false; } else if (this.m_ClientAuthorityOwner == null) { if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has no clientAuthority owner."); } result = false; } else if (this.m_ClientAuthorityOwner != conn) { if (LogFilter.logError) { Debug.LogError("RemoveClientAuthority for " + base.gameObject + " has different owner."); } result = false; } else { this.m_ClientAuthorityOwner.RemoveOwnedObject(this); this.m_ClientAuthorityOwner = null; this.ForceAuthority(true); conn.Send(15, new ClientAuthorityMessage { netId = this.netId, authority = false }); if (NetworkIdentity.clientAuthorityCallback != null) { NetworkIdentity.clientAuthorityCallback(conn, this, false); } result = true; } return(result); }
/// <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((object)"RemoveClientAuthority can only be call on the server for spawned objects."); } return(false); } if (this.connectionToClient != null) { if (LogFilter.logError) { Debug.LogError((object)"RemoveClientAuthority cannot remove authority for a player object"); } return(false); } if (this.m_ClientAuthorityOwner == null) { if (LogFilter.logError) { Debug.LogError((object)("RemoveClientAuthority for " + (object)this.gameObject + " has no clientAuthority owner.")); } return(false); } if (this.m_ClientAuthorityOwner != conn) { if (LogFilter.logError) { Debug.LogError((object)("RemoveClientAuthority for " + (object)this.gameObject + " has different owner.")); } return(false); } this.m_ClientAuthorityOwner.RemoveOwnedObject(this); this.m_ClientAuthorityOwner = (NetworkConnection)null; this.ForceAuthority(true); conn.Send((short)15, (MessageBase) new ClientAuthorityMessage() { netId = this.netId, authority = false }); if (NetworkIdentity.clientAuthorityCallback != null) { NetworkIdentity.clientAuthorityCallback(conn, this, false); } return(true); }