When client leaves room they cannot join or create a new room

Options
The game will start and everyone connects to photon without an issue. Any user can create or join a room. However the user that creates the room is free to join or create another room after leaving the first room. The client that joins the room is unable to create or join a room after leaving the first one.

This error is shown: CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.

I have tried completely disconnecting the user from photon and reconnecting but it just seems to hang at various stages.

If I completely disconnect PhotonNetwork.connectionStateDetailed Shows ConnectingToNameServer

If I just let the player try to join another room without disconnecting I get ConnectingToMasterserver

Any thoughts on what I am doing wrong?

Here is my matchmaking code:
public void TryToFindMatch(string matchType)
    {
        bool matchFound = false;
        foreach (RoomInfo game in PhotonNetwork.GetRoomList())
        {


            if (game.CustomProperties.ContainsValue(matchType))
            {
                
                if (game.CustomProperties.ContainsValue("HasNotStarted"))
                {
                    if (game.PlayerCount < 8)
                    {
                        if (game.IsOpen)
                        {
                            Debug.Log("FOUND AVAILABLE ROOM: " + game.Name);
                            matchFound = true;
                            PhotonNetwork.JoinRoom(game.Name);
                            break;
                        }
                      
                    }
                }

            }
        }

        if (matchFound == false)
        {
            Debug.Log("NO GAME FOUND. CREATING... ");

            
            
            RoomOptions roomOptions = new RoomOptions();
            roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
            roomOptions.MaxPlayers = 8;
            roomOptions.CustomRoomProperties.Add("GameType", gameType);
            roomOptions.CustomRoomProperties.Add("HasStarted", "HasNotStarted");
            roomOptions.CustomRoomPropertiesForLobby = new string[2] { "GameType", "HasStarted" };
         
            roomOptions.CleanupCacheOnLeave = false;
     
            PhotonNetwork.CreateRoom(null, roomOptions, TypedLobby.Default);
            
        }
    }

Comments

  • Tobias
    Options
    Please, don't fetch the room list to then join some random room.
    Have a look at JoinRandomRoom.
    The component ConnectAndJoinRandom will get you in a room and you can copy it into your own class to modify it (max players, etc).