fix on_receive_fieldss: check for protection and do not set meta if that field is nil, eg.g because of pressing escape

This commit is contained in:
HybridDog 2016-04-27 18:42:20 +02:00
parent e4ed8a50ee
commit 3c99c37f44
7 changed files with 40 additions and 33 deletions

@ -1,16 +1,15 @@
local toggle_timer = function (pos, restart)
local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos)
if timer:is_started() and not restart then
if timer:is_started()
and not restart then
timer:stop()
else
timer:start(tonumber(meta:get_int("interval")))
timer:start(tonumber(minetest.get_meta(pos):get_string("interval")) or 0)
end
end
local on_timer = function (pos)
local node = minetest.get_node(pos)
if(mesecon.flipstate(pos, node) == "on") then
local on_timer = function(pos)
if mesecon.flipstate(pos, minetest.get_node(pos)) == "on" then
mesecon.receptor_on(pos)
else
mesecon.receptor_off(pos)
@ -31,14 +30,16 @@ mesecon.register_node("moremesecons_adjustable_blinkyplant:adjustable_blinky_pla
},
on_timer = on_timer,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[interval;interval;${interval}]")
minetest.get_meta(pos):set_string("formspec", "field[interval;interval;${interval}]")
toggle_timer(pos, true)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
meta:set_string("interval", fields.interval)
on_receive_fields = function(pos, _, fields, player)
local interval = tonumber(fields.interval)
if interval
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("interval", interval)
toggle_timer(pos, true)
end
end,
},{
tiles = {"moremesecons_blinky_plant_off.png"},

@ -14,9 +14,10 @@ local function object_detector_make_formspec(pos)
make_formspec(minetest.get_meta(pos))
end
local function object_detector_on_receive_fields(pos, formname, fields)
local function object_detector_on_receive_fields(pos, _, fields, player)
if not fields.scanname
or not fields.digiline_channel then
or not fields.digiline_channel
or minetest.is_protected(pos, player:get_player_name()) then
return
end

@ -37,13 +37,14 @@ local function after_place(pos, placer)
end
end
local function receive_fields(pos, formname, fields, sender)
local function receive_fields(pos, _, fields, player)
if not fields.submit then
return
end
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner ~= "" and sender:get_player_name() ~= owner then
if owner ~= ""
and player:get_player_name() ~= owner then
return
end
meta:set_string("commands", fields.commands)

@ -14,9 +14,10 @@ local function object_detector_make_formspec(pos)
make_formspec(minetest.get_meta(pos))
end
local function object_detector_on_receive_fields(pos, formname, fields)
local function object_detector_on_receive_fields(pos, _, fields, player)
if not fields.scanname
or not fields.digiline_channel then
or not fields.digiline_channel
or minetest.is_protected(pos, player:get_player_name()) then
return
end

@ -77,8 +77,9 @@ minetest.register_node("moremesecons_sayer:sayer", {
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[text;text;${text}]")
end,
on_receive_fields = function(pos, _, fields)
if fields.text then
on_receive_fields = function(pos, _, fields, player)
if fields.text
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("text", fields.text)
end
end,

@ -66,8 +66,9 @@ mesecon.register_node("moremesecons_temporarygate:temporarygate", {
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[time;time;${time}]")
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.time then
on_receive_fields = function(pos, _, fields, player)
if fields.time
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("time", fields.time)
end
end

@ -83,8 +83,7 @@ minetest.register_node("moremesecons_wireless:wireless", {
},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", "field[channel;channel;${channel}]")
minetest.get_meta(pos):set_string("formspec", "field[channel;channel;${channel}]")
register_RID(pos)
end,
on_destruct = function(pos)
@ -95,9 +94,11 @@ minetest.register_node("moremesecons_wireless:wireless", {
end
mesecon.receptor_off(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
meta:set_string("channel", fields.channel)
on_receive_fields = function(pos, _, fields, player)
if fields.channel
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("channel", fields.channel)
end
end,
})