mirror of
https://github.com/moparisthebest/minetest
synced 2024-12-22 23:58:48 -05:00
Improve /grant and /revoke output, add /auth_reload
This commit is contained in:
parent
13159c1a48
commit
36c9463467
@ -990,11 +990,7 @@ minetest.register_chatcommand("privs", {
|
|||||||
minetest.chat_send_player(name, "Privileges of "..param.." are hidden from you.")
|
minetest.chat_send_player(name, "Privileges of "..param.." are hidden from you.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
privs = {}
|
minetest.chat_send_player(name, "Privileges of "..param..": "..minetest.privs_to_string(minetest.get_player_privs(param), ' '))
|
||||||
for priv, _ in pairs(minetest.get_player_privs(param)) do
|
|
||||||
table.insert(privs, priv)
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name, "Privileges of "..param..": "..table.concat(privs, " "))
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
minetest.register_chatcommand("grant", {
|
minetest.register_chatcommand("grant", {
|
||||||
@ -1013,6 +1009,10 @@ minetest.register_chatcommand("grant", {
|
|||||||
privs[priv] = true
|
privs[priv] = true
|
||||||
end
|
end
|
||||||
minetest.set_player_privs(grantname, privs)
|
minetest.set_player_privs(grantname, privs)
|
||||||
|
minetest.chat_send_player(name, "Privileges of "..grantname..": "..minetest.privs_to_string(minetest.get_player_privs(grantname), ' '))
|
||||||
|
if grantname ~= name then
|
||||||
|
minetest.chat_send_player(grantname, name.." granted you privileges: "..minetest.privs_to_string(grantprivs, ' '))
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
minetest.register_chatcommand("revoke", {
|
minetest.register_chatcommand("revoke", {
|
||||||
@ -1031,6 +1031,10 @@ minetest.register_chatcommand("revoke", {
|
|||||||
privs[priv] = nil
|
privs[priv] = nil
|
||||||
end
|
end
|
||||||
minetest.set_player_privs(revokename, privs)
|
minetest.set_player_privs(revokename, privs)
|
||||||
|
minetest.chat_send_player(name, "Privileges of "..revokename..": "..minetest.privs_to_string(minetest.get_player_privs(revokename), ' '))
|
||||||
|
if revokename ~= name then
|
||||||
|
minetest.chat_send_player(revokename, name.." revoked privileges from you: "..minetest.privs_to_string(revokeprivs, ' '))
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
minetest.register_chatcommand("setpassword", {
|
minetest.register_chatcommand("setpassword", {
|
||||||
@ -1056,6 +1060,20 @@ minetest.register_chatcommand("clearpassword", {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_chatcommand("auth_reload", {
|
||||||
|
params = "",
|
||||||
|
description = "reload authentication data",
|
||||||
|
privs = {server=true},
|
||||||
|
func = function(name, param)
|
||||||
|
local done = minetest.auth_reload()
|
||||||
|
if done then
|
||||||
|
minetest.chat_send_player(name, "Done.")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(name, "Failed.")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("teleport", {
|
minetest.register_chatcommand("teleport", {
|
||||||
params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
|
params = "<X>,<Y>,<Z> | <to_name> | <name> <X>,<Y>,<Z> | <name> <to_name>",
|
||||||
description = "teleport to given position",
|
description = "teleport to given position",
|
||||||
@ -1179,24 +1197,26 @@ end)
|
|||||||
-- Authentication handler
|
-- Authentication handler
|
||||||
--
|
--
|
||||||
|
|
||||||
function minetest.string_to_privs(str)
|
function minetest.string_to_privs(str, delim)
|
||||||
assert(type(str) == "string")
|
assert(type(str) == "string")
|
||||||
|
delim = delim or ','
|
||||||
privs = {}
|
privs = {}
|
||||||
for _, priv in pairs(string.split(str, ',')) do
|
for _, priv in pairs(string.split(str, delim)) do
|
||||||
privs[priv:trim()] = true
|
privs[priv:trim()] = true
|
||||||
end
|
end
|
||||||
return privs
|
return privs
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.privs_to_string(privs)
|
function minetest.privs_to_string(privs, delim)
|
||||||
assert(type(privs) == "table")
|
assert(type(privs) == "table")
|
||||||
|
delim = delim or ','
|
||||||
list = {}
|
list = {}
|
||||||
for priv, bool in pairs(privs) do
|
for priv, bool in pairs(privs) do
|
||||||
if bool then
|
if bool then
|
||||||
table.insert(list, priv)
|
table.insert(list, priv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return table.concat(list, ',')
|
return table.concat(list, delim)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert(minetest.string_to_privs("a,b").b == true)
|
assert(minetest.string_to_privs("a,b").b == true)
|
||||||
@ -1319,7 +1339,11 @@ minetest.builtin_auth_handler = {
|
|||||||
minetest.auth_table[name].privileges = privileges
|
minetest.auth_table[name].privileges = privileges
|
||||||
minetest.notify_authentication_modified(name)
|
minetest.notify_authentication_modified(name)
|
||||||
save_auth_file()
|
save_auth_file()
|
||||||
end
|
end,
|
||||||
|
reload = function()
|
||||||
|
read_auth_file()
|
||||||
|
return true
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
function minetest.register_authentication_handler(handler)
|
function minetest.register_authentication_handler(handler)
|
||||||
@ -1338,11 +1362,22 @@ function minetest.get_auth_handler()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function minetest.set_player_password(name, password)
|
function minetest.set_player_password(name, password)
|
||||||
minetest.get_auth_handler().set_password(name, password)
|
if minetest.get_auth_handler().set_password then
|
||||||
|
minetest.get_auth_handler().set_password(name, password)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function minetest.set_player_privs(name, privs)
|
function minetest.set_player_privs(name, privs)
|
||||||
minetest.get_auth_handler().set_privileges(name, privs)
|
if minetest.get_auth_handler().set_privileges then
|
||||||
|
minetest.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()
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -532,6 +532,7 @@ minetest.privs_to_string(privs) -> "priv1,priv2,..."
|
|||||||
minetest.set_player_password(name, password_hash)
|
minetest.set_player_password(name, password_hash)
|
||||||
minetest.set_player_privs(name, {priv1=true,...})
|
minetest.set_player_privs(name, {priv1=true,...})
|
||||||
minetest.get_player_privs(name) -> {priv1=true,...}
|
minetest.get_player_privs(name) -> {priv1=true,...}
|
||||||
|
minetest.auth_reload()
|
||||||
^ These call the authentication handler
|
^ These call the authentication handler
|
||||||
minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
|
minetest.check_player_privs(name, {priv1=true,...}) -> bool, missing_privs
|
||||||
^ A quickhand for checking privileges
|
^ A quickhand for checking privileges
|
||||||
|
Loading…
Reference in New Issue
Block a user