[Photon PUN] How can I organize lobbies?

As far as I understand, Photon's logic is like this:
- The client connects to the master server
- The client joins to a lobby
- The client can see the rooms in that lobby

I have 2 different game modes in my game. A client can only see the rooms in the lobby they're in. I would like to organize players depending on the game mode they select. For example; Client 1 wants to play Game Mode A and Client 2 wants to play Game Mode B. In this example; there should be 2 lobbies. Client 1 joins to Lobby X, Client 2 joins to Lobby Y. So, they don't see each others in the room list. How can I do that?

The "Lobbies" doc page should help here.
In general, you are right. Make up two lobbies (different names) and whenever a room gets created, pass the relevant lobby, so it gets associated with it.
We usually don't recommend to join a lobby (and list rooms) as players tend to not really select a room for a good reason but for being in the top 5 results or so. The ping is the same in all cases...

1 Like

Basically, the code should be like this?

    TypedLobby freeAllLobby = new TypedLobby("FreeAll", LobbyType.Default);
    TypedLobby teamDMLobby = new TypedLobby("TeamDM", LobbyType.Default);

    public void CreateRoom_FreeAll()
    {
        // ... Set the room options

        PhotonNetwork.CreateRoom(nickname, roomOptions, freeAllLobby);
    }

    public override void OnConnectedToMaster()
    {
        switch (gameMode)
        {
            switch EGameMode.FreeAll:
                PhotonNetwork.JoinLobby(freeAllLobby);
                break;
            switch EGameMode.TeamDM:
                PhotonNetwork.JoinLobby(teamDMLobby);
                break;
            default:
                break;
        }
    }

I also heard that there's a player limit for every lobby. There can't be more than 16 players in a lobby. Is that true? If so, what would happen in the code above if the 17th player wants to connect to the same lobby?

2 Likes

Yes, the code may look like that.
In Photon matchmaking, Lobbies are lists of rooms, used to find a suitable room to join. Players have no impact on those lobbies, so there is no such limit.
In rooms, there is a player limit, correct. This is due to PUN 2's approach to syncing the networked objects. The more players there are, the more traffic this causes and at some point you'd run into performance problems.
You have to set the MaxPlayers value in the RoomOptions to <= 16.
If this cap needs to be lifted, mail us: developer@photonengine.com. It's possible but we'd like to greenlight the usage, knowing a little about the case.

1 Like