From f08683a3775989e749237cd001a8eaf3193d1684 Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Wed, 3 Jun 2026 01:15:29 +0200 Subject: add main menu --- client.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'client.lua') diff --git a/client.lua b/client.lua index 43ddda0..b300d2b 100644 --- a/client.lua +++ b/client.lua @@ -8,7 +8,7 @@ local client = {} local function create_client(secret) local clt = {} - clt.host = enet.host_create() -- enet.host_create("10.75.98.51:58901") + clt.host = enet.host_create() clt.secret = secret return clt end @@ -20,7 +20,11 @@ local function connect(clt, addr) end function client.join(invite, match_addr) - local invite_dec = base64.decode(invite) + local decode_succ, invite_dec = pcall(base64.decode, invite) + if not decode_succ then + return nil, "invalid_invite" + end + local game_id = invite_dec:sub(1, common.gameid_len) local secret = invite_dec:sub(common.gameid_len+1) @@ -93,7 +97,7 @@ end function client.status(clt) if clt.status == "wait_match" and clt.match_req+3 < socket.gettime() then clt.status = "timeout_match" - elseif clt.status == "wait_server" and clt.match_req+5 < socket.gettime() then + elseif clt.status == "wait_server" and clt.server_req+5 < socket.gettime() then clt.status = "timeout_server" end @@ -113,6 +117,9 @@ function client.status(clt) 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:destroy() end -- cgit v1.2.3