From 896baf8e05c4a17f6c302edbfff27f1e96fa08f0 Mon Sep 17 00:00:00 2001 From: Gabriel PĂ©rez-Cerezo Date: Sat, 20 Jul 2019 19:26:55 +0200 Subject: Prevent injection of floating-point delays, that wreck advtrains --- advtrains_line_automation/stoprail.lua | 11 ++++++++--- 1 file 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 -- cgit v1.2.3