Skip to content

Commit

Permalink
Fix quickauth
Browse files Browse the repository at this point in the history
  • Loading branch information
LBPHacker committed Jun 20, 2021
1 parent a80d880 commit 67849f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tptmp/client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local colours = require("tptmp.client.colours")
local config = require("tptmp.client.config")
local util = require("tptmp.client.util")
local format = require("tptmp.client.format")
local manager = require("tptmp.client.manager")

local log_event = print

Expand Down Expand Up @@ -641,7 +640,7 @@ function client_i:handshake_()
self:write_bytes_(tpt.version.major, tpt.version.minor, config.version)
self:write_nullstr_((name or tpt.get_name() or ""):sub(1, 255))
self:write_bytes_(0) -- * Flags, currently unused.
local qa_uid, qa_token = manager.get("quickauth", ""):match("^([^:]+):([^:]+)$")
local qa_uid, qa_token = self.get_qa_func_():match("^([^:]+):([^:]+)$")
self:write_str8_(qa_token and qa_uid == uid and qa_token or "")
self:write_str8_(self.initial_room_ or "")
self:write_flush_()
Expand All @@ -664,7 +663,7 @@ function client_i:handshake_()
self:write_flush_()
conn_status = self:read_bytes_(1)
if uid then
manager.set("quickauth", (conn_status == 1) and (uid .. ":" .. token) or "")
self.set_qa_func_((conn_status == 1) and (uid .. ":" .. token) or "")
end
end
if conn_status == 1 then
Expand Down Expand Up @@ -1264,6 +1263,8 @@ local function new(params)
initial_room_ = params.initial_room,
set_id_func_ = params.set_id_func,
get_id_func_ = params.get_id_func,
set_qa_func_ = params.set_qa_func,
get_qa_func_ = params.get_qa_func,
should_reconnect_func_ = params.should_reconnect_func,
should_not_reconnect_func_ = params.should_not_reconnect_func,
id_to_member = {},
Expand Down
11 changes: 11 additions & 0 deletions tptmp/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local client = require("tptmp.client.client")
local util = require("tptmp.client.util")
local profile = require("tptmp.client.profile")
local format = require("tptmp.client.format")
local manager = require("tptmp.client.manager")

local function run()
assert(sim.CELL == 4, "CELL size is not 4") -- * Required by cursor snapping functions.
Expand Down Expand Up @@ -38,6 +39,14 @@ local function run()
local function get_id()
return current_id, current_hist
end
local quickauth = manager.get("quickauth", "")
local function set_qa(qa)
quickauth = qa
manager.set("quickauth", quickauth)
end
local function get_qa()
return quickauth
end
local should_reconnect_at
local cli
local prof = profile.new({
Expand Down Expand Up @@ -84,6 +93,8 @@ local function run()
params.profile = prof
params.set_id_func = set_id
params.get_id_func = get_id
params.set_qa_func = set_qa
params.get_qa_func = get_qa
params.should_reconnect_func = function()
should_reconnect = true
end
Expand Down

0 comments on commit 67849f2

Please sign in to comment.