Stores login time as time since epoch, and formats the time in the the chat command

This commit is contained in:
Ryan Newell 2014-10-17 16:53:11 -07:00
parent ef17f6f2f8
commit 6f9aeaea85
5 changed files with 11 additions and 14 deletions

View File

@ -41,7 +41,7 @@ local function read_auth_file()
end
for line in file:lines() do
if line ~= "" then
local name, password, privilegestring, lastlogin = string.match(line, "([^:]*):([^:]*):([^:]*):([0-9/]* [0-9:]* [AP]M)")
local name, password, privilegestring, lastlogin = string.match(line, "([^:]*):([^:]*):([^:]*):([^:]*)")
if not name or not password or not privilegestring or not lastlogin then
error("Invalid line in auth.txt: "..dump(line))
end
@ -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
@ -122,7 +122,7 @@ core.builtin_auth_handler = {
core.auth_table[name] = {
password = password,
privileges = core.string_to_privs(core.setting_get("default_privs")),
lastlogin = "0",
lastlogin = 0,
}
save_auth_file()
end,
@ -154,7 +154,7 @@ core.builtin_auth_handler = {
end,
set_login_time = function(name, logintime)
assert(type(name) == "string")
assert(type(logintime) == "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"))

View File

@ -733,8 +733,9 @@ core.register_chatcommand('logintime', {
end
local pauth = core.get_auth_handler().get_auth(param)
local logtime = pauth["lastlogin"]
core.log("action", "Player " .. name .. "requested last login, " .. logtime)
core.chat_send_player(name, "Last login time was " .. logtime)
local formatted = os.date("%c", logtime)
core.log("action", "Player " .. name .. " requested last login, " .. formatted)
core.chat_send_player(name, "Last login time was " .. formatted)
end,
})

View File

@ -126,7 +126,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
}
bool ScriptApiServer::set_login_time(const std::string &playername,
const std::string logintime)
int logintime)
{
SCRIPTAPI_PRECHECKHEADER
@ -136,7 +136,7 @@ bool ScriptApiServer::set_login_time(const std::string &playername,
if(lua_type(L, -1) != LUA_TFUNCTION)
throw LuaError("Authentication handler missing set_login_time");
lua_pushstring(L, playername.c_str());
lua_pushstring(L, logintime.c_str());
lua_pushnumber(L, logintime);
if(lua_pcall(L, 2, 1, m_errorhandler))
scriptError();
return lua_toboolean(L, -1);

View File

@ -43,7 +43,7 @@ public:
bool setPassword(const std::string &playername,
const std::string &password);
bool set_login_time(const std::string &playername,
const std::string logintime);
int logintime);
private:
void getAuthHandler();
void readPrivileges(int index, std::set<std::string> &result);

View File

@ -1604,11 +1604,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
time_t logtim;
logtim = time(NULL);
char buf[80];
struct tm *ft = gmtime(&logtim);
strftime(buf, sizeof(buf), "%D %r", ft);
std::string bts(buf);
m_script->set_login_time(playername, buf);
m_script->set_login_time(playername, (int) logtim);
m_clients.setPlayerName(peer_id,playername);