Example
Matchmaking Queue
Players join/leave via routes, Bridge fires an internal event when a match forms, push notifies matched players.
local MATCH_SIZE = 2
local queue = {}
local function tryMatch()
while #queue >= MATCH_SIZE do
local group = {}
for i = 1, MATCH_SIZE do
table.insert(group, table.remove(queue, 1))
end
local matchId = game:GetService("HttpService"):GenerateGUID(false)
bridge.Fire("match.created", { matchId = matchId, players = group })
for _, player in ipairs(group) do
app:Push(player, "match.found", { matchId = matchId })
end
end
end
app:Post("matchmaking/join", function(Player, Payload, req, res)
for _, p in ipairs(queue) do
if p == Player then res:Status(400):Error("Already queued"); return end
end
table.insert(queue, Player)
res:Send({ position = #queue })
tryMatch()
end)
app:Post("matchmaking/leave", function(Player, Payload, req, res)
for i, p in ipairs(queue) do
if p == Player then table.remove(queue, i); res:Send({ left = true }); return end
end
res:Status(400):Error("Not in queue")
end)
app:Get("matchmaking/status", function(Player, Payload, req, res)
for i, p in ipairs(queue) do
if p == Player then res:Send({ queued = true, position = i }); return end
end
res:Send({ queued = false })
end)
See also
App · Bridge | internal match.created event · Server Push | match.found notification · Round Manager | what comes after a match forms