diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 267fd9356..a129e599c 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4087,7 +4087,9 @@ Utilities major = 5, -- major version number minor = 2, -- minor version number patch = 1, -- patch version number - vers_string = "5.2.1", -- full version string + version_string = "5.2.1", -- full version string (or maybe version_string) + platform = "Linux", -- as PLATFORM variable + sysinfo = "Linux/2.6.32 x86", state = "Active" -- current client state } diff --git a/src/client/client.cpp b/src/client/client.cpp index c6d28ce80..271f90f9a 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1244,13 +1244,21 @@ void Client::sendRespawn() void Client::sendReady() { + const char *platform_name = porting::getPlatformName(); + const std::string sysinfo = porting::get_sysinfo(); + const size_t version_len = strlen(g_version_hash) + 1 + strlen(platform_name) + 1 + sysinfo.size(); + NetworkPacket pkt(TOSERVER_CLIENT_READY, - 1 + 1 + 1 + 1 + 2 + sizeof(char) * strlen(g_version_hash) + 2); + 1 + 1 + 1 + 1 + 2 + sizeof(char) * version_len + 2); pkt << (u8) VERSION_MAJOR << (u8) VERSION_MINOR << (u8) VERSION_PATCH - << (u8) 0 << (u16) strlen(g_version_hash); + << (u8) 0 << (u16) version_len; pkt.putRawString(g_version_hash, (u16) strlen(g_version_hash)); + pkt << (u8) 0; + pkt.putRawString(platform_name, (u16) strlen(platform_name)); + pkt << (u8) 0; + pkt.putRawString(sysinfo.c_str(), sysinfo.size()); pkt << (u16)FORMSPEC_API_VERSION; Send(&pkt); } diff --git a/src/clientiface.h b/src/clientiface.h index e1b555383..2ae8fd6f6 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -332,7 +332,13 @@ public: m_version_major = major; m_version_minor = minor; m_version_patch = patch; - m_full_version = full; + m_full_version = full.c_str(); + const size_t pos1 = full.find('\x00'); + if (pos1 != std::string::npos) + m_platform = full.substr(pos1 + 1).c_str(); + const size_t pos2 = full.find('\x00', pos + 1); + if (pos2 != std::string::npos) + m_sysinfo = full.substr(pos2 + 1); } /* read version information */ @@ -340,6 +346,8 @@ public: u8 getMinor() const { return m_version_minor; } u8 getPatch() const { return m_version_patch; } const std::string &getFull() const { return m_full_version; } + const std::string &getPlatform() const { return m_platform; } + const std::string &getSysInfo() const { return m_sysinfo; } private: // Version is stored in here after INIT before INIT2 u8 m_pending_serialization_version = SER_FMT_VER_INVALID; @@ -413,6 +421,8 @@ private: u8 m_version_patch = 0; std::string m_full_version = "unknown"; + std::string m_platform = "unknown"; + std::string m_sysinfo = "unknown"; u16 m_deployed_compression = 0; diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index d3799868b..ae42af45b 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -935,6 +935,8 @@ enum ToServerCommand u8 reserved u16 len u8[len] full_version_string + u8[len] platform + u8[len] sysinfo */ TOSERVER_FIRST_SRP = 0x50, diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 28615f65a..ce27f71b5 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -162,7 +162,9 @@ int ModApiServer::l_get_player_information(lua_State *L) u32 uptime; u16 prot_vers; u8 ser_vers,major,minor,patch; - std::string vers_string; + std::string version_string; + std::string platform; + std::string sysinfo; #define ERET(code) \ if (!(code)) { \ @@ -182,7 +184,7 @@ int ModApiServer::l_get_player_information(lua_State *L) &avg_jitter)) ERET(getServer(L)->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers, - &prot_vers, &major, &minor, &patch, &vers_string)) + &prot_vers, &major, &minor, &patch, &version_string, &platform, &sysinfo)) lua_newtable(L); int table = lua_gettop(L); @@ -254,7 +256,15 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_settable(L, table); lua_pushstring(L,"version_string"); - lua_pushstring(L, vers_string.c_str()); + lua_pushstring(L, version_string.c_str()); + lua_settable(L, table); + + lua_pushstring(L,"platform"); + lua_pushstring(L, platform.c_str()); + lua_settable(L, table); + + lua_pushstring(L,"sysinfo"); + lua_pushstring(L, sysinfo.c_str()); lua_settable(L, table); lua_pushstring(L,"state"); diff --git a/src/server.cpp b/src/server.cpp index 239ddd92e..2b1fe9cf6 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1263,7 +1263,9 @@ bool Server::getClientInfo( u8* major, u8* minor, u8* patch, - std::string* vers_string + std::string* version_string, + std::string* platform, + std::string* sysinfo ) { *state = m_clients.getClientState(peer_id); @@ -1282,7 +1284,9 @@ bool Server::getClientInfo( *major = client->getMajor(); *minor = client->getMinor(); *patch = client->getPatch(); - *vers_string = client->getFull(); + *version_string = client->getFull(); + *platform = client->getPlatform(); + *sysinfo = client->getSysInfo(); m_clients.unlock(); diff --git a/src/server.h b/src/server.h index 680de57b5..223e04048 100644 --- a/src/server.h +++ b/src/server.h @@ -335,7 +335,7 @@ public: bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval); bool getClientInfo(session_t peer_id, ClientState *state, u32 *uptime, u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch, - std::string* vers_string); + std::string* version_string, std::string* platform, std::string* sysinfo); void printToConsoleOnly(const std::string &text);