Custom Room Properties - What am I Doing Wrong?

I'm sorry because I know this has been asked before, and I followed the docs AND read the answers and I still can't get room properties working. (tried this: https://doc.photonengine.com/en-us/server/v4/applications/loadbalancing/matchmaking-and-lobby)

My simple case is that I want every room to have a custom bracket property "brkt" (int), and players need to supply their bracket to see if it matches, if it doesn't they should create their own. 2 player games only.

private string bracketCustomPropertiesString = "brkt";
public int bracket=1;

// try to join random room with property : { "brkt"==1}
void MyJoinRandomRoom()
{
	Photon.Realtime.RoomOptions roomOptions = new Photon.Realtime.RoomOptions();
	roomOptions.MaxPlayers = 2;
	roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable();
	roomOptions.CustomRoomProperties.Add(bracketCustomPropertiesString, bracket);
	PhotonNetwork.JoinRandomRoom(roomOptions.CustomRoomProperties, 2);
}

// Create random room with property : { "brkt"==1}
void OnJoinRandomFailed(short returnCode, string message)
{
	Photon.Realtime.RoomOptions roomOptions = new Photon.Realtime.RoomOptions();
	roomOptions.MaxPlayers = 2;
	roomOptions.CustomRoomPropertiesForLobby = new string[1] {bracketCustomPropertiesString };
	roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable(1) {{bracketCustomPropertiesString , bracket}};
	PhotonNetwork.CreateRoom(null, roomOptions, Photon.Realtime.TypedLobby.Default);
}

What is happening right now is that if I create the room with the custom properties, it seems anyone can join with PhotonNetwork.JoinRandomRoom(). BUT, if someone creates a room WITHOUT custom properties, I can't join it if I try to join with properties. (That was the test I tried when I was joining when I thought I shouldn't have).

EDIT: Now I tried joining the room with players having different brackets and they all join eachother, regardless of "brkt" value. Also added roomOptions.isVisible=true; and didn't help.

Thanks in advance!

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited March 2019
    Hi @Breeman,

    1. (not really related to your question/issue) Code optimization:
    void MyJoinRandomRoom()
    {
    	ExitGames.Client.Photon.Hashtable filter = new ExitGames.Client.Photon.Hashtable(1);
    	filter.Add(bracketCustomPropertiesString, bracket);
    	PhotonNetwork.JoinRandomRoom(filter, 2);
    }
    2. Make sure you wait until the room is created before calling join random, you can do so by joining the default lobby and receiving room list updates OR using application stats or lobby stats. You are probably testing using two clients and don't give the servers enough time to finish creating the room.
    3. If you are not connecting to self-hosted Photon Server, the proper documentation page link for PUN is https://doc.photonengine.com/en-us/pun/current/lobby-and-matchmaking/matchmaking-and-lobby
  • Breeman
    Breeman
    edited March 2019
    @JohnTube

    Thanks for the optimization! I actually went through a few iterations, and this was a copy/page hacky way of getting the hashtable, it made things more complicated to look at than it actually was.

    After your confirmation that everything looked correct, I went back and looked at the way I was setting "bracket", and that was the problem. In the end it was ME doing something wrong (like I thought it would be). Everything is working now, thanks SO much for taking the time to help, and sorry for wasting your time!