Skip to content

Commit

Permalink
Simplify AddPlayerForConnection (#62)
Browse files Browse the repository at this point in the history
* Simplify AddPlayerForConnection

BREAKING CHANGE: AddPlayerForConnection no longer receives the client

* fix compilatio errors

* fix build errors
  • Loading branch information
paulpach committed Feb 12, 2020
1 parent 7436164 commit fb26755
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Assets/Mirror/Components/NetworkRoomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public override void OnServerAddPlayer(NetworkConnection conn)
if (newRoomGameObject == null)
newRoomGameObject = Instantiate(roomPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);

server.AddPlayerForConnection(conn, client, newRoomGameObject);
server.AddPlayerForConnection(conn, newRoomGameObject);
}
else
OnRoomServerAddPlayer(conn);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void OnCreatePlayer(NetworkConnection connection, CreatePlayerMessage cr
playergo.GetComponent<Player>().playerName = createPlayerMessage.name;

// set it as the player
server.AddPlayerForConnection(connection, client, playergo);
server.AddPlayerForConnection(connection, playergo);

chatWindow.gameObject.SetActive(true);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/Pong/Scripts/NetworkManagerPong.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void OnServerAddPlayer(NetworkConnection conn)
// add player at correct spawn position
Transform start = numPlayers == 0 ? leftRacketSpawn : rightRacketSpawn;
GameObject player = Instantiate(playerPrefab, start.position, start.rotation);
server.AddPlayerForConnection(conn, client, player);
server.AddPlayerForConnection(conn, player);

// spawn ball if two players
if (numPlayers == 2)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ public virtual void OnServerAddPlayer(NetworkConnection conn)
? Instantiate(playerPrefab, startPos.position, startPos.rotation)
: Instantiate(playerPrefab);

server.AddPlayerForConnection(conn, client, player);
server.AddPlayerForConnection(conn, player);
}

/// <summary>
Expand Down
9 changes: 4 additions & 5 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,13 @@ public bool ReplacePlayerForConnection(NetworkConnection conn, NetworkClient cli
/// <param name="player">Player object spawned for the player.</param>
/// <param name="assetId"></param>
/// <returns></returns>
public bool AddPlayerForConnection(NetworkConnection conn, NetworkClient client, GameObject player, Guid assetId)
public bool AddPlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId)
{
if (GetNetworkIdentity(player, out NetworkIdentity identity))
{
identity.assetId = assetId;
}
return AddPlayerForConnection(conn, client, player);
return AddPlayerForConnection(conn, player);
}

void SpawnObserversForConnection(NetworkConnection conn)
Expand Down Expand Up @@ -675,7 +675,7 @@ void SpawnObserversForConnection(NetworkConnection conn)
/// <param name="client">Client associated to the player.</param>
/// <param name="player">Player object spawned for the player.</param>
/// <returns></returns>
public bool AddPlayerForConnection(NetworkConnection conn, NetworkClient client, GameObject player)
public bool AddPlayerForConnection(NetworkConnection conn, GameObject player)
{
NetworkIdentity identity = player.GetComponent<NetworkIdentity>();
if (identity == null)
Expand All @@ -699,8 +699,7 @@ public bool AddPlayerForConnection(NetworkConnection conn, NetworkClient client,
// set server to the NetworkIdentity
identity.server = this;

// set client to the NetworkIdentity
identity.client = client;
identity.client = this.localClient;

// Set the connection on the NetworkIdentity on the server, NetworkIdentity.SetLocalPlayer is not called on the server (it is on clients)
identity.SetClientOwner(conn);
Expand Down

0 comments on commit fb26755

Please sign in to comment.