Hello!
For the past week, I’ve been diving in the docs and also the Nakama’s main source code trying to find a solution for a problem but haven’t been successful yet. So I thought I’d ask it here too.
Basically I’m trying to write a manager that tunes the game logic and players roles based on presence events. So if, for example, a critical role leaves the game, that manager can know what to do to help the game flow not freeze. It must be able to function properly even when clients get disconnected unexpectedly.
The main problem is that the functions registered to be called before and after “MatchLeave” in lua runtime, aren’t getting called.
The functions are quite simple and at this point, are just for testing:
local function match_leave_before(context, payload)
nk.logger_info("[match leave before]")
return payload
end
local function match_leave_after(context, payload)
nk.logger_info("[match leave after]")
return payload
end
nk.register_rt_before(match_leave_before, "MatchLeave")
nk.register_rt_after(match_leave_after, "MatchLeave")
They get registered properly:
{"level":"info","ts":"2022-03-09T10:06:43.214Z","caller":"server/runtime.go:654","msg":"Registered Lua runtime Before function invocation","id":"*rtapi.envelope_matchleave"}
{"level":"info","ts":"2022-03-09T10:06:43.214Z","caller":"server/runtime.go:668","msg":"Registered Lua runtime After function invocation","id":"*rtapi.envelope_matchleave"}
I’m testing this with some Unity clients. Tried a few times, the registered runtime functions don’t get called when I suddenly close the Unity build.
The Unity code doesn’t do anything specific in this scenario. The clients just send matchmaking requests and join the match when a match is found. The matchmaking request has no query or numeric or string properties, only a min and max room size variables.
Then I close the build to suddenly make them disconnected.
When a client suddenly gets disconnected, Nakama server realizes this and logs a presence event properly:
{"level":"debug","ts":"2022-03-09T08:51:24.712Z","caller":"server/tracker.go:907","msg":"Processing presence event","joins":0,"leaves":1}
VERSIONS:
- Nakama 3.10.0 on Docker
- Unity client version 2.5.1 (has been in production code base for quite some time)
- Lua Runtime