As for your second question: Yes. I think you are on the right track. Basically, you handle the match rewards, xp gains, rank gains, etc. in your match handler; Then you can add these levelups to your player stats. The best place is metadata as the name suggests, but cannot see a reason why you cannot store it in storage or even wallet (if you are too caring about user privacy ).
For your first question, I think you can use Nakama Mathcmaker for that:
const query = "+properties.region:europe +properties.rank:>=5 +properties.rank:<=10";
const minCount = 2;
const maxCount = 4;
const stringProperties = {
region: "europe"
};
const numericProperties = {
rank: 8
};
var ticket = await socket.addMatchmaker(query, minCount, maxCount, stringProperties, numericProperties);
use this example as it simply, and I quote, “searches for opponents that must be in europe
and must have a rank
between 5 and 10, inclusive”.
Now the only remaining thing is trusting the player and the possibility of him/her lying about his rank, MMR, etc. Suppose this function is hooked to handle matchmaking requests using initializer.RegisterMatchmakingMatched
:
func doMatchmaking(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, entries []runtime.MatchmakerEntry) (string, error) {
for i, e := range entries {
// fetch user metadata for entries[i].GetPresence()
// check if the actual rank or MMR matches what he/she provided in the query
for k, v := range e.GetProperties() {
logger.Info("Matched on '%s' value '%v'", k, v)
// return nil if a presence has not been honest with his "rank" property, e.g.
}
}
matchId, err := nk.MatchCreate(... params passed to match create)
if err != nil {
return "", err
}
return matchId, nil
}