aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorShadowNinja <noreply@gmail.com>2013-08-02 16:41:36 -0400
committerShadowNinja <shadowninja@minetest.net>2013-11-02 14:01:10 -0400
commit06a5eceb81f8f5006814e567790166a0d7693972 (patch)
tree1a78385f7895f00cd2512dee3d934d3787b7165a /builtin
parent2636c92075196b4c2cd65327b1f839f1e8919b83 (diff)
downloadminetest-06a5eceb81f8f5006814e567790166a0d7693972.tar.gz
minetest-06a5eceb81f8f5006814e567790166a0d7693972.tar.bz2
minetest-06a5eceb81f8f5006814e567790166a0d7693972.zip
Add basic protection support to builtin
Diffstat (limited to 'builtin')
-rw-r--r--builtin/item.lua18
-rw-r--r--builtin/misc.lua11
-rw-r--r--builtin/misc_register.lua1
3 files changed, 30 insertions, 0 deletions
diff --git a/builtin/item.lua b/builtin/item.lua
index 99614581d..b3ab9bc4c 100644
--- a/builtin/item.lua
+++ b/builtin/item.lua
@@ -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}
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 "
.. def.name .. " at " .. minetest.pos_to_string(place_to))
@@ -377,6 +386,15 @@ function minetest.node_dig(pos, node, digger)
return
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 "
.. node.name .. " at " .. minetest.pos_to_string(pos))
diff --git a/builtin/misc.lua b/builtin/misc.lua
index 3d2c496e3..a6a1718ad 100644
--- a/builtin/misc.lua
+++ b/builtin/misc.lua
@@ -106,3 +106,14 @@ function minetest.setting_get_pos(name)
return minetest.string_to_pos(value)
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
+
diff --git a/builtin/misc_register.lua b/builtin/misc_register.lua
index 242fe6092..bb2c62ab8 100644
--- a/builtin/misc_register.lua
+++ b/builtin/misc_register.lua
@@ -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_crafts, minetest.register_on_craft = make_registration()
minetest.registered_craft_predicts, minetest.register_craft_predict = make_registration()
+minetest.registered_on_protection_violation, minetest.register_on_protection_violation = make_registration()