Lobby with specified positions

Hello everyone,
I’m trying to use Lobby in a certain way but I’m having lot of problems so maybe I’m doing it wrong, so I want to hear your opinions:

  • I want the host to create a lobby and invite other players, my game needs 4 players to start to be played 2 v 2, and there is possibility to join lobby to spectate
  • so in lobby I have player data as follow :
{
    isSpectator : Boolean,
    position: Integer
}
  • position is used to define the teams, (0, 1) vs (2, 3)
  • the host is always in position 0
  • when a player joins the lobby, he joins with isSpectator = true, so it doesn’t have a position, when he joins successfully, he parses the players in lobby and check position, then if a position from {1, 2, 3} is available, he updates his data and set his position to the available one, otherwise he stays as spectator

the problem I’m facing is, it happens that all players join at same time so they got same free position, and they all take it, which causes problem …
So I’m not sure if I’m on good path or there is a better way, can you please share your thoughts
thank you in advance :pray:

Sounds like you allow clients to pick the position by themselves. So two players joining at the same time will have the same “three players already joined” list and thus they put themselves in fourth place.

This needs to be handled by the server (host) in such a way that the server assigns each connecting client a given ID. There will never be a case where a client joined event runs simultaneously for the lobby host. Have the host subscribe to the Lobby “changed” event and handle player join/leave accordingly.

Clients should only be allowed to modify personalization data, such as their names, spectator mode, the avatar choice or the “ready” state, but nothing that may be in conflict with other players (eg the game mode to play, the difficulty, their start position, the Avatar choice in a game where Avatars are mutually exclusive ie no two players can play the same Avatar).

1 Like

Oh I see, that’s will make my life easier :man_facepalming: ! thank you so much for clarification :pray: