keeps track of a player's last login as a unix timestamp, adds lua function minetest.get_player_last_online(<name>) to access that information

in lua mods
This commit is contained in:
Brandon 2013-07-02 16:59:51 -05:00
parent 42a991758e
commit 036095e237
7 changed files with 50 additions and 1 deletions

View File

@ -1485,3 +1485,9 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) {
return true; return true;
} }
int PlayerSAO::getLastOnline()
{
return m_player->last_online;
}

View File

@ -237,6 +237,7 @@ public:
} }
bool getCollisionBox(aabb3f *toset); bool getCollisionBox(aabb3f *toset);
int getLastOnline();
private: private:
std::string getPropertyPacket(); std::string getPropertyPacket();

View File

@ -38,6 +38,7 @@ Player::Player(IGameDef *gamedef):
hp(PLAYER_MAX_HP), hp(PLAYER_MAX_HP),
breath(-1), breath(-1),
peer_id(PEER_ID_INEXISTENT), peer_id(PEER_ID_INEXISTENT),
last_online(0),
// protected // protected
m_gamedef(gamedef), m_gamedef(gamedef),
m_pitch(0), m_pitch(0),
@ -50,6 +51,7 @@ Player::Player(IGameDef *gamedef):
m_last_pos(0,0,0), m_last_pos(0,0,0),
m_last_hp(PLAYER_MAX_HP), m_last_hp(PLAYER_MAX_HP),
m_last_inventory(gamedef->idef()) m_last_inventory(gamedef->idef())
{ {
updateName("<not set>"); updateName("<not set>");
inventory.clear(); inventory.clear();
@ -177,6 +179,7 @@ void Player::serialize(std::ostream &os)
args.setFloat("yaw", m_yaw); args.setFloat("yaw", m_yaw);
args.setV3F("position", m_position); args.setV3F("position", m_position);
args.setS32("hp", hp); args.setS32("hp", hp);
args.setS32("last_online",last_online);
args.writeLines(os); args.writeLines(os);
@ -214,6 +217,12 @@ void Player::deSerialize(std::istream &is, std::string playername)
hp = 20; hp = 20;
} }
try{
last_online = args.getS32("last_online");
} catch ( SettingNotFoundException &e ){
last_online = time(NULL);
}
inventory.deSerialize(is); inventory.deSerialize(is);
if(inventory.getList("craftpreview") == NULL) if(inventory.getList("craftpreview") == NULL)

View File

@ -180,6 +180,16 @@ public:
return m_name; return m_name;
} }
u32 getLastOnline()
{
return last_online;
}
virtual void setLastOnline( u32 lo )
{
last_online = lo;
}
core::aabbox3d<f32> getCollisionbox() { core::aabbox3d<f32> getCollisionbox() {
return m_collisionbox; return m_collisionbox;
} }
@ -269,6 +279,7 @@ public:
std::vector<HudElement *> hud; std::vector<HudElement *> hud;
u32 hud_flags; u32 hud_flags;
s32 hud_hotbar_itemcount; s32 hud_hotbar_itemcount;
u32 last_online;
protected: protected:
IGameDef *m_gamedef; IGameDef *m_gamedef;
@ -283,7 +294,7 @@ protected:
f32 m_last_pitch; f32 m_last_pitch;
f32 m_last_yaw; f32 m_last_yaw;
v3f m_last_pos; v3f m_last_pos;
u16 m_last_hp; u16 m_last_hp;
Inventory m_last_inventory; Inventory m_last_inventory;
}; };

View File

@ -77,6 +77,7 @@ bool ModApiBasic::Initialize(lua_State* L,int top) {
retval &= API_FCT(get_player_privs); retval &= API_FCT(get_player_privs);
retval &= API_FCT(get_player_ip); retval &= API_FCT(get_player_ip);
retval &= API_FCT(get_player_last_online);
retval &= API_FCT(get_ban_list); retval &= API_FCT(get_ban_list);
retval &= API_FCT(get_ban_description); retval &= API_FCT(get_ban_description);
retval &= API_FCT(ban_player); retval &= API_FCT(ban_player);
@ -335,6 +336,23 @@ int ModApiBasic::l_get_player_ip(lua_State *L)
} }
} }
// get_player_last_online()
int ModApiBasic::l_get_player_last_online(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const char * name = luaL_checkstring(L, 1);
Player *player = getEnv(L)->getPlayer(name);
if ( player == NULL )
{
lua_pushnil(L);
return 1;
}
lua_pushnumber(L,(double)player->getLastOnline());
return 1;
}
// get_ban_list() // get_ban_list()
int ModApiBasic::l_get_ban_list(lua_State *L) int ModApiBasic::l_get_ban_list(lua_State *L)
{ {

View File

@ -72,6 +72,9 @@ private:
// get_player_ip() // get_player_ip()
static int l_get_player_ip(lua_State *L); static int l_get_player_ip(lua_State *L);
// get_player_last_online()
static int l_get_player_last_online(lua_State *L);
// get_ban_list() // get_ban_list()
static int l_get_ban_list(lua_State *L); static int l_get_ban_list(lua_State *L);

View File

@ -2161,6 +2161,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
actionstream<<player->getName()<<" ["<<addr_s<<"] "<<" joins game. List of players: " actionstream<<player->getName()<<" ["<<addr_s<<"] "<<" joins game. List of players: "
<<os.str()<<std::endl; <<os.str()<<std::endl;
player->setLastOnline(time(NULL));
} }
return; return;