Add support for protection_bypass priv.

Closes #330
This commit is contained in:
Foz 2016-12-31 21:47:09 -05:00 committed by Auke Kok
parent 4e439c34cb
commit a14722eb98
3 changed files with 42 additions and 28 deletions

View File

@ -117,32 +117,36 @@ function homedecor.handle_inventory(name, def, original_def)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local playername = player:get_player_name() local playername = player:get_player_name()
if (playername ~= owner) then if playername == owner or
minetest.check_player_privs(player, "protection_bypass") then
return allow_move and
allow_move(pos, from_list, from_index, to_list, to_index, count, player) or
count
end
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s", minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, name, owner, minetest.pos_to_string(pos) playername, name, owner, minetest.pos_to_string(pos)
)) ))
return 0 return 0
end end
return allow_move and allow_move(pos, from_list, from_index, to_list, to_index, count, player)
or count
end
local allow_put = def.allow_metadata_inventory_put local allow_put = def.allow_metadata_inventory_put
def.allow_metadata_inventory_put = function(pos, listname, index, stack, player) def.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local playername = player:get_player_name() local playername = player:get_player_name()
if (playername ~= owner) then if playername == owner or
minetest.check_player_privs(player, "protection_bypass") then
return allow_put and allow_put(pos, listname, index, stack, player) or
stack:get_count()
end
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s", minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, name, owner, minetest.pos_to_string(pos) playername, name, owner, minetest.pos_to_string(pos)
)) ))
return 0 return 0
end end
return allow_put and allow_put(pos, listname, index, stack, player)
or stack:get_count()
end
local allow_take = def.allow_metadata_inventory_take local allow_take = def.allow_metadata_inventory_take
def.allow_metadata_inventory_take = function(pos, listname, index, stack, player) def.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
@ -150,15 +154,17 @@ function homedecor.handle_inventory(name, def, original_def)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local playername = player:get_player_name() local playername = player:get_player_name()
if (playername ~= owner) then if playername == owner or
minetest.check_player_privs(player, "protection_bypass") then
return allow_take and allow_take(pos, listname, index, stack, player) or
stack:get_count()
end
minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s", minetest.log("action", string.format("%s tried to access a %s belonging to %s at %s",
playername, name, owner, minetest.pos_to_string(pos) playername, name, owner, minetest.pos_to_string(pos)
)) ))
return 0 return 0
end end
return allow_take and allow_take(pos, listname, index, stack, player)
or stack:get_count()
end
end end
local lockable = inventory.lockable local lockable = inventory.lockable

View File

@ -45,7 +45,9 @@ minetest.register_node("inbox:empty", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local player = clicker:get_player_name() local player = clicker:get_player_name()
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if owner == player then if owner == player or
minetest.check_player_privs(player, "protection_bypass") and
clicker:get_player_control().aux1 then
minetest.show_formspec( minetest.show_formspec(
clicker:get_player_name(), clicker:get_player_name(),
"default:chest_locked", "default:chest_locked",

View File

@ -126,7 +126,8 @@ minetest.register_node("itemframes:frame",{
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
if not itemstack then return end if not itemstack then return end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if clicker:get_player_name() == meta:get_string("owner") then if clicker:get_player_name() == meta:get_string("owner") or
minetest.check_player_privs(clicker, "protection_bypass") then
drop_item(pos,node) drop_item(pos,node)
local s = itemstack:take_item() local s = itemstack:take_item()
meta:set_string("item",s:to_string()) meta:set_string("item",s:to_string())
@ -136,14 +137,16 @@ minetest.register_node("itemframes:frame",{
end, end,
on_punch = function(pos,node,puncher) on_punch = function(pos,node,puncher)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if puncher:get_player_name() == meta:get_string("owner") then if puncher:get_player_name() == meta:get_string("owner") or
minetest.check_player_privs(puncher, "protection_bypass") then
drop_item(pos, node) drop_item(pos, node)
end end
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local name = player and player:get_player_name() local name = player and player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
return name == meta:get_string("owner") return name == meta:get_string("owner") or
minetest.check_player_privs(player, "protection_bypass")
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -183,7 +186,8 @@ minetest.register_node("itemframes:pedestal",{
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
if not itemstack then return end if not itemstack then return end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if clicker:get_player_name() == meta:get_string("owner") then if clicker:get_player_name() == meta:get_string("owner") or
minetest.check_player_privs(clicker, "protection_bypass") then
drop_item(pos,node) drop_item(pos,node)
local s = itemstack:take_item() local s = itemstack:take_item()
meta:set_string("item",s:to_string()) meta:set_string("item",s:to_string())
@ -193,14 +197,16 @@ minetest.register_node("itemframes:pedestal",{
end, end,
on_punch = function(pos,node,puncher) on_punch = function(pos,node,puncher)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
if puncher:get_player_name() == meta:get_string("owner") then if puncher:get_player_name() == meta:get_string("owner") or
minetest.check_player_privs(puncher, "protection_bypass") then
drop_item(pos,node) drop_item(pos,node)
end end
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local name = player and player:get_player_name() local name = player and player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
return name == meta:get_string("owner") return name == meta:get_string("owner") or
minetest.check_player_privs(player, "protection_bypass")
end, end,
on_destruct = function(pos) on_destruct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)