From e38c8177feaa341e22ae98f433a58e1e694b074c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=B5=D1=80=D1=85=D0=B0=D1=80=D0=B4=20PICCORO=20Len?= =?UTF-8?q?z=20McKAY?= Date: Wed, 3 Nov 2021 16:47:39 -0400 Subject: [PATCH] do not write auth.txt on each new user - added comit new command to * do not write on each new user * but let to write if set new password or any other case * added new commit command --- builtin/game/auth.lua | 10 +++++++++- builtin/game/chatcommands.lua | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/builtin/game/auth.lua b/builtin/game/auth.lua index 19af8db73..6b2c11630 100644 --- a/builtin/game/auth.lua +++ b/builtin/game/auth.lua @@ -39,6 +39,7 @@ local function read_auth_file() core.log("info", core.auth_file_path.." could not be opened for reading ("..errmsg.."); assuming new world") return end + minetest.log( "action", "Reading authentication data from disk..." ) for line in file:lines() do if line ~= "" then local fields = line:split(":", true) @@ -127,7 +128,7 @@ core.builtin_auth_handler = { privileges = core.string_to_privs(core.settings:get("default_privs")), last_login = os.time(), } - save_auth_file() +-- save_auth_file() -- save only when users logout or set a password end, set_password = function(name, password) assert(type(name) == "string") @@ -154,9 +155,15 @@ core.builtin_auth_handler = { save_auth_file() end, reload = function() + minetest.log( "action", "Reading authentication data from disk..." ) read_auth_file() return true end, + commit = function() + minetest.log( "action", "Writing authentication data manually (commit) to disk..." ) + save_auth_file() + return true + end, record_login = function(name) assert(type(name) == "string") assert(core.auth_table[name]).last_login = os.time() @@ -190,6 +197,7 @@ end core.set_player_password = auth_pass("set_password") core.set_player_privs = auth_pass("set_privileges") core.auth_reload = auth_pass("reload") +core.auth_commit = auth_pass("commit") local record_login = auth_pass("record_login") diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua index 3bd8f2f9c..e119d59be 100644 --- a/builtin/game/chatcommands.lua +++ b/builtin/game/chatcommands.lua @@ -279,6 +279,16 @@ core.register_chatcommand("auth_reload", { end, }) +core.register_chatcommand("auth_commit", { + params = "", + description = "write authentication data to disk", + privs = {server=true}, + func = function(name, param) + local done = core.auth_commit() + return done, (done and "Authentication data successfully saved to disk." or "Failed to write the auth.txt file.") + end, +}) + core.register_chatcommand("remove_player", { params = "", description = "Remove player data",