Add chat command to get a players last login time

This commit is contained in:
Ryan Newell 2014-10-16 16:27:46 -05:00
parent 670d1f8e8a
commit 7fc82ff033
5 changed files with 25 additions and 7 deletions

View File

@ -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) == "number")
assert(type(stuff.lastlogin) == "string")
end
local file, errmsg = io.open(core.auth_file_path, 'w+b')
if not file then
@ -154,7 +154,7 @@ core.builtin_auth_handler = {
end,
set_login_time = function(name, logintime)
assert(type(name) == "string")
assert(type(logintime) == "number")
assert(type(logintime) == "string")
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

@ -723,3 +723,18 @@ core.register_chatcommand("msg", {
end,
})
core.register_chatcommand('logintime', {
params = "<name>",
description = "Get the last login time of a player",
privs = {interact=true},
func = function(name, param)
if param == "" then
param = name
end
local pauth = core.get_auth_handler().getAuth(param)
local logtime = pauth[lastlogin]
core.log("action", "Player " .. name .. "requested last login, " .. logtime)
core.chat_send_player(name, "Last login time was " .. logtime)
end,
})

View File

@ -126,7 +126,7 @@ bool ScriptApiServer::setPassword(const std::string &playername,
}
bool ScriptApiServer::set_login_time(const std::string &playername,
int logintime)
const std::string 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_pushnumber(L, logintime);
lua_pushstring(L, logintime.c_str());
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,
int logintime);
const std::string logintime);
private:
void getAuthHandler();
void readPrivileges(int index, std::set<std::string> &result);

View File

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