Matchmaking Around Blocked Users

Nakama’s matchmaker can be used to bring users together for any type of social gameplay or interaction available in your application. As with any community, some users will get along and some will not.

When a user has blocked another, ideally these two users should not be placed in the same match, group, or other such social feature by the matchmaker.

This guide provides one approach you can use to ensure no user is matched with someone they have blocked. This involves:

  • Looking up each user’s list of blocked users
  • Using that list as part of their respective matchmaker properties
  • Adding a clause to their matchmaker query to avoid matching blocked users

Listing blocked users #

Use the Friends Listing API, filtering only users in a blocked state, to get a complete list of all users this player has blocked.

You need to write the complete list of blocked user IDs into a space-separated string (e.g. user-id-1 user-id-2 user-id-3) that will be part of the user’s matchmaker properties.

Matchmaker criteria #

Each user’s matchmaker criteria will now include an additional property, using the key blocked, of the concatenated string of blocked users created above.

Along with the new property, each user’s matchmaker query will also have a new must not clause in the form -properties.blocked:/.*my\-user\-id.*/.

By using the player’s own ID, this clause ensure that the searching player does not appear in the blocked list of any potential match - i.e. that this player is not matched with any player that has blocked them and, ultimately, no player is matched with anyone they have blocked.

The complete matchmaker request would look like: