Protection fixes

- Work with new NC protection API for items
- Alarm only when protection provided by dais,
  not on other mods' protections
master
Aaron Suen 2021-03-20 08:18:33 -04:00
parent eca47daa51
commit 12582da596
3 changed files with 20 additions and 7 deletions

View File

@ -9,6 +9,8 @@ local exmachina = nodecore[modname]
local squelch = {}
minetest.register_on_protection_violation(function(pos, name)
if not pos.alarm then return end
local gain = tonumber(minetest.settings:get(modname .. "_alarm")) or 1
if gain <= 0 then return end

View File

@ -1,3 +1,3 @@
name = nc_exmachina
depends = nc_api_all, nc_terrain, nc_tree
depends = nc_api_all, nc_terrain, nc_tree, nc_items
min_minetest_version = 5.3

View File

@ -6,8 +6,6 @@ local minetest, nodecore, pairs, rawset
local modname = minetest.get_current_modname()
local exmachina = nodecore[modname]
local old_prot = minetest.is_protected
local default = "group:metal_cube, group:tote"
local grouppref = "group:"
@ -29,19 +27,32 @@ local function check(pos, thingname, pname)
if minetest.check_player_privs(pname, "protection_bypass") then return end
if match(thingname) or match(nodecore.stack_get(pos):get_name()) then
local owned = exmachina.owner_search(pos)
if owned and owned ~= pname then return true end
if owned and owned ~= pname then
pos.alarm = true
return true
end
end
end
local placing
local function metacheck(pos, name)
return check(pos, minetest.get_node(pos).name, name)
or (placing and check(pos, placing, name))
end
-- Check on trying to dig/access a protected node, and
-- handle placement check from special cases.
local old_prot = minetest.is_protected
function minetest.is_protected(pos, name, ...)
if check(pos, minetest.get_node(pos).name, name)
or (placing and check(pos, placing, name)) then return true end
if metacheck(pos, minetest.get_node(pos).name, name) then return true end
return old_prot(pos, name, ...)
end
local old_exempt = nodecore.protection_exempt
function nodecore.protection_exempt(pos, name, ...)
local old = old_exempt(pos, name, ...)
if not old then return old end
if metacheck(pos, minetest.get_node(pos).name, name) then return end
return old
end
-- Check on trying to place a protected node.
local old_place = minetest.item_place_node