diff --git a/init.lua b/init.lua index d512d01..166765d 100644 --- a/init.lua +++ b/init.lua @@ -2,9 +2,11 @@ digistuff = {} digistuff.update_panel_formspec = function (pos,dispstr) local meta = minetest.get_meta(pos) + local locked = meta:get_int("locked") == 1 local fs = "size[10,8]".. "background[0,0;0,0;digistuff_panel_bg.png;true]".. "label[0,0;%s]".. + (locked and "image_button[9,3;1,1;digistuff_panel_locked.png;unlock;]" or "image_button[9,3;1,1;digistuff_panel_unlocked.png;lock;]").. "image_button[2,4.5;1,1;digistuff_adwaita_go-up.png;up;]".. "image_button[1,5;1,1;digistuff_adwaita_go-previous.png;left;]".. "image_button[3,5;1,1;digistuff_adwaita_go-next.png;right;]".. @@ -15,6 +17,7 @@ digistuff.update_panel_formspec = function (pos,dispstr) "button[8,5.5;1,1;savechan;Set]" fs = fs:format(minetest.formspec_escape(dispstr)):gsub("|","\n") meta:set_string("formspec",fs) + meta:set_string("text",dispstr) end digistuff.panel_on_digiline_receive = function (pos, node, channel, msg) @@ -28,22 +31,79 @@ end digistuff.panel_on_receive_fields = function(pos, formname, fields, sender) local meta = minetest.get_meta(pos) local setchan = meta:get_string("channel") + local playername = sender:get_player_name() + local locked = meta:get_int("locked") == 1 + local can_bypass = minetest.check_player_privs(playername,{protection_bypass=true}) + local is_protected = minetest.is_protected(pos,playername) if fields.savechan then - meta:set_string("channel",fields.channel) - local helpmsg = "Channel has been set. Waiting for data..." - digistuff.update_panel_formspec(pos,helpmsg) + if can_bypass or not is_protected then + meta:set_string("channel",fields.channel) + local helpmsg = "Channel has been set. Waiting for data..." + digistuff.update_panel_formspec(pos,helpmsg) + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to change the channel of this panel.") + end elseif fields.up then - digiline:receptor_send(pos, digiline.rules.default, setchan, "up") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "up") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end elseif fields.down then - digiline:receptor_send(pos, digiline.rules.default, setchan, "down") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "down") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end elseif fields.left then - digiline:receptor_send(pos, digiline.rules.default, setchan, "left") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "left") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end elseif fields.right then - digiline:receptor_send(pos, digiline.rules.default, setchan, "right") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "right") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end elseif fields.back then - digiline:receptor_send(pos, digiline.rules.default, setchan, "back") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "back") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end elseif fields.enter then - digiline:receptor_send(pos, digiline.rules.default, setchan, "enter") + if can_bypass or not is_protected or not locked then + digiline:receptor_send(pos, digiline.rules.default, setchan, "enter") + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to use this panel.") + end + elseif fields.lock then + if can_bypass or not is_protected then + meta:set_int("locked",1) + minetest.chat_send_player(playername,"This panel has been locked. Access will now be controlled according to area protection.") + digistuff.update_panel_formspec(pos,meta:get_string("text")) + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to lock this panel.") + end + elseif fields.unlock then + if can_bypass or not is_protected then + meta:set_int("locked",0) + minetest.chat_send_player(playername,"This panel has been unlocked. It can now be used (but not locked or have the channel changed) by anyone.") + digistuff.update_panel_formspec(pos,meta:get_string("text")) + else + minetest.record_protection_violation(pos,playername) + minetest.chat_send_player(playername,"You are not authorized to unlock this panel.") + end end end @@ -286,6 +346,7 @@ minetest.register_node("digistuff:panel", { on_construct = function(pos) local helpmsg = "Please set a channel." digistuff.update_panel_formspec(pos,helpmsg) + minetest.get_meta(pos):set_int("locked",0) end, drawtype = "nodebox", tiles = { diff --git a/textures/digistuff_panel_locked.png b/textures/digistuff_panel_locked.png new file mode 100644 index 0000000..5e523a6 Binary files /dev/null and b/textures/digistuff_panel_locked.png differ diff --git a/textures/digistuff_panel_unlocked.png b/textures/digistuff_panel_unlocked.png new file mode 100644 index 0000000..c94f26c Binary files /dev/null and b/textures/digistuff_panel_unlocked.png differ