Commit c3b95447 authored by Andrei Mihu's avatar Andrei Mihu Committed by Mo Firouz
Browse files

Allow authoritative match join attempts to carry metadata. Improve sample lua modules.

parent c966b2e8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
### Added
- More flexible query-based filter when listing realtime multiplayer matches.
- Runtime function to batch get groups by group ID.
- Allow authoritative match join attempts to carry metadata from the client.

### Changed
- Improved cancellation of ongoing work when clients disconnect.
+8 −2
Original line number Diff line number Diff line
@@ -65,8 +65,14 @@ local function send_stream_data(context, payload)
end
nk.register_rpc(send_stream_data, "clientrpc.send_stream_data")

local function create_authoritative_match(_context, _payload)
  local match_id = nk.match_create("match", { debug = true })
local function create_authoritative_match(_context, payload)
  local decoded = nk.json_decode(payload)
  local params = {
    debug = (decoded and decoded.debug) or true,
    label = (decoded and decoded.label)
  }

  local match_id = nk.match_create("match", params)
  return nk.json_encode({ match_id = match_id })
end
nk.register_rpc(create_authoritative_match, "clientrpc.create_authoritative_match")
+9 −1
Original line number Diff line number Diff line
@@ -86,13 +86,21 @@ Presence is the user attempting to join the match. Format:
  node: "name of the Nakama node the user is connected to"
}

Metadata is an optional set of arbitrary key-value pairs received from the client. These may contain information
the client wishes to supply to the match handler in order to process the join attempt, for example: authentication or
match passwords, client version information, preferences etc. Format:
{
  key: "value"
}

Expected return these values (all required) in order:
1. An (optionally) updated state. May be any non-nil Lua term, or nil to end the match.
2. Boolean true if the join attempt should be allowed, false otherwise.
--]]
local function match_join_attempt(context, dispatcher, tick, state, presence)
local function match_join_attempt(context, dispatcher, tick, state, presence, metadata)
  if state.debug then
    print("match join attempt:\n" .. du.print_r(presence))
    print("match join attempt metadata:\n" .. du.print_r(metadata))
  end
  return state, true
end
+4 −0
Original line number Diff line number Diff line
@@ -52,4 +52,8 @@ function M.match_loop(context, dispatcher, tick, state, messages)
  end
end

function M.match_terminate(context, dispatcher, tick, state, grace_seconds)
  return nil
end

return M
+149 −137

File changed.

Preview size limit exceeded, changes collapsed.

Loading