mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Make RemoveClientAuthority easier to use (#1113)
* Make RemoveClientAuthority easier to use * Added back the returns...oops
This commit is contained in:
parent
db2e1488c1
commit
85e607088a
@ -181,9 +181,9 @@ internal set
|
|||||||
// (see AssignSceneID comments)
|
// (see AssignSceneID comments)
|
||||||
// suppress "Field 'NetworkIdentity.m_SceneId' is never assigned to, and will always have its default value 0"
|
// suppress "Field 'NetworkIdentity.m_SceneId' is never assigned to, and will always have its default value 0"
|
||||||
// when building standalone
|
// when building standalone
|
||||||
#pragma warning disable CS0649
|
#pragma warning disable CS0649
|
||||||
[SerializeField] ulong m_SceneId;
|
[SerializeField] ulong m_SceneId;
|
||||||
#pragma warning restore CS0649
|
#pragma warning restore CS0649
|
||||||
|
|
||||||
// keep track of all sceneIds to detect scene duplicates
|
// keep track of all sceneIds to detect scene duplicates
|
||||||
static readonly Dictionary<ulong, NetworkIdentity> sceneIds = new Dictionary<ulong, NetworkIdentity>();
|
static readonly Dictionary<ulong, NetworkIdentity> sceneIds = new Dictionary<ulong, NetworkIdentity>();
|
||||||
@ -801,7 +801,7 @@ void OnDeserializeSafely(NetworkBehaviour comp, NetworkReader reader, bool initi
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// show a detailed error and let the user know what went wrong
|
// show a detailed error and let the user know what went wrong
|
||||||
Debug.LogError("OnDeserialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + m_SceneId.ToString("X") + " length=" + contentSize + ". Possible Reasons:\n * Do " + comp.GetType() + "'s OnSerialize and OnDeserialize calls write the same amount of data(" + contentSize +" bytes)? \n * Was there an exception in " + comp.GetType() + "'s OnSerialize/OnDeserialize code?\n * Are the server and client the exact same project?\n * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.\n\n" + e);
|
Debug.LogError("OnDeserialize failed for: object=" + name + " component=" + comp.GetType() + " sceneId=" + m_SceneId.ToString("X") + " length=" + contentSize + ". Possible Reasons:\n * Do " + comp.GetType() + "'s OnSerialize and OnDeserialize calls write the same amount of data(" + contentSize + " bytes)? \n * Was there an exception in " + comp.GetType() + "'s OnSerialize/OnDeserialize code?\n * Are the server and client the exact same project?\n * Maybe this OnDeserialize call was meant for another GameObject? The sceneIds can easily get out of sync if the Hierarchy was modified only in the client OR the server. Try rebuilding both.\n\n" + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// now the reader should be EXACTLY at 'before + size'.
|
// now the reader should be EXACTLY at 'before + size'.
|
||||||
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user