Skip to content

Commit

Permalink
Fix air mode being reset to whatever it was before loading a save
Browse files Browse the repository at this point in the history
Also harden JSON decoding, nobody told me it's valid for a JSON document to not be an array or an object.
  • Loading branch information
LBPHacker committed Aug 11, 2021
1 parent 99b686b commit 9b40d9d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local ENV_DEFAULTS = {
DEFAULT_UI_WIND = 0,
TPTMP_PT_UNKNOWN = 0,
},
tpt = { version = { major = 96, minor = 0 } },
tpt = { version = { major = 96, minor = 1 } },
http = {},
socket = {},
}
Expand Down
7 changes: 5 additions & 2 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ xpcall(function()
end
assert(ok or err == util.CQUEUES_WRAP_RETHROW, "sanity check failure")
end, function(err)
io.stderr:write("[rip] top-level error: " .. tostring(err) .. "\n")
io.stderr:write("[rip] " .. debug.traceback():gsub("\n", "\n[rip] ") .. "\n")
local function rip(str)
io.stderr:write(str:gsub("\n", "\n[rip] ") .. "\n")
end
rip("[rip] top-level error: " .. tostring(err))
rip("[rip] " .. debug.traceback())
end)
17 changes: 12 additions & 5 deletions tptmp/client/profile/vanilla.lua
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ local function preshack_graphics(i)
return 0, 0
end

function profile_i:begin_placesave_size_(x, y, defer)
function profile_i:begin_placesave_size_(x, y, lazy_button_check)
local id = sim.partCreate(-3, 0, 0, preshack_elem)
if id == -1 then
preshack_zero = save_and_kill_zero()
Expand Down Expand Up @@ -808,9 +808,14 @@ function profile_i:begin_placesave_size_(x, y, defer)
pres = pres,
bx = bx,
by = by,
airmode = sim.airMode(),
airmode = not lazy_button_check and sim.airMode(),
}
if defer then
if lazy_button_check then
-- * This means that begin_placesave_size_ was called from a button
-- callback, i.e. not really in response to pasting, but reloading /
-- clearing / opening a save. In this case, the air mode should
-- not be reset to the original air mode, but left to be whatever
-- value these actions set it to.
self.placesave_size_next_ = pss
else
self.placesave_size_ = pss
Expand Down Expand Up @@ -842,8 +847,10 @@ function profile_i:end_placesave_size_()
pop(bx, y)
end
end
local partcount = self.placesave_size_.partcount
sim.airMode(self.placesave_size_.airmode)
local partcount = self.placesave_size_.partcount -- * TODO[opt]: figure out what I wanted to do with partcount
if self.placesave_size_.airmode then
sim.airMode(self.placesave_size_.airmode)
end
self.placesave_size_ = nil
if lx == math.huge then
self.placesave_postmsg_ = {
Expand Down
2 changes: 1 addition & 1 deletion tptmp/server/authenticator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ local function check_external_auth(client, token)
}
end
local ok, json = pcall(lunajson.decode, body)
if not ok then
if not ok or type(json) ~= "table" then
return nil, json, {
substage = "json",
reason = json,
Expand Down
13 changes: 12 additions & 1 deletion tptmp/server/remote_console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function remote_console_i:listen_()
break
end
local ok, data = pcall(lunajson.decode, line, nil, nil, true)
if ok then
if ok and type(data) == "table" then
if data.type == "request" then
local handler = self.handlers_[data.request]
if handler then
Expand Down Expand Up @@ -109,6 +109,17 @@ function remote_console_i:listen_()
break_outer = true
break
end
elseif ok then
self:send_json_({
type = "response",
status = "badformat",
human = "invalid format",
line = line,
reason = data,
})
self.log_wrn_("invalid format: $", data)
break_outer = true
break
else
self:send_json_({
type = "response",
Expand Down
6 changes: 6 additions & 0 deletions tptmp/server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ function server_i:fetch_user_(nick)
})
return nil, json
end
if not (type(json) == "table" and
type(json.User) == "table" and
type(json.ID) == "number" and
type(json.Username) == "string") then
return nil, "invalid response from backend"
end
self:rconlog({
event = "fetch_user",
input = nick,
Expand Down

0 comments on commit 9b40d9d

Please sign in to comment.