Unify protection handling

master
number Zero 2018-11-29 15:24:08 +03:00
parent f7ee82adb8
commit 637b5b4be4
3 changed files with 20 additions and 11 deletions

View File

@ -26,8 +26,7 @@ local function filter_init(pos)
end
local function filter_receive_fields(pos, formname, fields, sender)
if minetest.is_protected(pos, sender) and not minetest.check_player_privs(sender, "protection_bypass") then
minetest.record_protection_violation(pos, sender)
if digiline_routing.is_protected(pos, sender) then
return
end
if not fields.channel then

View File

@ -12,16 +12,14 @@ digiline_routing.multiblock.build2 = function(node1, node2, itemstack, placer, p
pos = pointed_thing.above
end
if minetest.is_protected(pos, placer:get_player_name()) and not minetest.check_player_privs(placer, "protection_bypass") then
minetest.record_protection_violation(pos, placer:get_player_name())
if digiline_routing.is_protected(pos, placer) then
return itemstack, false
end
local dir = minetest.dir_to_facedir(placer:get_look_dir())
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
if minetest.is_protected(botpos, placer:get_player_name()) and not minetest.check_player_privs(placer, "protection_bypass") then
minetest.record_protection_violation(botpos, placer:get_player_name())
if digiline_routing.is_protected(botpos, placer) then
return itemstack, false
end
@ -45,11 +43,11 @@ digiline_routing.multiblock.rotate2 = function(pos, node, user, mode, new_param2
local dir = minetest.facedir_to_dir(node.param2)
local p = vector.add(pos, dir)
local node2 = minetest.get_node_or_nil(p)
if not node2 or not node.param2 == node2.param2 then
if not node2 or node.param2 ~= node2.param2 then
return false
end
if minetest.is_protected(p, user:get_player_name()) then
minetest.record_protection_violation(p, user:get_player_name())
-- protection at `pos` is checked by the screwdriver
if digiline_routing.is_protected(p, user) then
return false
end
if mode ~= screwdriver.ROTATE_FACE then
@ -61,8 +59,7 @@ digiline_routing.multiblock.rotate2 = function(pos, node, user, mode, new_param2
if not node_def or not node_def.buildable_to then
return false
end
if minetest.is_protected(newp, user:get_player_name()) then
minetest.record_protection_violation(newp, user:get_player_name())
if digiline_routing.is_protected(newp, user) then
return false
end
node.param2 = new_param2

View File

@ -14,3 +14,16 @@ digiline_routing.get_base_rule = function(rule, param2)
end
return BASE_RULES[(rule + param2) % 4]
end
digiline_routing.is_protected = function(pos, player)
local name = player:get_player_name()
if not minetest.is_protected(pos, name) then
return false
end
-- FIXME: is this necessary?
if minetest.check_player_privs(name, "protection_bypass") then
return false
end
minetest.record_protection_violation(pos, name)
return true
end