Return ip address of dedicated server to users from MatchmakerMatchedFunction

Hi,

I’ve been trying to return the ip address of a dedicated server to matched users from MatchmakerMatchedFunction. I’ve tried to add it like this:

const onMatchmakerMatched : nkruntime.MatchmakerMatchedFunction = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, matches: nkruntime.MatchmakerResult[]): string | void
{
	// Create server instance at our hosting provider
	let serverAddress : string = createAuthoritativeGameServer(logger, nk);

	matches.forEach( match => 
	{
		match.properties["serverAddress"] = serverAddress;
		logger.info("match property: " + match.properties["serverAddress"]);
	});
}

The logging does log the correct address as expected, but the client doesn’t recieve the property when this event is triggered (in Unity):

private void OnMatchmakerMatched(IMatchmakerMatched matched)

I’ve noticed that when I set the properties earlier, it does work as expected:

const beforeMatchmakerAdd : nkruntime.RtBeforeHookFunction<nkruntime.EnvelopeMatchmakerAdd> = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, envelope: nkruntime.EnvelopeMatchmakerAdd) : nkruntime.EnvelopeMatchmakerAdd | void
{
	envelope.matchmakerAdd.stringProperties = {"serverAddress" : "Not yet set" };
	return envelope
}

But at this moment the address for the server is not known.

Is it possible to set properties from the MatchmakerMatchedFunction? If so, what am I doing wrong? Of not, how should I do this?

Thanks!

Hello @Maarten,

When the onMatchmakerMatched hook is called with functions from the TS or Lua runtimes, any changes to the match result properties won’t have any effect, only if they’re modified before they go into the pool (as in your before hook beforeMatchmakerAdd example).

If you need to include more properties from the clients, even if not used in the matchmaker queries, you can add them when submitting the tickets.

If you must send the IP from within onMatchmakerMatched, you can use a server notification.

Best

1 Like