Revert "fix: replacing the player does not mean giving up authority (#1254)"

This reverts commit a2c273ecd1.
This commit is contained in:
Paul Pacheco 2019-11-29 16:03:21 -06:00
parent fb26d0023f
commit b8618d356f
3 changed files with 23 additions and 0 deletions

View File

@ -718,6 +718,10 @@ static void CheckForLocalPlayer(NetworkIdentity identity)
{
if (identity.pendingLocalPlayer)
{
if (readyConnection.identity != null && readyConnection.identity != identity)
{
readyConnection.identity.SetNotLocalPlayer();
}
// supposed to be local player, so make it the local player!
// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO

View File

@ -204,6 +204,18 @@ internal void SetClientOwner(NetworkConnection conn)
/// </summary>
public static void ResetNextNetworkId() => nextNetworkId = 1;
// used when the player object for a connection changes
internal void SetNotLocalPlayer()
{
if (NetworkServer.active && NetworkServer.localClientActive)
{
// dont change authority for objects on the host
return;
}
hasAuthority = false;
NotifyAuthority();
}
// this is used when a connection is destroyed, since the "observers" property is read-only
internal void RemoveObserverInternal(NetworkConnection conn)
{

View File

@ -890,6 +890,13 @@ internal static bool InternalReplacePlayerForConnection(NetworkConnection conn,
//NOTE: there can be an existing player
if (LogFilter.Debug) Debug.Log("NetworkServer ReplacePlayer");
// is there already an owner that is a different object??
if (conn.identity != null)
{
conn.identity.SetNotLocalPlayer();
conn.identity.connectionToClient = null;
}
conn.identity = identity;
// Set the connection on the NetworkIdentity on the server, NetworkIdentity.SetLocalPlayer is not called on the server (it is on clients)