summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-12-22 17:57:00 +0000
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-12-22 17:57:00 +0000
commit91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f (patch)
tree83e9a4920602df7296cf9e4b8046f9cb69439161
parent57fc8c67f827a41ab1278fd0d25b2566032da61a (diff)
downloadpipeworks-91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f.tar
pipeworks-91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f.tar.gz
pipeworks-91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f.tar.bz2
pipeworks-91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f.tar.xz
pipeworks-91bd0c7e985c6d5f98fddd22dccb6a4d30cae86f.zip
teleport_tube.lua: add checks for hash collisions in positions table
-rw-r--r--teleport_tube.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/teleport_tube.lua b/teleport_tube.lua
index 9a66de2..d707717 100644
--- a/teleport_tube.lua
+++ b/teleport_tube.lua
@@ -50,6 +50,11 @@ local function read_tube_db()
return tp_tube_db
end
+-- debug formatter for coordinates used below
+local fmt = function(pos)
+ return pos.x..", "..pos.y..", "..pos.z
+end
+
-- updates or adds a tube
local function set_tube(pos, channel, can_receive)
local tubes = tp_tube_db or read_tube_db()
@@ -63,6 +68,19 @@ local function set_tube(pos, channel, can_receive)
end
-- we haven't found any tp tube to update, so lets add it
+ -- but sanity check that the hash has not already been inserted.
+ -- if so, complain very loudly and refuse the update so the player knows something is amiss.
+ -- to catch regressions of https://github.com/minetest-mods/pipeworks/issues/166
+ local existing = tp_tube_db[hash]
+ if existing ~= nil then
+ local e = "error"
+ minetest.log(e, "pipeworks teleport tube update refused due to position hash collision")
+ minetest.log(e, "collided hash: "..hash)
+ minetest.log(e, "tried-to-place tube: "..fmt(pos))
+ minetest.log(e, "existing tube: "..fmt(existing))
+ return
+ end
+
tp_tube_db[hash] = {x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=can_receive}
save_tube_db()
end