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

View File

@ -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,15 +30,17 @@ 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}]")
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)
minetest.get_meta(pos):set_string("formspec", "field[interval;interval;${interval}]")
toggle_timer(pos, true)
end,
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"},
groups = {dig_immediate=3},

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -75,10 +75,11 @@ minetest.register_node("moremesecons_sayer:sayer", {
},
groups = {dig_immediate = 2},
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[text;text;${text}]")
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,

View File

@ -64,10 +64,11 @@ mesecon.register_node("moremesecons_temporarygate:temporarygate", {
is_ground_content = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
minetest.get_meta(pos):set_string("formspec", "field[time;time;${time}]")
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

View File

@ -24,12 +24,12 @@ local function wireless_activate(pos)
-- jamming doesn't disallow receiving signals, only sending them
return
end
local channel_first_wireless = minetest.get_meta(pos):get_string("channel")
if channel_first_wireless == "" then
return
end
for i = 1, #wireless do
if not vector.equals(wireless[i], pos)
and minetest.get_meta(wireless[i]):get_string("channel") == channel_first_wireless then
@ -83,9 +83,8 @@ 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}]")
register_RID(pos)
minetest.get_meta(pos):set_string("formspec", "field[channel;channel;${channel}]")
register_RID(pos)
end,
on_destruct = function(pos)
local RID = get(wireless_rids, pos.z,pos.y,pos.x)
@ -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,
})