NetworkLobbyManager.FindSlot changed to int so it can return '-1' for 'not found', which is more obvious than Byte.MaxValue

This commit is contained in:
vis2k 2018-06-11 20:12:02 +02:00
parent 3ac3790ee7
commit 9de07af7c9

View File

@ -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<NetworkLobbyPlayer>();
newLobbyPlayer.slot = slot;
newLobbyPlayer.slot = (byte)slot;
lobbySlots[slot] = newLobbyPlayer;
NetworkServer.AddPlayerForConnection(conn, newLobbyGameObject, playerControllerId);