mirror of https://github.com/minetest/minetest.git
Added lastlogin time to auth.lua and server.cpp now saves when a player logins in. Hopefully
This commit is contained in:
parent
c7367ed882
commit
9f5d8f1bde
|
@ -63,7 +63,7 @@ local function save_auth_file()
|
|||
assert(type(stuff) == "table")
|
||||
assert(type(stuff.password) == "string")
|
||||
assert(type(stuff.privileges) == "table")
|
||||
assert(type(stuff.lastlogin) == "string")
|
||||
assert(type(stuff.lastlogin) == "number")
|
||||
end
|
||||
local file, errmsg = io.open(core.auth_file_path, 'w+b')
|
||||
if not file then
|
||||
|
@ -112,6 +112,7 @@ core.builtin_auth_handler = {
|
|||
return {
|
||||
password = core.auth_table[name].password,
|
||||
privileges = privileges,
|
||||
last_login = core.auth_table[name].lastlogin,
|
||||
}
|
||||
end,
|
||||
create_auth = function(name, password)
|
||||
|
@ -150,6 +151,16 @@ core.builtin_auth_handler = {
|
|||
read_auth_file()
|
||||
return true
|
||||
end,
|
||||
set_login_time = function(name, logintime)
|
||||
assert(type(name) == "string")
|
||||
assert(type(logintime) == "number")
|
||||
if not core.auth_table[name] then
|
||||
core.builtin_auth_handler.create_auth(name, core.get_password_hash(name, core.setting_get("default_password")))
|
||||
core.auth_table[name].privileges = core.string_to_privs(core.setting_get("default_privs"))
|
||||
end
|
||||
core.auth_table[name].lastlogin = logintime
|
||||
save_auth_file()
|
||||
end,
|
||||
}
|
||||
|
||||
function core.register_authentication_handler(handler)
|
||||
|
@ -179,6 +190,12 @@ function core.set_player_privs(name, privs)
|
|||
end
|
||||
end
|
||||
|
||||
function core.set_last_login(name, logintime)
|
||||
if core.get_auth_handler().set_login_time then
|
||||
core.get_auth_handler().set_login_time(name, logintime)
|
||||
end
|
||||
end
|
||||
|
||||
function core.auth_reload()
|
||||
if core.get_auth_handler().reload then
|
||||
return core.get_auth_handler().reload()
|
||||
|
|
|
@ -125,6 +125,23 @@ bool ScriptApiServer::setPassword(const std::string &playername,
|
|||
return lua_toboolean(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiServer::set_login_time(const std::string &playername,
|
||||
const std::int &logintime)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
getAuthHandler();
|
||||
lua_getfield(L, -1, "set_login_time");
|
||||
lua_remove(L, -2);
|
||||
if(lua_type(L, -1) != LUA_TFUNCTION)
|
||||
throw LuaError("Authentication handler missing set_login_time");
|
||||
lua_pushstring(L, playername.c_str());
|
||||
lua_pushNumber(L, logintime);
|
||||
if(lua_pcall(L, 2, 1, m_errorhandler))
|
||||
scriptError();
|
||||
return lua_toboolean(L, -1);
|
||||
}
|
||||
|
||||
bool ScriptApiServer::on_chat_message(const std::string &name,
|
||||
const std::string &message)
|
||||
{
|
||||
|
|
|
@ -1600,6 +1600,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
|
|||
L"name. If your client closed unexpectedly, try again in "
|
||||
L"a minute.");
|
||||
}
|
||||
|
||||
time_t time;
|
||||
time = time(NULL);
|
||||
|
||||
|
||||
m_script->set_login_time(playername, (int) time);
|
||||
|
||||
m_clients.setPlayerName(peer_id,playername);
|
||||
|
||||
|
|
Loading…
Reference in New Issue