Go runtime, nk.matchList for non-authoritative matches

Hi, I’m trying to build Go runtime module to register RPCs and query non-authoritative matches.
The problem is that nk.MatchList cannot skip label and query parameters. And these two are not supported for non-authoritative matches, according to API explorer.
I tried to pass empty string “” but it didn’t work, and nil cannot be assigned to string type. Is there a walkaround for this?

Setting label and query as empty strings "" ignores those fields and should give you non-authoritative matches as long as you set the authoritative parameter to false.

1 Like

Hey @sesposito thank you for your reply!

Right, I’ve also read the source code and the function checks against empty strings. However, I wasn’t able to list matches in my runtime module.

Here’s the RPC I have:

type RPCMatchPayload struct {
	GameTag       string `json:"GameTag"`
	MaxNumPlayers int    `json:"MaxNumPlayers"`
}

func joinOrCreateMatch(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
	prop := RPCMatchPayload{}
	err := json.Unmarshal([]byte(payload), &prop)
	if err == nil {
		logger.Error("joinOrFindMatch received invalid payload = %s", payload)
		return "", nil
	} else {
		minNumPlayers := 0
		matches, _ := nk.MatchList(ctx, 1, false, "", &minNumPlayers, &prop.MaxNumPlayers, "")
		if len(matches) > 0 {
			matchId := matches[0].MatchId
			logger.Info("joinOrFindMatch found match = %s", matchId)
			return matchId, nil
		} else {
			http.Head(fmt.Sprintf("http://host.docker.internal:9000/nakama?query=%s", prop.GameTag))
			logger.Info("joinOrFindMatch not match found, sending new instance request")
			return "", nil
		}
	}
}

This RPC function tries to find a non-authoritative match with maximum 4 players. If not found, it will send HTTP request to another server to request a unity instance (which creates a new match).

When there is a non-authoritative match created, nk.MatchList always returns empty list (And the returned err is nil). API explorer is able to find the match though.
The nakama version is v3.13.1, nakama-common version is v1.24.0.

Is there anything wrong with my code?

By the way, I was using Typescript runtime module at first, and the similar code was able to find the match:

let maxPlayers = Number(prop.MaxNumPlayers)
let matches = nakama.matchList(1, false, null, 0, maxPlayers)

I switched to use Go because there was a runtime error for “node-fetch” (for HTTP request) package when used in Typescript rollup build.

Hey, just wanna update on this.
There is nothing wrong with Go runtime. Turns out that prop.MaxNumPlayers in my code is somehow decoded to 0. Therefore empty list and no error message.
I should be able to resolve this myself. @sesposito Thank you for your help!

1 Like