Room is still visible when it should not

Options
Pier
Pier
Hi everyone,

First of all I would like to thank the whole Exitgames team for this wonderful and powerful Unity plugin which is PUN.

We are however stuck on an issue we cannot find a solution of:
A room that has been set NotVisible is still retrieved by other players inside the lobby.

This is our code:

1. Masterclient set the room IsVisible = false when max number of players is reached:
if(PhotonNetwork.playerList.Count() == PhotonNetwork.room.MaxPlayers)
{
        if (PhotonNetwork.player.IsMasterClient == false)
        return;
	PhotonNetwork.room.IsOpen = false;
        PhotonNetwork.room.IsVisible = false;
}
2. Player in lobby press the refresh button, clear all the rooms UI and repopulate it:
public void OnRoomListRefresh()
{
	// Clear the List
	clearRoomsList ();

	// Populate Room List
	populateRoomsList();	
}

void clearRoomsList()
{
	foreach (Transform child in g_oRoomsListPanel.transform)
	{
		Destroy(child.gameObject);
	}
}

// Populate the available rooms list
void populateRoomsList()
{
	foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList ())
	{
		if(roomInfo.IsVisible == true)
		{
			addRoomInfo(roomInfo);
		}
	}
}
The problem is that the room, which has been set not visible by the masterclient is still added inside the UI rooms list.
Furthermore, when I print the roominfo.playercount of that particular room, it shows me one player less.
(Eg. inside the room there are 2 players, however inside lobby it tells me there is only 1)

Any idea of what it could be the issue here?
Inside the game room.IsVisible is definitely false as I am printing it on the console.

Kind regards,
Pier

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited September 2017
    Options
    Hi @Pier,

    Thank you for choosing Photon and for your kind words.

    This is probably due to the frequency of rooms list updates events.
    While PUN updates rooms list in the background for you automatically when it receives new list from server, this may not happen as often as you think.
    The update can be logged using a special callback (OnReceivedRoomListUpdate), so you should replace button refresh logic with:
    private void OnReceivedRoomListUpdate() 
    {
             Debug.Log("OnReceivedRoomListUpdate");
             OnRoomListRefresh();
    }	
  • Pier
    Options
    Thanks John for your prompt reply.

    I have tried your suggestion however the outcome is the same as using our current logic (refresh button).

    What I have noticed is that the call back "OnReceivedRoomListUpdate" is not triggered when a room reaches maximum capacity and therefore is closed (PhotonNetwork.room.IsOpen = false; PhotonNetwork.room.IsVisible = false;) by masterclient.

    To test the logic, I created a room with max capacity of 4 players and used my laptop to print Debug.Log("OnReceivedRoomListUpdate");

    When the room is created, there is the first callback.
    A second player joins this room and the callback is fired again.
    Same with the third player; "OnReceivedRoomListUpdate" is fired as expected.
    However, when the fourth and last player joins the room and therefore room is closed by masterclient because room has reached max capacity and game is about to start, OnReceivedRoomListUpdate() is NOT fired and the room is still listed in lobby showing 3/4 players.
    And of course if a fifth player presses the join button on that particular room, PUN fires an error saying that the room has been closed.

    Thanks in advance for your time and support.

    Kind Regards,
    Pier
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited September 2017
    Options
    Hi @Pier I could not reproduce this issue.
    Can you give us repro project, video, gif, screenshots or logs?
  • Pier
    Options
    Dear John, I have finally SOLVED the issue!

    As I am connecting to a LobbyType.SqlLobby, what I needed was to add this check before calling GetRoomList():

    if(PhotonNetwork.GetCustomRoomList(m_oSqlLobby, m_sSqlLobbyFilter) == false)
    return;

    foreach( RoomInfo room in PhotonNetwork.GetRoomList() )
    {
    if(room.IsOpen == true)
    {
    addRoomInfo(room);
    }
    }

    Now the closed room is finally NOT displayed inside the lobby.

    I take this opportunity to wish you and the whole Exitgames team and community all the very best.
    Keep up the amazing job you are doing!

    Regards,
    Pier