Add basic protection support to builtin
This commit is contained in:
parent
f435c5211e
commit
a78ef8d3a0
|
@ -218,6 +218,15 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, param2)
|
||||||
place_to = {x = under.x, y = under.y, z = under.z}
|
place_to = {x = under.x, y = under.y, z = under.z}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if minetest.is_protected(place_to, placer:get_player_name()) then
|
||||||
|
minetest.log("action", placer:get_player_name()
|
||||||
|
.. " tried to place " .. def.name
|
||||||
|
.. " at protected position "
|
||||||
|
.. minetest.pos_to_string(place_to))
|
||||||
|
minetest.record_protection_violation(place_to, placer:get_player_name())
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
minetest.log("action", placer:get_player_name() .. " places node "
|
minetest.log("action", placer:get_player_name() .. " places node "
|
||||||
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
.. def.name .. " at " .. minetest.pos_to_string(place_to))
|
||||||
|
|
||||||
|
@ -377,6 +386,15 @@ function minetest.node_dig(pos, node, digger)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if minetest.is_protected(pos, digger:get_player_name()) then
|
||||||
|
minetest.log("action", digger:get_player_name()
|
||||||
|
.. " tried to dig " .. node.name
|
||||||
|
.. " at protected position "
|
||||||
|
.. minetest.pos_to_string(pos))
|
||||||
|
minetest.record_protection_violation(pos, digger:get_player_name())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.log('action', digger:get_player_name() .. " digs "
|
minetest.log('action', digger:get_player_name() .. " digs "
|
||||||
.. node.name .. " at " .. minetest.pos_to_string(pos))
|
.. node.name .. " at " .. minetest.pos_to_string(pos))
|
||||||
|
|
||||||
|
|
|
@ -106,3 +106,14 @@ function minetest.setting_get_pos(name)
|
||||||
return minetest.string_to_pos(value)
|
return minetest.string_to_pos(value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- To be overriden by protection mods
|
||||||
|
function minetest.is_protected(pos, name)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
function minetest.record_protection_violation(pos, name)
|
||||||
|
for _, func in pairs(minetest.registered_on_protection_violation) do
|
||||||
|
func(pos, name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -344,4 +344,5 @@ minetest.registered_on_player_receive_fields, minetest.register_on_player_receiv
|
||||||
minetest.registered_on_cheats, minetest.register_on_cheat = make_registration()
|
minetest.registered_on_cheats, minetest.register_on_cheat = make_registration()
|
||||||
minetest.registered_on_crafts, minetest.register_on_craft = make_registration()
|
minetest.registered_on_crafts, minetest.register_on_craft = make_registration()
|
||||||
minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration()
|
minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration()
|
||||||
|
minetest.registered_on_protection_violation, minetest.register_on_protection_violation = make_registration()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue