Skip to content

Commit

Permalink
Revert "fix: replacing the player does not mean giving up authority (…
Browse files Browse the repository at this point in the history
…#1254)"

This reverts commit a2c273e.
  • Loading branch information
paulpach committed Nov 29, 2019
1 parent fb26d00 commit b8618d3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b8618d3

Please sign in to comment.