Make RemoveClientAuthority easier to use (#1113)

* Make RemoveClientAuthority easier to use

* Added back the returns...oops
This commit is contained in:
MrGadget 2019-09-25 14:45:18 -04:00 committed by Paul Pacheco
parent db2e1488c1
commit 85e607088a

View File

@ -1067,35 +1067,47 @@ public void RebuildObservers(bool initialize)
} }
/// <summary> /// <summary>
/// Removes ownership for an object for a client by its connection. /// Obsolete: Use <see cref="RemoveClientAuthority()"/> instead
/// <para>This applies to objects that had authority set by AssignClientAuthority, or NetworkServer.SpawnWithClientAuthority. Authority cannot be removed for player objects.</para>
/// </summary> /// </summary>
/// <param name="conn">The connection of the client to remove authority for.</param> /// <param name="conn">The connection of the client to remove authority for.</param>
/// <returns>True if authority is removed.</returns> /// <returns>True if authority is removed.</returns>
[EditorBrowsable(EditorBrowsableState.Never), Obsolete("NetworkConnection parameter is no longer needed and nothing is returned")]
public bool RemoveClientAuthority(NetworkConnection conn) public bool RemoveClientAuthority(NetworkConnection conn)
{
RemoveClientAuthority();
return true;
}
/// <summary>
/// Removes ownership for an object.
/// <para>This applies to objects that had authority set by AssignClientAuthority, or NetworkServer.SpawnWithClientAuthority.</para>
/// <para>Authority cannot be removed for player objects.</para>
/// </summary>
public void RemoveClientAuthority()
{ {
if (!isServer) if (!isServer)
{ {
Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects."); Debug.LogError("RemoveClientAuthority can only be call on the server for spawned objects.");
return false; return;
} }
if (connectionToClient != null) if (connectionToClient != null)
{ {
Debug.LogError("RemoveClientAuthority cannot remove authority for a player object"); Debug.LogError("RemoveClientAuthority cannot remove authority for a player object");
return false; return;
} }
if (clientAuthorityOwner == null) if (clientAuthorityOwner != null)
{ {
Debug.LogError("RemoveClientAuthority for " + gameObject + " has no clientAuthority owner."); // send msg to that client
return false; ClientAuthorityMessage msg = new ClientAuthorityMessage
} {
netId = netId,
authority = false
};
if (clientAuthorityOwner != conn) clientAuthorityOwner.Send(msg);
{ clientAuthorityCallback?.Invoke(clientAuthorityOwner, this, false);
Debug.LogError("RemoveClientAuthority for " + gameObject + " has different owner.");
return false;
} }
clientAuthorityOwner.RemoveOwnedObject(this); clientAuthorityOwner.RemoveOwnedObject(this);
@ -1103,17 +1115,6 @@ public bool RemoveClientAuthority(NetworkConnection conn)
// server now has authority (this is only called on server) // server now has authority (this is only called on server)
ForceAuthority(true); ForceAuthority(true);
// send msg to that client
ClientAuthorityMessage msg = new ClientAuthorityMessage
{
netId = netId,
authority = false
};
conn.Send(msg);
clientAuthorityCallback?.Invoke(conn, this, false);
return true;
} }
/// <summary> /// <summary>