diff --git a/Unity-Technologies-networking/Runtime/NetworkLobbyManager.cs b/Unity-Technologies-networking/Runtime/NetworkLobbyManager.cs index ab0a6ba3a..5185b1e2e 100644 --- a/Unity-Technologies-networking/Runtime/NetworkLobbyManager.cs +++ b/Unity-Technologies-networking/Runtime/NetworkLobbyManager.cs @@ -68,10 +68,9 @@ void OnValidate() } } - Byte FindSlot() + int FindSlot() { - int index = Array.FindIndex(lobbySlots, sl => sl == null); - return index != -1 ? (byte)index : Byte.MaxValue; + return Array.FindIndex(lobbySlots, sl => sl == null); } void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject) @@ -287,8 +286,9 @@ public override void OnServerAddPlayer(NetworkConnection conn, short playerContr return; } - byte slot = FindSlot(); - if (slot == Byte.MaxValue) + // find empty slot and make sure that it's within byte range for packet + int slot = FindSlot(); + if (slot == -1 || slot > byte.MaxValue) { if (LogFilter.logWarn) { Debug.LogWarning("NetworkLobbyManager no space for more players"); } @@ -303,7 +303,7 @@ public override void OnServerAddPlayer(NetworkConnection conn, short playerContr } var newLobbyPlayer = newLobbyGameObject.GetComponent(); - newLobbyPlayer.slot = slot; + newLobbyPlayer.slot = (byte)slot; lobbySlots[slot] = newLobbyPlayer; NetworkServer.AddPlayerForConnection(conn, newLobbyGameObject, playerControllerId);