How to search for a match with custom property of approximate value?

Hey!

I am trying to implement a matchmaking for my game.

I match people solely on matchmaking rating, thus I am wondering how do I set a custom property for a room in a hashtable if imagine the player has a rating of 1500, so he should be looking for rooms with custom properties of rating between 1450 and 1550 (+- 50 rating).

Any ideas on this matter?

Thanks!

Comments

  • Currently, I can set up a custom property of 1500 rating but not quite sure how to include all values between two certain rating points as custom property for a room.
  • Hey @Kaiserludi ,

    thanks for the documentation but currently I am utilizing another database solution found in Assetstore which works perfectly for me at this moment.

    My concern is how to make an array or list of integers that I fill up with foreach loop which says add up all integers from 1450 and 1550 for instance
  • @HeadlessFly.
    You can't do that.
    You need to use SQL-filters to tell Photons matchmaking to match against ranges instead of against singel values, period. There is just no other way in Photon to achieve what you attempt to do than using SQL-lobbies and SQL-filters.

    I also don't see how it would in any way be relevant if your are utilizing some database solution in your code.
  • @Kaiserludi

    Thanks for the prompt reply!

    The database I am using is solely for login authorization, storing account information such as matchmaking rating in this case.

    My idea is that I add a List of integers as a value of a 'MMR' key in a photon Hashtable. Is that possible?

    On the Net, I could find sources stating that a list can be a value of a key in a hashtable but when I try to run the code it gives me an exception that it cannot serialize.

    Let me show you what I do:

    public void MatchmakingClick () { List<int> intList = new List<int>(); for (int i = (int.Parse(loginAccounts.yourRating_Text.text) - 50); i <= (int.Parse(loginAccounts.yourRating_Text.text) + 50); i++) { intList.Add (i); } Debug.Log (intList); Hashtable expectedCustomRoomProperties = new Hashtable () { { "MMR", intList } }; PhotonNetwork.JoinRandomRoom (expectedCustomRoomProperties, 2); }

    However, I suspect that JoinRandomRoom function throws an exception that it cannot serialize the expectedCustomRoomProperties hashtable.

    Thanks!
  • Hi @HeadlessFly.

    You can only use those types with Photon out of the box that are supported by Photons serialization:
    https://doc.photonengine.com/en-us/pun/current/reference/serialization-in-photon

    For everything else you need to register it as a custom type and register your own serialize and deserialize implementations for it first, before you can use it with Photon, otherwise you get serialization errors.

    Instead of a list you could simply store and array as custom room property.



    However you are currently wasting your time by still approaching the topic in a way for which I have already told you that it is not supported by Photon and impossible to get to work, although I have pointed you at the ONLY supported approach on how to do what you want do do: SQL-filters.

    Yes, you could store an array as room property and you could also store a list if you register it as custom type, but that doesn't buy you anything in regards to range-based matchmaking.
  • HeadlessFly
    edited January 2018
    @Kaiserludi

    Thank you for the clarification!

    I thoroughly read the documentation you provided, and I am almost there to successfully implement it, however I have struck into an issue while doing so. I will be glad if you could help me.

    This is the way I JoinRandomRoom based on filter:
    public void MatchmakingClick () {
    
    		TypedLobby sqlLobby = new TypedLobby ("myLobby", LobbyType.SqlLobby);
    		string sqlFilter = "C0 > " + (int.Parse (loginAccounts.yourRating_Text.text) - 50) + " AND C0 < " + (int.Parse (loginAccounts.yourRating_Text.text) + 50);
    		PhotonNetwork.JoinRandomRoom (null, 2, MatchmakingMode.FillRoom, sqlLobby, sqlFilter, null);
    	}
    I know the sqlFilter, as shown in the documentation, is a string that is why I made it looks like (as an example): C0 > 1450 AND C0< 1550. It should be working but I am suspicious this is what it does not work in my code as I try to match two players of similar ELO but they do not get into the same room rather create a new one.

    This is how I create a room:
    
    public void CreateMatchmaking () {
    		RoomOptions roomOptions = new RoomOptions ();
    		roomOptions.MaxPlayers = 2;
    		roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable () { { "C0", loginAccounts.yourRating_Text.text } };
    		roomOptions.CustomRoomPropertiesForLobby = new string[] { "C0" };
    		TypedLobby sqlLobby = new TypedLobby ("myLobby", LobbyType.SqlLobby);
    		PhotonNetwork.CreateRoom (PhotonNetwork.playerName, roomOptions, sqlLobby);
    	}
    
    Any suggestions to why I cannot match two players? It must be something with the sqlFilter I assume so.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited January 2018
    Hi @HeadlessFly,

    Thank you for choosing Photon!


    It must be something with the sqlFilter I assume so.
    Not necessarily.
    1. Go through the "Matchmaking Checklist". Maybe you are trying to match two clients from two different regions or using different PUN versions...Check app stats to see if the players can see each other.
    2. Make sure to give enough time after starting the creation of the first room in the lobby before trying to randomly join it. If you try two random joins from two clients at almost the same time then they will not end up in the same room. Check lobby stats or app stats to make sure room is there before you try to join it.
    3. Log SQL filter string and check if it's correct. Also, log C0 value on creation.
  • @JohnTube

    Thank you for your answer!

    I checked if the two clients are on the same server, they are. Also, I double checked if they could see each other, by being able to manually create a room on one client and join it from the second client.

    I always make sure the first client to make the room through the matchmaking is in the room and the network state is Connected (connected again after creating the room), then I try to match but to no avail.

    Logging the sqlFIlter and also the C0 value on creation pops up exactly what it is supposed to:

    C0 > 1550 AND C0 < 1650
    and
    C0 = 1600

    One client is the creator of a room (since no rooms are matching the criteria) and he got Rating of 1600. The second client is the one who is supposed to find the room of the first client because his filter would be C0 > 1501 AND C0 < 1601 (the mmr of the second client is 1551.

    Still to no avail. They both create rooms but no one joins.