====== advtrains.is_protected ======
//Checks if a node is protected.//
//Note: this page has been written for Advtrains 2.0.1 TSS and Minetest 5.1.0. Examples and practices described in this page don't take advantage of improvements introduced in later releases.//
===== Syntax =====
advtrains.is_protected(pos, name)
===== Parameters =====
* ''pos'' //(table)//: a Minetest position vector.
* ''name'' //(string)//: the player name. It does not need to be logged in, but it *needs* to exist in the ''auth.txt'' file.
===== Returns =====
True if the node is protected and the player cannot bypass this protection, false otherwise.
===== Errors and warnings =====
It gives an error if the ''name'' parameter is nil:
> 2019-01-01 15:00:00: Error[Server]: advtrains.is_protected() called without name parameter!
===== How it works internally =====
This Lua function checks whether the designated player has the ''protection_bypass'' privilege. If not, it checks whether the node is protected by using the ''[[https://dev.minetest.net/minetest.is_protected|minetest.is_protected]]'' function, which may be overridden by protection mods.
If the player has the ''protection_bypass'' privilege, Advtrains considers all nodes "unprotected" regardless of current protection status.
===== Examples =====
Consider that you are running a Minetest server and:
* Two players, ''alice'' and ''bob'' are connected to the server
* ''alice'' has the ''protection_bypass'' privilege while ''bob'' has no privileges
* Node at position **(0,1,5)** has been protected
advtrains.is_protected({x=0, y=1,y=5}, "alice") -- returns false: node is protected, but protection bypass is enabled for this user
advtrains.is_protected({x=0, y=1,y=5}, "bob") -- returns true: node is protected
advtrains.is_protected({x=-10,y=0,y=0}, "bob") -- returns false: node is not protected
===== In source code =====
advtrains/helpers.lua, lines 214 to 223:
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