Logger Doesn't Work in MatchHandler

Using the template project: GitHub - heroiclabs/nakama-project-template: An example project on how to set up and write custom server code in Nakama server., I tried to use logger to log something in MatchInit - but it doesn’t seem to work:

func (m *MatchHandler) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) {
    logger.Info("hello world!!!")
	fast, ok := params["fast"].(bool)
	if !ok {

I have a client using JS SDK to then call createMatch() and I know the call went through because I see this in Nakama log:

backend           | {"level":"debug","ts":"2023-03-24T13:15:04.161Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchCreate message","uid":"f4256a05-405c-46fd-bee9-8010
backend           | {"level":"debug","ts":"2023-03-24T13:15:04.162Z","caller":"server/tracker.go:907","msg":"Processing presence event","joins":1,"leaves":0}
backend           | {"level":"debug","ts":"2023-03-24T13:15:04.162Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_Match message","uid":"f4256a05-405c-46fd-bee9-80107543
087f","sid":"e3c7a5e8-ca45-11ed-892e-006100a0eb06","envelope":"cid:\"2\" match:{match_id:\"eb9d0410-8fa0-4758-abf9-16b589f69eda.\" size:1 self:{user_id:\"f4256a05-405c-46fd-bee9-80107543087f
\" session_id:\"e3c7a5e8-ca45-11ed-892e-006100a0eb06\" username:\"Kbgstmxgtw\"}}"}
backend           | {"level":"debug","ts":"2023-03-24T13:15:04.165Z","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchJoin message","uid":"c77188ae-a9d2-4159-b46d-c17999
backend           | {"level":"debug","ts":"2023-03-24T13:15:04.165Z","caller":"server/tracker.go:907","msg":"Processing presence event","joins":1,"leaves":0}
backend           | {"level":"debug","ts":"2023-03-24T13:15:04.166Z","caller":"server/session_ws.go:395","msg":"Sending *rtapi.Envelope_Match message","uid":"c77188ae-a9d2-4159-b46d-c179997e
e867","sid":"e3c8a9b6-ca45-11ed-892e-006100a0eb06","envelope":"cid:\"2\" match:{match_id:\"eb9d0410-8fa0-4758-abf9-16b589f69eda.\" size:1 presences:{user_id:\"f4256a05-405c-46fd-bee9-8010754
3087f\" session_id:\"e3c7a5e8-ca45-11ed-892e-006100a0eb06\" username:\"Kbgstmxgtw\"} self:{user_id:\"c77188ae-a9d2-4159-b46d-c179997ee867\" session_id:\"e3c8a9b6-ca45-11ed-892e-006100a0eb06\
" username:\"nAFsZBsiXQ\"}}"}

But no where in the log could I see my hello world!!!. I also tried to add this to the typescript module from that example project:

let matchInit: nkruntime.MatchInitFunction<State> = function (ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, params: {[key: string]: string}) {
    logger.info("hello world!!!")
    const fast = !!params['fast'];

When testing typescript I removed the go build process from the dockerfile (to avoid conflicts). Same problem as with Go. Lastly, my match is not Authoritative according to the console, how do I make it so that it is?:

I am using the sample project with no other changes, I did this because I couldn’t get it working in my own project either. I’m sure I’m missing something obvious but I can’t seem to figure it out. Any help would be appreciated, thank you.

  1. Versions: Docker heroiclabs/nakama:3.9.0, Docker heroiclabs/nakama:3.15.0 (tried both)
  2. Server Framework Runtime language: Go, TS

Hello @dragonlobster,

Authoritative matches can only be created server-side, you need to write a custom RPC (see this example) or use a matchmaker matched hook to create them.

The createMatch() functions exposed in the SDKs will create client-relayed matches only, this is why you see a non-authoritative match being created which won’t load your match handlers.

Hope this helps.

Ah thank you for that, somehow I missed that in the docs. It does seem hacky - feels like this feature should just work out of the box. Don’t really see a reason to prevent client from starting an authoritative match when they can do so anyway with this RPC hack. On the other hand there probably is a good reason.

Anyway I understand how this works now - thanks for your help!