diff --git a/src/content_sao.cpp b/src/content_sao.cpp index cc02a7431..210494ba0 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -1485,3 +1485,9 @@ bool PlayerSAO::getCollisionBox(aabb3f *toset) { return true; } + +int PlayerSAO::getLastOnline() +{ + return m_player->last_online; +} + diff --git a/src/content_sao.h b/src/content_sao.h index dca02bb00..667b36b9b 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -237,6 +237,7 @@ public: } bool getCollisionBox(aabb3f *toset); + int getLastOnline(); private: std::string getPropertyPacket(); diff --git a/src/player.cpp b/src/player.cpp index 2a7a3084c..461b25d63 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -38,6 +38,7 @@ Player::Player(IGameDef *gamedef): hp(PLAYER_MAX_HP), breath(-1), peer_id(PEER_ID_INEXISTENT), + last_online(0), // protected m_gamedef(gamedef), m_pitch(0), @@ -50,6 +51,7 @@ Player::Player(IGameDef *gamedef): m_last_pos(0,0,0), m_last_hp(PLAYER_MAX_HP), m_last_inventory(gamedef->idef()) + { updateName(""); inventory.clear(); @@ -177,6 +179,7 @@ void Player::serialize(std::ostream &os) args.setFloat("yaw", m_yaw); args.setV3F("position", m_position); args.setS32("hp", hp); + args.setS32("last_online",last_online); args.writeLines(os); @@ -214,6 +217,12 @@ void Player::deSerialize(std::istream &is, std::string playername) hp = 20; } + try{ + last_online = args.getS32("last_online"); + } catch ( SettingNotFoundException &e ){ + last_online = time(NULL); + } + inventory.deSerialize(is); if(inventory.getList("craftpreview") == NULL) diff --git a/src/player.h b/src/player.h index 60645a60f..f4f8932f6 100644 --- a/src/player.h +++ b/src/player.h @@ -180,6 +180,16 @@ public: return m_name; } + u32 getLastOnline() + { + return last_online; + } + + virtual void setLastOnline( u32 lo ) + { + last_online = lo; + } + core::aabbox3d getCollisionbox() { return m_collisionbox; } @@ -269,6 +279,7 @@ public: std::vector hud; u32 hud_flags; s32 hud_hotbar_itemcount; + u32 last_online; protected: IGameDef *m_gamedef; @@ -283,7 +294,7 @@ protected: f32 m_last_pitch; f32 m_last_yaw; v3f m_last_pos; - u16 m_last_hp; + u16 m_last_hp; Inventory m_last_inventory; }; diff --git a/src/script/lua_api/luaapi.cpp b/src/script/lua_api/luaapi.cpp index d457d257e..fc1315769 100644 --- a/src/script/lua_api/luaapi.cpp +++ b/src/script/lua_api/luaapi.cpp @@ -77,6 +77,7 @@ bool ModApiBasic::Initialize(lua_State* L,int top) { retval &= API_FCT(get_player_privs); retval &= API_FCT(get_player_ip); + retval &= API_FCT(get_player_last_online); retval &= API_FCT(get_ban_list); retval &= API_FCT(get_ban_description); 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() int ModApiBasic::l_get_ban_list(lua_State *L) { diff --git a/src/script/lua_api/luaapi.h b/src/script/lua_api/luaapi.h index ba76117d4..647b9ff30 100644 --- a/src/script/lua_api/luaapi.h +++ b/src/script/lua_api/luaapi.h @@ -72,6 +72,9 @@ private: // get_player_ip() 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() static int l_get_ban_list(lua_State *L); diff --git a/src/server.cpp b/src/server.cpp index 1618a0915..66ade538d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2161,6 +2161,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) actionstream<getName()<<" ["<setLastOnline(time(NULL)); } return;