nakama-defold
nakama-defold copied to clipboard
Really not sure what's wrong. Trying to send Match Data
trying to send match data with
local result = socket.match_data_send(matchid , opcodes.send_input, data)
this is being done in a coroutine with a connected socket.
No error, the server sees that the message is recieved like this
{"level":"debug","ts":"2024-07-10T17:18:31.705-0400","caller":"server/pipeline.go:65","msg":"Received *rtapi.Envelope_MatchDataSend message","uid":"2f1ac17d-b374-4aa2-85b1-34a73ee10af2","sid":"ea506ba6-3f01-11ef-b43b-e0e9830395f8","message":{"MatchDataSend":{"match_id":"89786132-d824-41e1-ad7d-820960662c7d.doomscroller","op_code":3,"data":"eyJ4IjoxLjA3MDY4ODAzMDE2MDIsInkiOjB9"}}}
I've tried both the lua and the typescript runtime, no dice. Essentially, the server receives the message but doesn't actually forward it to the match_loop handlers or anything. My only theory is that my match id is somehow wrong? I'm sending the same match_id that I save from the callback of the rpc that creates the match, its the same match_id as the one I use to successfully join. Then I try to send match data to that same match id, the server receives it but it never seems to make it to the match_loop. the messages table/object is literally empty. I have no idea what's causing this, can't find any similar issues and don't even know if this is something wrong with the client library or the runtimes or what I'm doing wrong.
A minimum repro would be create a match using an rpc, join the authoritative match with the match id from the callback of the rpc, then attempt to send match data using socket.match_data_send. The server runtime debug logs show the message as being received but it's not propagated any further and does not actually reach the match_loop.
my create match rpc looks like this:
local function create_match(context, payload)
local modulename = "normal_run"
local setupstate = { initialstate = payload }
local matchid = nk.match_create(modulename, setupstate)
return nk.json_encode({ matchid = matchid })
end
nk.register_rpc(create_match, "create_match_rpc")
my match data send looks like this
local result = socket.match_data_send(match.match["match_id"] , opcodes.send_input, data)
the socket is joining the match properly as I can see there is a presence. But the message doesn't reach the matchloop and never goes further than what the person here #59 before the issue was closed due to inactivity was reporting. Just the runtime debug logs of a message being received. Match_loop messages stay empty.
I did a test just now with the XOXO / TicTacToe game and everything seems to be working as expected:
- https://github.com/defold/game-xoxo-nakama-client
- https://github.com/defold/game-xoxo-nakama-server
https://github.com/user-attachments/assets/94300969-79d6-4c28-b65f-20e8b2a31673
The match data which the game sends and receives is a JSON encoded Lua table:
- Send: https://github.com/defold/game-xoxo-nakama-client/blob/main/main/xoxo_nakama.lua#L91-L104
- Receive: https://github.com/defold/game-xoxo-nakama-client/blob/main/main/xoxo_nakama.lua#L108-L116
The Nakama Defold client will do base 64 encoding and decide automatically for match data:
https://github.com/heroiclabs/nakama-defold/blob/master/nakama/socket.lua#L29-L31
If you look at other clients such as the JS and Godot versions you see the same thing of base64 encoding/decoding under the hood. The general recommendation is ofc not to use JSON but a binary format such as protobuf or flatbuffers, but for the purpose of the example JSON is a good enough format.
local modulename = "normal_run" local setupstate = { initialstate = payload } local matchid = nk.match_create(modulename, setupstate)
I suppose a follow-up question would be if your match code in normal_run.lua is running correctly? Do you know for a fact that it works? What does you match_loop() look like? Can you share the entire match module?