mirror of
https://git.phreedom.club/localhost_frssoft/fediauth.git
synced 2024-11-22 16:01:28 +00:00
saner priv handling on join
This commit is contained in:
parent
de70d74ae9
commit
67ff44c51a
47
join.lua
47
join.lua
|
@ -7,23 +7,56 @@ local otp_time = 300
|
||||||
local otp_sessions = {}
|
local otp_sessions = {}
|
||||||
|
|
||||||
-- privs to revoke until the verification code is validated
|
-- privs to revoke until the verification code is validated
|
||||||
local temp_revoke_privs = {"interact", "shout", "privs", "basic_privs", "server", "ban", "kick"}
|
local temp_revoke_privs = {
|
||||||
|
-- builtin
|
||||||
|
"interact",
|
||||||
|
"shout",
|
||||||
|
"privs",
|
||||||
|
"basic_privs",
|
||||||
|
"server",
|
||||||
|
"ban",
|
||||||
|
"kick",
|
||||||
|
"settime",
|
||||||
|
"password",
|
||||||
|
"protection_bypass",
|
||||||
|
-- we
|
||||||
|
"worldedit",
|
||||||
|
-- areas
|
||||||
|
"areas"
|
||||||
|
}
|
||||||
|
|
||||||
|
-- moves all "temp_revoke_privs" to mod-storage
|
||||||
local function revoke_privs(playername)
|
local function revoke_privs(playername)
|
||||||
local privs = minetest.get_player_privs(playername)
|
local privs = minetest.get_player_privs(playername)
|
||||||
if otp.storage:get_string(playername .. "_privs") == "" then
|
if otp.storage:get_string(playername .. "_privs") == "" then
|
||||||
otp.storage:set_string(playername .. "_privs", minetest.serialize(privs))
|
local moved_privs = {}
|
||||||
for _, priv in ipairs(temp_revoke_privs) do
|
|
||||||
privs[priv] = nil
|
for _, priv_name in ipairs(temp_revoke_privs) do
|
||||||
minetest.set_player_privs(playername, privs)
|
if privs[priv_name] then
|
||||||
|
privs[priv_name] = nil
|
||||||
|
moved_privs[priv_name] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.log("action", "[otp] revoking privs of '" .. playername .. "' list: " .. dump(moved_privs))
|
||||||
|
minetest.set_player_privs(playername, privs)
|
||||||
|
otp.storage:set_string(playername .. "_privs", minetest.serialize(moved_privs))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- moves all privs from mod-storage into the live privs
|
||||||
local function regrant_privs(playername)
|
local function regrant_privs(playername)
|
||||||
local stored_priv_str = otp.storage:get_string(playername .. "_privs")
|
local stored_priv_str = otp.storage:get_string(playername .. "_privs")
|
||||||
if stored_priv_str ~= "" then
|
if stored_priv_str ~= "" then
|
||||||
local privs = minetest.deserialize(stored_priv_str)
|
local privs = minetest.get_player_privs(playername)
|
||||||
|
local stored_privs = minetest.deserialize(stored_priv_str)
|
||||||
|
|
||||||
|
-- merge stored privs into existing table
|
||||||
|
for priv_name in pairs(stored_privs) do
|
||||||
|
privs[priv_name] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("action", "[otp] regranting privs of '" .. playername .. "' list: " .. dump(stored_privs))
|
||||||
minetest.set_player_privs(playername, privs)
|
minetest.set_player_privs(playername, privs)
|
||||||
otp.storage:set_string(playername .. "_privs", "")
|
otp.storage:set_string(playername .. "_privs", "")
|
||||||
end
|
end
|
||||||
|
@ -33,6 +66,8 @@ end
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
if minetest.check_player_privs(playername, "otp_enabled") then
|
if minetest.check_player_privs(playername, "otp_enabled") then
|
||||||
|
minetest.log("action", "[otp] session start for player: '" .. playername .. "'")
|
||||||
|
|
||||||
-- start otp session time
|
-- start otp session time
|
||||||
otp_sessions[player:get_player_name()] = os.time()
|
otp_sessions[player:get_player_name()] = os.time()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue