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 toggle_timer = function (pos, restart)
local timer = minetest.get_node_timer(pos) local timer = minetest.get_node_timer(pos)
local meta = minetest.get_meta(pos) if timer:is_started()
if timer:is_started() and not restart then and not restart then
timer:stop() timer:stop()
else else
timer:start(tonumber(meta:get_int("interval"))) timer:start(tonumber(minetest.get_meta(pos):get_string("interval")) or 0)
end end
end end
local on_timer = function (pos) local on_timer = function(pos)
local node = minetest.get_node(pos) if mesecon.flipstate(pos, minetest.get_node(pos)) == "on" then
if(mesecon.flipstate(pos, node) == "on") then
mesecon.receptor_on(pos) mesecon.receptor_on(pos)
else else
mesecon.receptor_off(pos) mesecon.receptor_off(pos)
@ -31,15 +30,17 @@ mesecon.register_node("moremesecons_adjustable_blinkyplant:adjustable_blinky_pla
}, },
on_timer = on_timer, on_timer = on_timer,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) minetest.get_meta(pos):set_string("formspec", "field[interval;interval;${interval}]")
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)
toggle_timer(pos, true) toggle_timer(pos, true)
end, 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"}, tiles = {"moremesecons_blinky_plant_off.png"},
groups = {dig_immediate=3}, groups = {dig_immediate=3},

View File

@ -14,9 +14,10 @@ local function object_detector_make_formspec(pos)
make_formspec(minetest.get_meta(pos)) make_formspec(minetest.get_meta(pos))
end 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 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 return
end end

View File

@ -37,13 +37,14 @@ local function after_place(pos, placer)
end end
end end
local function receive_fields(pos, formname, fields, sender) local function receive_fields(pos, _, fields, player)
if not fields.submit then if not fields.submit then
return return
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") 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 return
end end
meta:set_string("commands", fields.commands) 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)) make_formspec(minetest.get_meta(pos))
end 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 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 return
end end

View File

@ -75,10 +75,11 @@ minetest.register_node("moremesecons_sayer:sayer", {
}, },
groups = {dig_immediate = 2}, groups = {dig_immediate = 2},
on_construct = function(pos) 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, end,
on_receive_fields = function(pos, _, fields) on_receive_fields = function(pos, _, fields, player)
if fields.text then if fields.text
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("text", fields.text) minetest.get_meta(pos):set_string("text", fields.text)
end end
end, end,

View File

@ -64,10 +64,11 @@ mesecon.register_node("moremesecons_temporarygate:temporarygate", {
is_ground_content = true, is_ground_content = true,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) 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, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, player)
if fields.time then if fields.time
and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("time", fields.time) minetest.get_meta(pos):set_string("time", fields.time)
end end
end end

View File

@ -24,12 +24,12 @@ local function wireless_activate(pos)
-- jamming doesn't disallow receiving signals, only sending them -- jamming doesn't disallow receiving signals, only sending them
return return
end end
local channel_first_wireless = minetest.get_meta(pos):get_string("channel") local channel_first_wireless = minetest.get_meta(pos):get_string("channel")
if channel_first_wireless == "" then if channel_first_wireless == "" then
return return
end end
for i = 1, #wireless do for i = 1, #wireless do
if not vector.equals(wireless[i], pos) if not vector.equals(wireless[i], pos)
and minetest.get_meta(wireless[i]):get_string("channel") == channel_first_wireless then 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(), sounds = default.node_sound_stone_defaults(),
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) minetest.get_meta(pos):set_string("formspec", "field[channel;channel;${channel}]")
meta:set_string("formspec", "field[channel;channel;${channel}]") register_RID(pos)
register_RID(pos)
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local RID = get(wireless_rids, pos.z,pos.y,pos.x) local RID = get(wireless_rids, pos.z,pos.y,pos.x)
@ -95,9 +94,11 @@ minetest.register_node("moremesecons_wireless:wireless", {
end end
mesecon.receptor_off(pos) mesecon.receptor_off(pos)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, _, fields, player)
local meta = minetest.get_meta(pos) if fields.channel
meta:set_string("channel", fields.channel) and not minetest.is_protected(pos, player:get_player_name()) then
minetest.get_meta(pos):set_string("channel", fields.channel)
end
end, end,
}) })