summaryrefslogtreecommitdiff
path: root/client.lua
diff options
context:
space:
mode:
Diffstat (limited to 'client.lua')
-rw-r--r--client.lua11
1 files changed, 6 insertions, 5 deletions
diff --git a/client.lua b/client.lua
index 8639c2c..3c6cd63 100644
--- a/client.lua
+++ b/client.lua
@@ -1,5 +1,6 @@
local enet = require("enet")
local socket = require("socket")
+local util = require("util")
local common = require("common")
local client = {}
@@ -18,7 +19,7 @@ local function connect(clt, addr)
end
function client.join(invite, match_addr)
- local invite_dec = common.base64_dec(invite)
+ local invite_dec = util.base64_dec(invite)
if not invite_dec then
return nil, "invalid_invite"
end
@@ -28,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(common.json_enc({ type = "match_join", game_id = game_id }))
+ clt.match:send(util.json_enc({ type = "match_join", game_id = game_id }))
clt.match_req = socket.gettime()
clt.game_id = game_id
clt.status = "wait_match"
@@ -65,7 +66,7 @@ function client.update(clt)
local event = clt.host:service(20)
while event do
if event.type == "receive" then
- local pkt = common.json_dec(event.data)
+ local pkt = util.json_dec(event.data)
if pkt then
if event.peer == clt.match and clt.status == "wait_match" then
handle_match(clt, pkt)
@@ -77,9 +78,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(common.json_enc({ type = "match_join", game_id = common.base64_enc(clt.game_id) }))
+ clt.match:send(util.json_enc({ 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(common.json_enc({ type = "server_hi", secret = common.base64_enc(clt.secret) }))
+ clt.server:send(util.json_enc({ type = "server_hi", secret = util.base64_enc(clt.secret) }))
else
event.peer:disconnect_now()
end