Players in pool not getting matched by matchmaker

As the title says, I am having trouble getting people in a pool matched together. They just show up as separate tickets but the match requirements (query, min/max players) never get fulfilled.

Frontend code

const ticket: MatchmakerTicket = await socket.addMatchmaker("*", 2, 2);
console.log(ticket);

socket.onmatchmakermatched = (matched) => {
  console.info("Received MatchmakerMatched message: ", matched);
  console.info("Matched opponents: ", matched.users);
};

Backend code

export const matchmakerMatched = (
  _context: nkruntime.Context,
  logger: nkruntime.Logger,
  nk: nkruntime.Nakama,
  matches: nkruntime.MatchmakerResult[]
): string => {
  logger.info("Match is Made");

  matches.forEach(function (match) {
    logger.info("Matched user '%s' named '%s'", match.presence.userId, match.presence.username);

    Object.keys(match.properties).forEach(function (key) {
      logger.info("Matched on '%s' value '%v'", key, match.properties[key]);
    });
  });

  try {
    const matchId = nk.matchCreate("standard", { invited: matches });
    logger.debug(matchId);
    return matchId;
  } catch (error) {
    throw logError(error, logger);
  }
};

Init

initializer.registerMatchmakerMatched(matchmakerMatched);


Logs of 3 clients trying to get matched. The ticket gets shown in console.log() as per the frontend code


Nothing is happening after this.
matchmaker.interval_sec is set to 15 but even after waiting that long it stays quiet.

So on both the frontend (socket) as the backend (hook) the matchmaking doesn’t get triggered. I also tried them separately but without success.

Any clue? Thanks in advance :pray:

1 Like

@nick Can you also share the client SDK and server versions? Also make sure you register socket.onmatchmakermatched hooks before submitting your tickets.

Side note - screenshots of code or logs are not ideal. Use text where possible so we can copy/paste or alter for responses.

Thanks for your response.

Client SDK: @heroiclabs/nakama-js 2.4.1
Server version: 3.9.0+6f4c456b

And I also tried registering the socket before submitting the ticket, but that’s not changing anything sadly. Also tried an empty query string as I saw in an example in the docs.

And sure, I will paste the code next time :+1:

BTW, is there a way to debug the matchmaking pool? To see how many people are there with what kind of query etc.

Weird thing is, that even when I try to log socket.onmatchmakerticket, it isn’t firing when a ticket is generated.

Code

socket.onmatchmakermatched = async (matchmakerMatched) => {
  console.log("matched");
  console.log(matchmakerMatched);
};

socket.onmatchmakerticket = async (matchTicket) => {
  console.log("onmatchmakerticket");
  console.log(matchTicket);
};

console.log(socket);

const query = "*";
const minPlayers = 2;
const maxPlayers = 2;

const matchmakingTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);

console.log(matchmakingTicket);

Console output

Screenshot 2022-10-05 at 10.32.08

So it seems like it is not registering that a ticket has been created.
The backend log doesn’t show any error:

[backend] {"level":"debug","ts":"2022-10-05T08:30:47.746Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"b024ef99-0268-47c8-89fe-3e5e640fbf2e","sid":"01ab35cf-4488-11ed-ad69-006100a0eb06","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T08:30:47.748Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"b024ef99-0268-47c8-89fe-3e5e640fbf2e","sid":"01ab35cf-4488-11ed-ad69-006100a0eb06","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"943e12d1-5769-4667-9029-772f7c7e0071\"}"}

Last thing worth mentioning (not sure if matters) is that the cid (is that the Client ID?) stays at 1, even when I am creating a ticket from another client.

Playing around with it more, and even if I trigger 3 tickets (matchmaker.max_tickets) from the same client, it gets registered with the correct amount of cids, but still nothing gets triggered in the console, and the registered MatchmakerMatched isn’t called either.

Code

socket.onmatchmakermatched = async (matchmakerMatched) => {
  console.log("matched");
  console.log(matchmakerMatched);
};

socket.onmatchmakerticket = async (matchTicket) => {
  console.log("onmatchmakerticket");
  console.log(matchTicket);
};

const query = "*";
const minPlayers = 2;
const maxPlayers = 2;

const ticket1: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);
const ticket2: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);
const ticket3: MatchmakerTicket = await socket.addMatchmaker(query, minPlayers, maxPlayers);

Logs

[backend] {"level":"debug","ts":"2022-10-05T11:12:54.658Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"1","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.663Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"1\" matchmaker_ticket:{ticket:\"d69cabe6-d7fb-4f29-9cb8-40f29f607936\"}"}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.668Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"2","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.672Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"2\" matchmaker_ticket:{ticket:\"1c462799-3e1d-49ad-b6bb-10fd4342f666\"}"}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.676Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchmakerAdd message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","cid":"3","message":{"MatchmakerAdd":{"min_count":2,"max_count":2,"query":"*"}}}
[backend] {"level":"debug","ts":"2022-10-05T11:12:54.679Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_MatchmakerTicket message","uid":"cd47fea7-c29f-4980-a763-ea905be60309","sid":"9ee2861b-449e-11ed-951b-006100a0eb06","envelope":"cid:\"3\" matchmaker_ticket:{ticket:\"bad368be-0325-401f-9591-b0a8acee2972\"}"}

@nick Start by updating to Nakama 3.13.1 and try again, we can debug further once you’re on the most recent version with all known bugfixes applied. :sunglasses:

@zyro But 2.4.1 is the latest release?

Nakama is the server, nakama-js is your client library. Your server is 3.9.0 per your own post a bit above. Update that to 3.13.1.

1 Like

@zyro well I guess that worked :sweat_smile: Thanks!

Unrelated question, is there a Nakama go-to way for a situation where users that get a matchmaking ticket are joining either a game with default settings or a game with predefined settings created by one of the users?

That sounds like a new topic, please start a new thread and give as much detail as you can about your use case. :+1:

1 Like