Skip to content

Commit

Permalink
Use a constant for max amount of players
Browse files Browse the repository at this point in the history
  • Loading branch information
toberge committed May 31, 2024
1 parent ce5c36d commit 9754e45
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Assets/Scripts/Control&Input/Peer2PeerTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class Peer2PeerTransport : NetworkManager

private static Dictionary<uint, PlayerDetails> players = new();
public static int NumPlayers => players.Count;
public const int MaxPlayers = 4;
public static IEnumerable<PlayerDetails> PlayerDetails => players.Values;

private static List<uint> localPlayerIds = new();
Expand Down Expand Up @@ -337,7 +338,7 @@ private void OnSpawnPlayerInput(NetworkConnectionToClient connection, PlayerConn
{
// Avoid adding more than the four allowed players
// TODO prevent this in some other more sustainable way :)))))
if (NumPlayers >= 4)
if (NumPlayers >= MaxPlayers)
return;

// Register connection
Expand Down Expand Up @@ -436,7 +437,7 @@ private void OnReceiveUpdatedPlayerDetails(UpdatedPlayerDetailsMessage message)

private void AddAiPlayers()
{
for (var i = players.Count; i < 4; i++)
for (var i = players.Count; i < MaxPlayers; i++)
{
var details = new PlayerDetails
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Utils/SteamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private void OnJoinRequest(GameLobbyJoinRequested_t callback)
{
// TODO verify that the lobby *should* be joined by more players!
// and verify that this is run on the server!
if (Peer2PeerTransport.NumPlayers >= 4 || Peer2PeerTransport.IsInMatch)
if (Peer2PeerTransport.NumPlayers >= Peer2PeerTransport.MaxPlayers || Peer2PeerTransport.IsInMatch)
return;
SteamMatchmaking.JoinLobby(callback.m_steamIDLobby);
}
Expand Down

0 comments on commit 9754e45

Please sign in to comment.