aboutsummaryrefslogtreecommitdiff
path: root/assets/blender/gleis/infos
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2018-06-19 19:49:24 +0200
committerorwell96 <orwell@bleipb.de>2018-06-19 19:49:24 +0200
commit08ac0f9c05c4623a2783749b1dee2dafa234cee6 (patch)
treee1ff64ecfcaf7688ef112b4b06f41e65a787dca2 /assets/blender/gleis/infos
parenteab240bdce187db0de7b2b2a20b8eabdb4bd3946 (diff)
downloadadvtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.tar.gz
advtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.tar.bz2
advtrains-08ac0f9c05c4623a2783749b1dee2dafa234cee6.zip
Check for inventory existence before serializing, and do not create it again if it already exists.
Diffstat (limited to 'assets/blender/gleis/infos')
0 files changed, 0 insertions, 0 deletions
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
-- Minetest: builtin/misc.lua

--
-- Misc. API functions
--

function core.check_player_privs(name, ...)
	local arg_type = type(name)
	if (arg_type == "userdata" or arg_type == "table") and
			name.get_player_name then -- If it quacks like a Player...
		name = name:get_player_name()
	elseif arg_type ~= "string" then
		error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
	end

	local requested_privs = {...}
	local player_privs = core.get_player_privs(name)
	local missing_privileges = {}

	if type(requested_privs[1]) == "table" then
		-- We were provided with a table like { privA = true, privB = true }.
		for priv, value in pairs(requested_privs[1]) do
			if value and not player_privs[priv] then
				missing_privileges[#missing_privileges + 1] = priv
			end
		end
	else
		-- Only a list, we can process it directly.
		for key, priv in pairs(requested_privs) do
			if not player_privs[priv] then
				missing_privileges[#missing_privileges + 1] = priv
			end
		end
	end

	if #missing_privileges > 0 then
		return false, missing_privileges
	end

	return true, ""
end

local player_list = {}

core.register_on_joinplayer(function(player)
	local player_name = player:get_player_name()
	player_list[player_name] = player
	if not minetest.is_singleplayer() then
		core.chat_send_all("*** " .. player_name .. " joined the game.")
	end
end)

core.register_on_leaveplayer(function(player, timed_out)
	local player_name = player:get_player_name()
	player_list[player_name] = nil
	local announcement = "*** " ..  player_name .. " left the game."
	if timed_out then
		announcement = announcement .. " (timed out)"
	end
	core.chat_send_all(announcement)
end)

function core.get_connected_players()
	local temp_table = {}
	for index, value in pairs(player_list) do
		if value:is_player_connected() then
			temp_table[#temp_table + 1] = value
		end
	end
	return temp_table
end

function minetest.player_exists(name)
	return minetest.get_auth_handler().get_auth(name) ~= nil
end

-- Returns two position vectors representing a box of `radius` in each
-- direction centered around the player corresponding to `player_name`
function core.get_player_radius_area(player_name, radius)
	local player = core.get_player_by_name(player_name)
	if player == nil then
		return nil
	end

	local p1 = player:getpos()
	local p2 = p1

	if radius then
		p1 = vector.subtract(p1, radius)
		p2 = vector.add(p2, radius)
	end

	return p1, p2
end

function core.hash_node_position(pos)
	return (pos.z+32768)*65536*65536 + (pos.y+32768)*65536 + pos.x+32768
end

function core.get_position_from_hash(hash)
	local pos = {}