forked from heroiclabs/fishgame-macroquad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_rpc.lua
More file actions
27 lines (19 loc) · 698 Bytes
/
match_rpc.lua
File metadata and controls
27 lines (19 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local nk = require("nakama")
local function rpc_macroquad_find_match(context, payload)
local params = nk.json_decode(payload)
local limit = 1
local authoritative = true
local min_size = 0
local max_size = 4
local query = string.format("+label.kind:%s +label.engine:%s", params.kind, params.engine)
local matches = nk.match_list(limit, authoritative, label, min_size, max_size, query)
local res
if #matches == 0 then
local module = "match"
res = nk.match_create(module, params)
else
res = matches[1].match_id
end
return nk.json_encode({["match_id"] = res})
end
nk.register_rpc(rpc_macroquad_find_match, "rpc_macroquad_find_match")