Trying to JoinRandomRoom for a LobbyType.SqlLobby, but it doesn't work.

Options
Here's my code, I'm not sure what I'm doing wrong:

Trying to join a room..
private void tryJoinRandomRoom()
{
    PhotonJoinedRoomSignal.AddListener(onJoinedRandomRoom);
    PhotonLeftRoomSignal.AddListener(onLeftRoom);
    PhotonRandomJoinFailedSignal.AddListener(onRandomJoinFailed);
    PhotonPlayerConnectedSignal.AddListener(onPlayerConnected);
    PhotonPlayerDisconnectedSignal.AddListener(onPlayerDisconnected);

    // more filter variations:
    // "C0 = 1 AND C2 > 50"
    // "C5 = \"Map2\" AND C2 > 10 AND C2 < 20"

    
    ExitGames.Client.Photon.Hashtable expectedProperties = new ExitGames.Client.Photon.Hashtable {
        { "Lobby", _dungeonConfig.Name }, // "3v3RandomJungle"
        { "C0", 10} };

    byte maxPlayers = (byte)_dungeonConfig.MaxPlayers;
    _lobby = new TypedLobby() { Name = _dungeonConfig.Name, Type = LobbyType.SqlLobby };
    string sqlFilter = "C0 >= 0 AND C0 < 50";

    PhotonNetwork.JoinRandomRoom(
        expectedProperties,
        maxPlayers,
        MatchmakingMode.SerialMatching,
        _lobby,
        sqlFilter);
}
Trying to join a room, on fail...
private void onRandomJoinFailed(object[] result)
{
    PhotonRandomJoinFailedSignal.RemoveListener(onRandomJoinFailed);
    PhotonCreatedRoomSignal.AddListener(onCreatedRoom);

    // more filter variations:
    // "C0 = 1 AND C2 > 50"
    // "C5 = \"Map2\" AND C2 > 10 AND C2 < 20"

    RoomOptions roomOptions = new RoomOptions();
    roomOptions.IsVisible = true;
    roomOptions.IsOpen = true;
    roomOptions.MaxPlayers = (byte)_dungeonConfig.MaxPlayers;
    roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable
    {
        { "Lobby", _dungeonConfig.Name },
        { "C0", 20 }
    };
    roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0", "Lobby" };
    roomOptions.PublishUserId = true;


    PhotonNetwork.CreateRoom(
        null,
        roomOptions,
        _lobby);
}
The problem is, every client doesn't think a room exists, so it creates a new one. I can understand the first client, but when more clients join, the room should exist right?

Here's the message I'm getting:

Operation failed: OperationResponse 225: ReturnCode: 32760 (No match found). Parameters: {}
UnityEngine.Debug:LogWarning(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1540)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:157)


Please help!

Comments

  • Bunzaga
    Bunzaga
    edited April 2017
    Options
    The idea is that the clients pass in their own values for 'C0', for example that could be an elo rating or something. In the first case, they pass in their own 'expected C0', which is 10. It should check if it is in the range of 0 to 50. If it isn't found, it creates a new room, with the C0 value of 20, which when the second client joins, that should fall in the range of 0 to 50... right?

    What am I doing wrong, or what am I not understanding?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2017
    Options
    Hi @Bunzaga,

    Thank you choosing Photon!

    Are you trying to random join from multiple clients at the same time? If the random join requests are sent in a small window they will all fail to find a match. This is a known issue for early stages of testing/development. Here are some tips on how to debug this:
    • Did you go through the "Matchmaking Checklist"?
    • In PUN 1.81 we added a way of getting a room list from SQL Lobby type: PhotonNetwork.GetCustomRoomList(sqlLobby, sqlLobbyFilter);. Try it to see if rooms are there. Or enable LobbStats and watch AppStats to see if rooms are being created in proper lobbies and WHEN.
    • Try changing the MatchmakingMode.
    • If nothing works, try not mixing normal custom properties ("Lobby") and SQL lobby properties ("C0"): remove "Lobby" as filter or replace "Lobby" with "CX" ("C1" or "C2", etc.).
  • Bunzaga
    Options
    I added a bunch of UI to show the lobby and networking stats, most of it seems inaccurate, but it gave me the idea to check my 'Hosting' settings for PUN. I originally had it set to 'Best Region', with only EU enabled. I thought that would force all to use EU.

    When I changed it to 'Photon Cloud', with EU selected, suddenly they can see each other now.

    It seems to me, that if I have Best Region selected, and I only have one server available, all devices should be forced to use that one region, but it seems this is not the case.

    After doing some digging, it looks like this is the cause: "Best region found in PlayerPrefs. Connecting to: usw"...

    So my PC was connecting to EU, meanwhile my phone was connecting to usw. Once I PlayerPrefs.DeleteKey("PUNCloudBestRegion") I reloaded the app, and now both devices are using EU.

    Just so you know, none of this data seems to be updating at all:
    public void Update()
    {
        if(Time.time > _nextTic)
        {
    		// I have it set to update every 1 second    
            _nextTic = Time.time + _statTicDuration;
    
            CountOfRooms.text = "Rooms: " + PhotonNetwork.countOfRooms.ToString();
            CountOfPlayersOnMaster.text = "Players On Master :" + PhotonNetwork.countOfPlayersOnMaster.ToString();
            CountOfPlayersInRooms.text = "Players In Rooms :" + PhotonNetwork.countOfPlayersInRooms.ToString();
            CountOfPlayers.text = "Players: " + PhotonNetwork.countOfPlayers.ToString();
    
            // delete the old data first
            LobbyInfo[] lobbyInfos = LobbyInfoParent.GetComponentsInChildren<LobbyInfo>();
    
            foreach (LobbyInfo lobbyInfo in lobbyInfos)
            {
                DestroyImmediate(lobbyInfo.gameObject);
            }
    
            // create new info panels for the new lobbys
            foreach (var info in PhotonNetwork.LobbyStatistics)
            {
                GameObject lobbyInfoGO = Instantiate(LobbyInfoElement, LobbyInfoParent, false);
                LobbyInfo lobbyInfo = lobbyInfoGO.GetComponent<LobbyInfo>();
                lobbyInfo.Name.text = info.Name;
                lobbyInfo.PlayerCount.text = "Player Count: " + info.PlayerCount.ToString();
                lobbyInfo.RoomCount.text = "Room Count: " + info.RoomCount.ToString();
            }
        }
    }
    I do have "Enable Lobby Stats" turned on. I waited several mins to see if anything would change, but it only seems to change on the initial connection to the lobby. Also, I'm getting 3 lobbies instead of just one, so there seems to be a lot of strange things going on.

    Good news is, I can now see other players in my Room :D
  • Bunzaga
    Options


    In this example, two clients joined the same lobby, and are in the same room. PhotonNetwork.countOfRooms, etc is on the left. Then for each lobby, the lobby info is on the right.

    Notice how there are three lobbies for some reason? The first one doesn't seem to have a name, and there are two named "3v3RandomJungle"... shouldn't there just be one single lobby with that name? The player count and room count for all of them is 0, yet we can clearly see by the network stats, there is some rooms and players...

    In any case, this doesn't really effect me, or what I'm doing, I just wanted to let you know it was happening, in case there was a bug or something. They don't seem to refresh at all, even if I register to listen for OnLobbyStatisticsUpdate. Is it because I'm no longer in the lobby, but I'm in a room, so I don't get the updates?
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2017
    Options
    Thank you for your reports.
    A Photon lobby is identified using two things: lobby name and lobby type. So maybe you should display the type as well.
    By default all apps have the default lobby: name is null, type is "Default".
    The stats events are sent by Master Server only so you need to be outside a room to receive them.
    AppStats is more frequent than LobbyStats.
  • Bunzaga
    Bunzaga
    edited April 2017
    Options
    Ahh ok, so it seems that it is all working as intended then :D

    I tried using PhotonNetwork.GetCustomRoomList(sqlLobby, sqlLobbyFilter); and in OnReceivedRoomListUpdate, I did PhotonNetwork.GetRoomList(), and often times this list of rooms didn't reflect what it should have been, based on the SQL String.

    For example, say a room has C0 set to 27, and my sql string was searching for 0 to 10. Sometimes GetRoomList() would contain the room with C0 set as 27, when it shouldn't have been.

    Other times, 27 should have fallen in the sql string range, but it would return a RoomList of Length 0.

    In any case, this wasn't reliable, so instead of getting a room list, I just try to join the room in that range, then on fail, I expand my sql search and retry. After 5 fails, I just create a room.

    This works, but of course it would be nice to just GetCustomRoomList, and not have to try joining a room each time. I would share my code, but I already deleted it...

    But basically, I would first call GetCustomRoomList, in OnReceivedRoomListUpdate, I would GetRoomList. If the roomList.Length > 0, that means it found a room, which fell into my sql search parameters, if it == 0, it means it couldn't find one, and I would just call GetCustomRoomList again, with an expanded sql string.