aboutsummaryrefslogtreecommitdiff
path: root/advtrains_line_automation
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-07-20 19:26:55 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-07-20 19:26:55 +0200
commit896baf8e05c4a17f6c302edbfff27f1e96fa08f0 (patch)
tree90312ebe6edba10f2c2f0aebb08ba052f024756c /advtrains_line_automation
parentd6de12ded6ec4676c52882411cbb67c6d6979849 (diff)
downloadadvtrains-896baf8e05c4a17f6c302edbfff27f1e96fa08f0.tar.gz
advtrains-896baf8e05c4a17f6c302edbfff27f1e96fa08f0.tar.bz2
advtrains-896baf8e05c4a17f6c302edbfff27f1e96fa08f0.zip
Prevent injection of floating-point delays, that wreck advtrains
Diffstat (limited to 'advtrains_line_automation')
-rw-r--r--advtrains_line_automation/stoprail.lua11
1 files changed, 8 insertions, 3 deletions
diff --git a/advtrains_line_automation/stoprail.lua b/advtrains_line_automation/stoprail.lua
index d0a8309..ec4994b 100644
--- a/advtrains_line_automation/stoprail.lua
+++ b/advtrains_line_automation/stoprail.lua
@@ -2,6 +2,11 @@
-- adds "stop rail". Recognized by lzb. (part of behavior is implemented there)
+local function to_int(n)
+ --- Disallow floating-point numbers
+ return math.floor(tonumber(n))
+end
+
local function updatemeta(pos)
local meta = minetest.get_meta(pos)
local pe = advtrains.encode_pos(pos)
@@ -112,7 +117,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
stdata.track = fields.track
end
if fields.wait then
- stdata.wait = tonumber(fields.wait) or 10
+ stdata.wait = to_int(fields.wait) or 10
end
if fields.ars then
@@ -120,10 +125,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if fields.ddelay then
- stdata.ddelay = tonumber(fields.wait) or 1
+ stdata.ddelay = to_int(fields.ddelay) or 1
end
if fields.speed then
- stdata.speed = tonumber(fields.speed) or "M"
+ stdata.speed = to_int(fields.speed) or "M"
end
--TODO: signal