online connectionc fix

This commit is contained in:
bryanthaboi
2026-08-31 07:25:10 -04:00
parent d18aab2086
commit 22f3b61c6b
3 changed files with 43 additions and 6 deletions
+3 -1
View File
@@ -1763,6 +1763,8 @@ function OnlinePanel.doConnect(imp)
if not ok then
st.status = tostring(err or "the relay didn't answer")
st.statusOk = false
else
st.status, st.statusOk = nil, false
end
return ok
end
@@ -1776,7 +1778,7 @@ function OnlinePanel.connect(imp)
st.connectWanted = true
st.ticketState = "pending"
local started = OnlinePanel.startJob(imp, "ticket", function(client)
return client:lobbyTicket()
return client:lobbyTicket(st.name)
end)
if started then return true end
st.ticketState = "unsupported"
+13 -5
View File
@@ -74,9 +74,13 @@ function SyncClient:send(method, path, body, opts)
local headers = { ["Accept"] = "application/json" }
local payload
if body ~= nil then
local ok, encoded = pcall(Json.encode, body)
if not ok then return nil, "could not encode the request" end
payload = encoded
if type(body) == "table" and next(body) == nil then
payload = "{}"
else
local ok, encoded = pcall(Json.encode, body)
if not ok then return nil, "could not encode the request" end
payload = encoded
end
headers["Content-Type"] = "application/json"
end
if not opts.noAuth then
@@ -190,8 +194,12 @@ function SyncClient:fetchShare(code)
{ noAuth = true, params = { code = trimmed } })
end
function SyncClient:lobbyTicket()
return self:send("POST", "/lobby/ticket", {})
function SyncClient:lobbyTicket(displayName)
local body = {}
if type(displayName) == "string" and displayName ~= "" then
body.displayName = displayName
end
return self:send("POST", "/lobby/ticket", body)
end
function SyncClient:setDisplayName(name)
+27
View File
@@ -1972,4 +1972,31 @@ do
ArenaData.speciesIds = savedSpecies
end
-- ------------------------------------------- lobby ticket request shape
do
local SyncClient = require("src.sync.SyncClient")
local sent
local transport = {
begin = function(_, req) sent = req return { req = req } end,
poll = function() return { status = "pending" } end,
release = function() end,
}
local client = SyncClient.new({ baseUrl = "http://relay.test",
transport = transport })
client:setAuth("account", "token")
client:lobbyTicket("RED#417")
T.eq(sent.body, '{"displayName":"RED#417"}',
"the ticket request carries the name the relay needs to mint one")
client:lobbyTicket(nil)
T.eq(sent.body, "{}",
"a nameless ticket request is still a JSON object, not an empty array")
client:send("POST", "/sync/unlink", {})
T.eq(sent.body, "{}", "any empty body is sent as an object")
end
T.finish("online panel")