internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
{
NetworkIdentity identity;
PlayerController controller;
if (!GetNetworkIdentity(playerGameObject, out identity))
{
if (LogFilter.logError)
{
Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject);
}
return false;
}
if (!CheckPlayerControllerIdForConnection(conn, playerControllerId))
{
return false;
}
if (LogFilter.logDev)
{
Debug.Log("NetworkServer ReplacePlayer");
}
if (conn.GetPlayerController(playerControllerId, out controller))
{
controller.unetView.SetNotLocalPlayer();
controller.unetView.ClearClientOwner();
}
PlayerController player = new PlayerController(playerGameObject, playerControllerId);
conn.SetPlayerController(player);
identity.SetConnectionToClient(conn, player.playerControllerId);
if (LogFilter.logDev)
{
Debug.Log("NetworkServer ReplacePlayer setup local");
}
if (!this.SetupLocalPlayerForConnection(conn, identity, player))
{
if (LogFilter.logDebug)
{
Debug.Log(string.Concat(new object[] { "Replacing playerGameObject object netId: ", playerGameObject.GetComponent<NetworkIdentity>().netId, " asset ID ", playerGameObject.GetComponent<NetworkIdentity>().assetId }));
}
FinishPlayerForConnection(conn, identity, playerGameObject);
if (identity.localPlayerAuthority)
{
identity.SetClientOwner(conn);
}
}
return true;
}