Respect protection_bypass privilege, fix crash with areas and properly record protection violations

master
orwell96 2017-03-30 21:21:03 +02:00
parent a091ac2e1d
commit b5a5d9035f
5 changed files with 26 additions and 11 deletions

View File

@ -98,8 +98,8 @@ advtrains.register_tracks("default", {
atc.controllers[pts]=nil
end,
on_receive_fields = function(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then
minetest.chat_send_player(player:get_player_name(), attrans("This position is protected!"))
if advtrains.is_protected(pos, player:get_player_name()) then
minetest.record_protection_violation(pos, name)
return
end
local meta=minetest.get_meta(pos)

View File

@ -242,3 +242,14 @@ function advtrains.deserialize_inventory(sers, inv)
return false
end
--is_protected wrapper that checks for protection_bypass privilege
function advtrains.is_protected(pos, name)
if not name then
error("advtrains.is_protected() called without name parameter!")
end
if minetest.check_player_privs(name, {protection_bypass=true}) then
--player can bypass protection
return false
end
return minetest.is_protected(pos, name)
end

View File

@ -194,8 +194,9 @@ function tp.register_track_placer(nnprefix, imgprefix, dispname)
if pointed_thing.type=="node" then
local pos=pointed_thing.above
local upos=vector.subtract(pointed_thing.above, {x=0, y=1, z=0})
if minetest.is_protected(pos,name) and minetest.is_protected(upos,name) then
return itemstack
if advtrains.is_protected(pos,name) then
minetest.record_protection_violation(pos, name)
return itemstack
end
if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to
and minetest.registered_nodes[minetest.get_node(upos).name] and minetest.registered_nodes[minetest.get_node(upos).name].walkable then
@ -225,7 +226,8 @@ minetest.register_craftitem("advtrains:trackworker",{
end
if pointed_thing.type=="node" then
local pos=pointed_thing.under
if minetest.is_protected(pos, name) then
if advtrains.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return
end
local node=minetest.get_node(pos)
@ -267,8 +269,9 @@ minetest.register_craftitem("advtrains:trackworker",{
if pointed_thing.type=="node" then
local pos=pointed_thing.under
local node=minetest.get_node(pos)
if minetest.is_protected(pos, name) then
return
if advtrains.is_protected(pos, name) then
minetest.record_protection_violation(pos, name)
return
end
--if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end

View File

@ -490,8 +490,8 @@ function sl.create_slopeplacer_on_place(def, preset)
minetest.chat_send_player(player:get_player_name(), attrans("Can't place: space occupied!"))
return istack
end
if minetest.is_protected(pos, player:get_player_name()) then
minetest.chat_send_player(player:get_player_name(), attrans("Can't place: protected position!"))
if advtrains.is_protected(pos, player:get_player_name()) then
minetest.record_protection_violation(pos, player:get_player_name())
return istack
end
--determine player orientation (only horizontal component)
@ -525,7 +525,7 @@ function sl.create_slopeplacer_on_place(def, preset)
while step<=lookup.max do
local node=minetest.get_node(vector.add(pos, dirvec))
--next node solid?
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or minetest.is_protected(pos, player:get_player_name()) then
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or advtrains.is_protected(pos, player:get_player_name()) then
--do slopes of this distance exist?
if lookup[step] then
if minetest.setting_getbool("creative_mode") or istack:get_count()>=step then

View File

@ -34,7 +34,8 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{
end
if pointed_thing.type=="node" then
local pos=pointed_thing.under
if minetest.is_protected(pos, name) then
if advtrains.is_protected(pos, pname) then
minetest.record_protection_violation(pos, name)
return
end
local node=minetest.get_node(pos)