In an authoritative match, initially match state has 5000 items which I need to sync with the client when someone joins.
What I am doing here in the M.match_join handler, I am sending those items in a small chunk, let’s say 100 items per call. so a total of 50 calls.
Here is the code sample. Basically what it’s doing here is sending a total of 5000 items, 100 at a time.
function M.match_join(context, dispatcher, tick, state, presences)
for _, presence in ipairs(presences) do
print("New player: ", presence.username, state.world_id, context.match_id)
for _, items_table in pairs(state.world_items) do
local world_items_array = convert_world_items_info_to_array(items_table)
local paginated_items_array = {
items = {}
}
for i = 1, #world_items_array.items do
table.insert(paginated_items_array.items, world_items_array.items[i])
if i % state.items_in_one_page == 0 or i == #world_items_array.items then
local encoded_msg = nk.json_encode(paginated_items_array)
dispatcher.broadcast_message(MatchMessageType.WorldItemsInfo, encoded_msg, {presence})
paginated_items_array.items = {}
end
end
end
state.presences[presence.username] = presence
print("Player joined match successfully:", presence.username, state.world_id, context.match_id)
end
return state
end
Depending on the server and client location and network status, completing this M.match_join execution may take a few seconds, even a few minutes. But when the player leaves the match and disconnects the socket before completing these calls, Nakama runtime still tries to send the messages even though the socket is disconnected.
A side effect of this is I receive the M.match_leave fires when above 50 calls are completed.
If user tried to same session immediately after leaving the same session, we got some other wired behavior.
The documentation says Lua runtime does not give any error if the broadcast failed. What to do in this scenario?
- Nakama: Nakama: 3.1.2
- Server Framework Runtime language: Lua
- Unity SDK: 2.8.1