aboutsummaryrefslogtreecommitdiff
path: root/builtin/game/auth.lua
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/game/auth.lua')
-rw-r--r--builtin/game/auth.lua106
1 files changed, 53 insertions, 53 deletions
diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua
index b6cca609c..5c62dbf28 100644
--- a/builtin/game/auth.lua
+++ b/builtin/game/auth.lua
@@ -4,7 +4,7 @@
-- Authentication handler
--
-function minetest.string_to_privs(str, delim)
+function core.string_to_privs(str, delim)
assert(type(str) == "string")
delim = delim or ','
privs = {}
@@ -14,7 +14,7 @@ function minetest.string_to_privs(str, delim)
return privs
end
-function minetest.privs_to_string(privs, delim)
+function core.privs_to_string(privs, delim)
assert(type(privs) == "table")
delim = delim or ','
list = {}
@@ -26,17 +26,17 @@ function minetest.privs_to_string(privs, delim)
return table.concat(list, delim)
end
-assert(minetest.string_to_privs("a,b").b == true)
-assert(minetest.privs_to_string({a=true,b=true}) == "a,b")
+assert(core.string_to_privs("a,b").b == true)
+assert(core.privs_to_string({a=true,b=true}) == "a,b")
-minetest.auth_file_path = minetest.get_worldpath().."/auth.txt"
-minetest.auth_table = {}
+core.auth_file_path = core.get_worldpath().."/auth.txt"
+core.auth_table = {}
local function read_auth_file()
local newtable = {}
- local file, errmsg = io.open(minetest.auth_file_path, 'rb')
+ local file, errmsg = io.open(core.auth_file_path, 'rb')
if not file then
- minetest.log("info", minetest.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world")
+ 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
@@ -45,31 +45,31 @@ local function read_auth_file()
if not name or not password or not privilegestring then
error("Invalid line in auth.txt: "..dump(line))
end
- local privileges = minetest.string_to_privs(privilegestring)
+ local privileges = core.string_to_privs(privilegestring)
newtable[name] = {password=password, privileges=privileges}
end
end
io.close(file)
- minetest.auth_table = newtable
- minetest.notify_authentication_modified()
+ 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(minetest.auth_table) do
+ 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")
end
- local file, errmsg = io.open(minetest.auth_file_path, 'w+b')
+ local file, errmsg = io.open(core.auth_file_path, 'w+b')
if not file then
- error(minetest.auth_file_path.." could not be opened for writing: "..errmsg)
+ error(core.auth_file_path.." could not be opened for writing: "..errmsg)
end
- for name, stuff in pairs(minetest.auth_table) do
- local privstring = minetest.privs_to_string(stuff.privileges)
+ for name, stuff in pairs(core.auth_table) do
+ local privstring = core.privs_to_string(stuff.privileges)
file:write(name..":"..stuff.password..":"..privstring..'\n')
end
io.close(file)
@@ -77,7 +77,7 @@ end
read_auth_file()
-minetest.builtin_auth_handler = {
+core.builtin_auth_handler = {
get_auth = function(name)
assert(type(name) == "string")
-- Figure out what password to use for a new player (singleplayer
@@ -85,52 +85,52 @@ minetest.builtin_auth_handler = {
-- usually empty too)
local new_password_hash = ""
-- If not in authentication table, return nil
- if not minetest.auth_table[name] then
+ if not core.auth_table[name] then
return nil
end
-- Figure out what privileges the player should have.
-- Take a copy of the privilege table
local privileges = {}
- for priv, _ in pairs(minetest.auth_table[name].privileges) do
+ for priv, _ in pairs(core.auth_table[name].privileges) do
privileges[priv] = true
end
-- If singleplayer, give all privileges except those marked as give_to_singleplayer = false
- if minetest.is_singleplayer() then
- for priv, def in pairs(minetest.registered_privileges) do
+ if core.is_singleplayer() then
+ for priv, def in pairs(core.registered_privileges) do
if def.give_to_singleplayer then
privileges[priv] = true
end
end
-- For the admin, give everything
- elseif name == minetest.setting_get("name") then
- for priv, def in pairs(minetest.registered_privileges) do
+ elseif name == core.setting_get("name") then
+ for priv, def in pairs(core.registered_privileges) do
privileges[priv] = true
end
end
-- All done
return {
- password = minetest.auth_table[name].password,
+ password = core.auth_table[name].password,
privileges = privileges,
}
end,
create_auth = function(name, password)
assert(type(name) == "string")
assert(type(password) == "string")
- minetest.log('info', "Built-in authentication handler adding player '"..name.."'")
- minetest.auth_table[name] = {
+ core.log('info', "Built-in authentication handler adding player '"..name.."'")
+ core.auth_table[name] = {
password = password,
- privileges = minetest.string_to_privs(minetest.setting_get("default_privs")),
+ privileges = core.string_to_privs(core.setting_get("default_privs")),
}
save_auth_file()
end,
set_password = function(name, password)
assert(type(name) == "string")
assert(type(password) == "string")
- if not minetest.auth_table[name] then
- minetest.builtin_auth_handler.create_auth(name, password)
+ if not core.auth_table[name] then
+ core.builtin_auth_handler.create_auth(name, password)
else
- minetest.log('info', "Built-in authentication handler setting password of player '"..name.."'")
- minetest.auth_table[name].password = password
+ core.log('info', "Built-in authentication handler setting password of player '"..name.."'")
+ core.auth_table[name].password = password
save_auth_file()
end
return true
@@ -138,11 +138,11 @@ minetest.builtin_auth_handler = {
set_privileges = function(name, privileges)
assert(type(name) == "string")
assert(type(privileges) == "table")
- if not minetest.auth_table[name] then
- minetest.builtin_auth_handler.create_auth(name, minetest.get_password_hash(name, minetest.setting_get("default_password")))
+ if not core.auth_table[name] then
+ core.builtin_auth_handler.create_auth(name, core.get_password_hash(name, core.setting_get("default_password")))
end
- minetest.auth_table[name].privileges = privileges
- minetest.notify_authentication_modified(name)
+ core.auth_table[name].privileges = privileges
+ core.notify_authentication_modified(name)
save_auth_file()
end,
reload = function()
@@ -151,36 +151,36 @@ minetest.builtin_auth_handler = {
end,
}
-function minetest.register_authentication_handler(handler)
- if minetest.registered_auth_handler then
- error("Add-on authentication handler already registered by "..minetest.registered_auth_handler_modname)
+function core.register_authentication_handler(handler)
+ if core.registered_auth_handler then
+ error("Add-on authentication handler already registered by "..core.registered_auth_handler_modname)
end
- minetest.registered_auth_handler = handler
- minetest.registered_auth_handler_modname = minetest.get_current_modname()
+ core.registered_auth_handler = handler
+ core.registered_auth_handler_modname = core.get_current_modname()
end
-function minetest.get_auth_handler()
- if minetest.registered_auth_handler then
- return minetest.registered_auth_handler
+function core.get_auth_handler()
+ if core.registered_auth_handler then
+ return core.registered_auth_handler
end
- return minetest.builtin_auth_handler
+ return core.builtin_auth_handler
end
-function minetest.set_player_password(name, password)
- if minetest.get_auth_handler().set_password then
- minetest.get_auth_handler().set_password(name, password)
+function core.set_player_password(name, password)
+ if core.get_auth_handler().set_password then
+ core.get_auth_handler().set_password(name, password)
end
end
-function minetest.set_player_privs(name, privs)
- if minetest.get_auth_handler().set_privileges then
- minetest.get_auth_handler().set_privileges(name, privs)
+function core.set_player_privs(name, privs)
+ if core.get_auth_handler().set_privileges then
+ core.get_auth_handler().set_privileges(name, privs)
end
end
-function minetest.auth_reload()
- if minetest.get_auth_handler().reload then
- return minetest.get_auth_handler().reload()
+function core.auth_reload()
+ if core.get_auth_handler().reload then
+ return core.get_auth_handler().reload()
end
return false
end