Update chests protection to current minetest_game

This commit is contained in:
Thomas--S 2017-03-06 21:09:44 +01:00
parent 35da22fcd2
commit ec6354b6a5
2 changed files with 12 additions and 55 deletions

View File

@ -26,12 +26,7 @@ technic.chests.can_dig = function(pos, player)
end end
local function inv_change(pos, count, player) local function inv_change(pos, count, player)
local meta = minetest.get_meta(pos) if not default.can_interact_with_node(player, pos) then
if not has_locked_chest_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
" tried to access a locked chest belonging to "..
meta:get_string("owner").." at "..
minetest.pos_to_string(pos))
return 0 return 0
end end
return count return count
@ -54,42 +49,14 @@ function technic.chests.on_inv_move(pos, from_list, from_index, to_list, to_inde
end end
function technic.chests.on_inv_put(pos, listname, index, stack, player) function technic.chests.on_inv_put(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name().. minetest.log("action", player:get_player_name() ..
" puts stuff in to chest at " " moves " .. stack:get_name() ..
..minetest.pos_to_string(pos)) " to chest at " .. minetest.pos_to_string(pos))
end end
function technic.chests.on_inv_take(pos, listname, index, stack, player) function technic.chests.on_inv_take(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name().. minetest.log("action", player:get_player_name() ..
" takes stuff from chest at " " takes " .. stack:get_name() ..
..minetest.pos_to_string(pos)) " from chest at " .. minetest.pos_to_string(pos))
end
local function has_locked_chest_privilege(meta, player)
if player then
if minetest.check_player_privs(player, "protection_bypass") then
return true
end
else
return false
end
-- is player wielding the right key?
local item = player:get_wielded_item()
if item:get_name() == "default:key" then
local key_meta = minetest.parse_json(item:get_metadata())
local secret = meta:get_string("key_lock_secret")
if secret ~= key_meta.secret then
return false
end
return true
end
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end end

View File

@ -267,7 +267,7 @@ function technic.chests:definition(name, data)
on_blast = function(pos) on_blast = function(pos)
local drops = {} local drops = {}
default.get_inventory_drops(pos, "main", drops) default.get_inventory_drops(pos, "main", drops)
drops[#drops+1] = "default:chest" drops[#drops+1] = "technic:"..name:lower()..(data.locked and "_locked" or "").."_chest"
minetest.remove_node(pos) minetest.remove_node(pos)
return drops return drops
end, end,
@ -277,20 +277,10 @@ function technic.chests:definition(name, data)
def.allow_metadata_inventory_put = self.inv_put def.allow_metadata_inventory_put = self.inv_put
def.allow_metadata_inventory_take = self.inv_take def.allow_metadata_inventory_take = self.inv_take
def.on_blast = function() end def.on_blast = function() end
def.on_key_use = function(pos, player) def.can_dig = function(pos,player)
local secret = minetest.get_meta(pos):get_string("key_lock_secret") local meta = minetest.get_meta(pos);
local itemstack = player:get_wielded_item() local inv = meta:get_inventory()
local key_meta = minetest.parse_json(itemstack:get_metadata()) return inv:is_empty("main") and default.can_interact_with_node(player, pos)
if secret ~= key_meta.secret then
return
end
minetest.show_formspec(
player:get_player_name(),
"default:chest_locked",
get_locked_chest_formspec(pos)
)
end end
def.on_skeleton_key_use = function(pos, player, newsecret) def.on_skeleton_key_use = function(pos, player, newsecret)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)