Retrieve Number of Room Members When Searching Rooms In MatchMaker

There is a way to add current number of room members to MatchMaker so that when other users find rooms via MatchMaker, they get to see the number of rooms.

Use MatchMaker's Add() function.

The forth argument of matching.Add() function is a map and you may add anything to the map.

This map will be returned to other users when they find match making results, so adding the number of room member in this map will allow other users to see how many users are in each room when they find rooms via MatchMaker.

Example code:

The following example code adds a room to MatchMaker for 60 seconds (maximum length) with the number of room members in a room.

matchingID := "find-room-matching"

conditions := make(map[string]int)

conditions["roomType"] = 1

data := make(map[string]interface{})

// add current number of users in the room

data["numberOfMembers"] = len(room.GetMemberIDs(roomID)) 

// TTL max is 60 seconds. If you want to keep the room avaialble for matching search for more than 60 seconds, you need to call matching.Add again.

ttl := int64(60)

// How fast you want the data to be distributed - recommanded value for this is 2

limit := 2

matching.Add(matchingID, roomID, conditions, data, ttl, limit)