diff options
| author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-06-03 22:31:42 +0200 |
|---|---|---|
| committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-06-03 23:30:17 +0200 |
| commit | 341af788ffb60b1066f7735c10a2ef8480ec0aa9 (patch) | |
| tree | b1acbfe48184a263098e6146922730dd7ece8808 /client.lua | |
| parent | a42c94e103ecf7cb365a8888c3f5afc785def284 (diff) | |
| download | r6p-main.tar.xz | |
Diffstat (limited to 'client.lua')
| -rw-r--r-- | client.lua | 32 |
1 files changed, 17 insertions, 15 deletions
@@ -29,7 +29,7 @@ function client.join(invite, match_addr) local clt = create_client(secret) clt.match = clt.host:connect(match_addr or common.default_match_addr) - clt.match:send(util.json_enc({ type = "match_join", game_id = game_id })) + util.send(clt.match, { type = "match_join", game_id = game_id }) clt.match_req = socket.gettime() clt.game_id = game_id clt.status = "wait_match" @@ -59,6 +59,12 @@ local function handle_server(clt, pkt) clt.status = "active" elseif pkt.type == "client_reject" then clt.status = "fail_server" + elseif pkt.type == "client_info" then + clt.info = pkt + elseif pkt.type == "client_player" then + clt.player = pkt.name + elseif pkt.type == "client_player_fail" then + clt.player_error = pkt.error end end @@ -78,9 +84,9 @@ function client.update(clt) end elseif event.type == "connect" then if event.peer == clt.match and clt.status == "wait_match" then - clt.match:send(util.json_enc({ type = "match_join", game_id = util.base64_enc(clt.game_id) })) + util.send(clt.match, { type = "match_join", game_id = util.base64_enc(clt.game_id) }) elseif event.peer == clt.server and clt.status == "wait_server" then - clt.server:send(util.json_enc({ type = "server_hi", secret = util.base64_enc(clt.secret) })) + util.send(clt.server, { type = "server_hi", secret = util.base64_enc(clt.secret) }) else event.peer:disconnect_now() end @@ -103,24 +109,20 @@ function client.status(clt) end return clt.status +end - - -- wait_match - -- wait_server - - -- timeout_match - -- fail_match - -- timeout_server - -- fail_server - - -- active - -- disco +function client.select_player(clt, name, create) + util.send(clt.server, { + type = "server_player", + name = name, + create = create, + }) end function client.close(clt) if clt.match then clt.match:disconnect() end if clt.server then clt.server:disconnect() end - clt.host:service() + clt.host:flush() clt.host:destroy() end |
