aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/stairs
diff options
context:
space:
mode:
authorEmon Omen <emon@openmailbox.org>2016-05-07 20:15:36 +0200
committerest31 <MTest31@outlook.com>2016-05-10 18:55:50 +0200
commitd3304a7dc4e04aacf393c22e65d0007ea3e1819a (patch)
tree92b80e616f1864ffdb90e6b2dcbac1acac2533c1 /games/minimal/mods/stairs
parentd23669a8596a5015cc780ea2a420dde6f5fb25fd (diff)
downloadminetest-d3304a7dc4e04aacf393c22e65d0007ea3e1819a.tar.gz
minetest-d3304a7dc4e04aacf393c22e65d0007ea3e1819a.tar.bz2
minetest-d3304a7dc4e04aacf393c22e65d0007ea3e1819a.zip
Translated using Weblate (Italian)
Currently translated at 100.0% (887 of 887 strings) This is a merger of three commits.
Diffstat (limited to 'games/minimal/mods/stairs')
0 files changed, 0 insertions, 0 deletions
4' href='#n124'>124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
-- Minetest: builtin/auth.lua

--
-- Authentication handler
--

function core.string_to_privs(str, delim)
	assert(type(str) == "string")
	delim = delim or ','
	local privs = {}
	for _, priv in pairs(string.split(str, delim)) do
		privs[priv:trim()] = true
	end
	return privs
end

function core.privs_to_string(privs, delim)
	assert(type(privs) == "table")
	delim = delim or ','
	local list = {}
	for priv, bool in pairs(privs) do
		if bool then
			list[#list + 1] = priv
		end
	end
	return table.concat(list, delim)
end

assert(core.string_to_privs("a,b").b == true)
assert(core.privs_to_string({a=true,b=true}) == "a,b")

core.auth_file_path = core.get_worldpath().."/auth.txt"
core.auth_table = {}

local function read_auth_file()
	local newtable = {}
	local file, errmsg = io.open(core.auth_file_path, 'rb')
	if not file then
		core.log("info", core.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world")
		return
	end
	for line in file:lines() do
		if line ~= "" then
			local fields = line:split(":", true)
			local name, password, privilege_string, last_login = unpack(fields)
			last_login = tonumber(last_login)
			if not (name and password and privilege_string) then
				error("Invalid line in auth.txt: "..dump(line))
			end
			local privileges = core.string_to_privs(privilege_string)
			newtable[name] = {password=password, privileges=privileges, last_login=last_login}
		end
	end
	io.close(file)
	core.auth_table = newtable
	core.notify_authentication_modified()
end

local function save_auth_file()
	local newtable = {}
	-- Check table for validness before attempting to save
	for name, stuff in pairs(core.auth_table) do
		assert(type(name) == "string")
		assert(name ~= "")
		assert(type(stuff) == "table")
		assert(type(stuff.password) == "string")
		assert(type(stuff.privileges) == "table")
		assert(stuff.last_login == nil or type(stuff.last_login) == "number")
	end