[PUN2] OnRoomListUpdated() returning an empty list of RoomInfo

Hi there,

I'm trying to setup a lobby system with rooms in Unity 2019.3.7f1 using PUN 2.19 Lib 4.1.4.3 and have followed the tutorials to connect to master server n lobby. I can join servers and start games just fine. However when I try and access the Room List, OnRoomListUpdate returns an empty List.

I can verify through debug that the lobby has a room created. And PhotonNetwork.CountOfRooms is > 0. The room property is also set as visible.

My Photon server settings is set to dev region does this affect anything? I would like to be able to display the room list to users.

Cheers,
Benjamin

Comments

  • You need to join the lobby and stay connected to it. There is no room listing while being in a room.
    I would suggest you start with using only the default lobby. To do so, use null as parameter wherever a TypedLobby value is expected.

    The Asteroids Demo shows a room list. Have a look at that as blueprint.
  • Yes I am aware that there are no room list updates while I am in a room. My test code is similar to the asteroids demo in terms of flow.

    if you join a lobby you don't disconnect from it unless you join a room do you?

    My test case is this:
    1. Make a build.
    2. Launch the executable
    3. Join the master server on the executable (Players: 1 Rooms: 0 as expected)
    4. Press Join Lobby and process RoomListUpdate() (Empty list as expected)
    5. create/join a room with name '1234' (No updates as expected)

    6. Launch in editor
    7. Join master server on the executable (Players: 2 Players in Rooms: 1 Players not in Rooms: 1 Rooms: 1)
    8. Join Lobby and process RoomListUpdate() (Empty list - this is unexpected. There should be 1 room in the list)
  • In the above case my editor is not in a room but is in the lobby it should have a RoomListUpdate with 1 RoomInfo with the Room name being '1234'. The room was created as visible.
  • I am also aware the Asteroids Demo works. I'm trying to figure out the differences between what I created and what the asteroids demo does. So far it only seems to store the full RoomList info but that shouldn't matter because OnRoomListUpdated should return a list of RoomInfos regardless?
  • benjamin_bbrew
    edited June 2020
    relevant Image roomlistbug.png
    jpg image hosting
  • Source code relevant:

    public class NetworkManager : MonoBehaviourPunCallbacks
    {
    [Header("Version Settings")]
    public string gameVersion = "1";

    public MPState m_MPState = MPState.OFFLINE;

    public void Login(string playerName)
    {
    PhotonNetwork.LocalPlayer.NickName = playerName;

    ConnectToMasterServer();
    }

    void ConnectToMasterServer()
    {
    PhotonNetwork.GameVersion = gameVersion;
    //PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = gameVersion;
    PhotonNetwork.ConnectUsingSettings();
    }


    public override void OnConnectedToMaster()
    {
    Debug.Log("Connected to Server!");
    m_MPState = MPState.CONNECTEDMASTERSERVER;
    }

    public void DisconnectFromServer()
    {
    PhotonNetwork.Disconnect();
    m_MPState = MPState.OFFLINE;
    }

    public override void OnDisconnected(DisconnectCause cause)
    {
    Debug.Log("Disconnected from Server! Reason: " + cause);
    }

    public void JoinLobby()
    {
    PhotonNetwork.JoinLobby();
    }

    public override void OnJoinedLobby()
    {
    Debug.Log("Joined Lobby!");
    m_MPState = MPState.LOBBY;
    }

    public void CreateOrJoinRoom(string roomName)
    {
    Debug.Log("Trying to Create/Join Room " + roomName);
    RoomOptions roomOptions = new RoomOptions();
    roomOptions.MaxPlayers = (byte)6;
    roomOptions.IsVisible = true;
    roomOptions.IsOpen = true;
    TypedLobby typedLobby = new TypedLobby(roomName, LobbyType.Default);
    PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, typedLobby);
    }

    public override void OnJoinedRoom()
    {
    m_MPState = MPState.ROOM;
    }

    private List<string> m_RoomNames = new List<string>();
    public override void OnRoomListUpdate(List<RoomInfo> roomList)
    {
    Debug.Log("Room List Updated. Size: " + roomList.Count);
    m_RoomNames.Clear();

    foreach (RoomInfo ri in roomList)
    {
    m_RoomNames.Add(ri.Name);
    }
    }

    private void OnGUI()
    {
    float offsetY = 100;
    Rect displayRect = new Rect(100, offsetY, 1000, 100);

    GUI.Label(displayRect, "DEBUG: PhotonSettings App Version: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion);

    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "PhotonNetwork: " + PhotonNetwork.AppVersion);

    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "Player User ID: " + PhotonNetwork.LocalPlayer.UserId);

    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "MATCHMAKINGSTATE: " + m_MPState.ToString());
    switch (m_MPState)
    {
    case MPState.ROOM:
    if (PhotonNetwork.CurrentRoom != null)
    {
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "ROOM NAME: " + PhotonNetwork.CurrentRoom.Name);

    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "PlayerCount: " + PhotonNetwork.CurrentRoom.PlayerCount);

    int i = 0;
    foreach (KeyValuePair<int, Photon.Realtime.Player> keypair in PhotonNetwork.CurrentRoom.Players)
    {
    Player p = keypair.Value;
    if (p != null)
    {
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "P" + i + ": " + p.NickName);
    i++;
    }
    else
    {
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "NULL");
    }
    }
    /*for(int i = 1; i <= PhotonNetwork.CurrentRoom.PlayerCount; ++i) //photon player key starts from 1..
    {
    Player p = null;
    PhotonNetwork.CurrentRoom.Players.TryGetValue(i, out p);
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "P" + i + ": " + p.NickName);
    }*/
    }

    break;
    }


    offsetY += 40;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "PLAYERS NOT IN ROOMS: " + PhotonNetwork.CountOfPlayersOnMaster);
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "PLAYERS IN ROOMS: " + PhotonNetwork.CountOfPlayersInRooms);
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "PLAYERS TOTAL: " + PhotonNetwork.CountOfPlayers);
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "EXISTING ROOMS: " + PhotonNetwork.CountOfRooms);

    if (m_RoomNames.Count == 0)
    {
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, "NONE");
    }

    foreach (string roomName in m_RoomNames)
    {
    offsetY += 20;
    displayRect = new Rect(100, offsetY, 1000, 100);
    GUI.Label(displayRect, roomName);
    }
    }
    }
  • benjamin_bbrew
    edited June 2020
    Tobias wrote: »
    You need to join the lobby and stay connected to it. There is no room listing while being in a room.
    I would suggest you start with using only the default lobby. To do so, use null as parameter wherever a TypedLobby value is expected.

    Hello tobias,

    I found the problem.. which I believe is a small bug on the side of the provided API code or some misunderstanding on my part.

    The difference between getting the room to show up in the RoomListUpdate list is the the LobbyType as you stated before. However I do not understand why theres a difference in behavior when null is passed as an argument instead of TypedLobby.Default.

    This line in JoinOrCreateRoom seems to be the cause of the issue? Why would the argument difference cause the lobby to be wrong?
    typedLobby = typedLobby ?? ((NetworkingClient.InLobby) ? NetworkingClient.CurrentLobby : null); // use given lobby, or active lobby (if any active) or none
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @benjamin_bbrew,

    Thank you for choosing Photon!

    from documentation
    When a client is joined to a lobby and tries to create (or JoinOrCreate) a room without explicitly setting a lobby, if the creation succeeds/happens, the room will be added to the currently joined lobby. When a client is not joined to a lobby and tries to create (or JoinOrCreate) a room without explicitly setting a lobby, if the creation succeeds/happens, the room will be added to the default lobby. When a client is joined to a lobby and tries to creates (or JoinOrCreate) a room by explicitly setting a lobby, if the creation succeeds/happens:

    - if the lobby name is null or empty: the room will be added to the currently joined lobby. This means you cannot create rooms in the default lobby when you are joined to a custom/different one.
    - if the lobby name is not null nor empty: the room will be added to the lobby specified by the room creation request.
    The Default Lobby
    It has a null name and its type is Default Lobby Type. In C# SDKs, it's defined in TypedLobby.Default. The default lobby's name is reserved: only the default lobby can have a null name, all other lobbies need to have a name string that is not null nor empty. If you use a string empty or null as a lobby name it will point to the default lobby no matter the type specified.

  • Ahh okay, thanks for the clarification