From f91eca1e5eb88c3c9ed74ff1980378b97a91e62c Mon Sep 17 00:00:00 2001 From: luk3yx Date: Wed, 27 Apr 2022 18:24:40 +1200 Subject: [PATCH] Add platform information to get_player_information (#50) --- doc/lua_api.txt | 17 +++++++++-------- src/client/client.cpp | 11 +++++++++-- src/clientiface.h | 16 ++++++++++++++-- src/script/lua_api/l_server.cpp | 8 ++++++++ src/server.cpp | 2 ++ src/server.h | 2 +- 6 files changed, 43 insertions(+), 13 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 39ea91e31..7e3c549d1 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -4523,14 +4523,15 @@ Utilities min_jitter = 0.01, -- minimum packet time jitter max_jitter = 0.5, -- maximum packet time jitter avg_jitter = 0.03, -- average packet time jitter - -- the following information is available in a debug build only!!! - -- DO NOT USE IN MODS - --ser_vers = 26, -- serialization version used by client - --major = 0, -- major version number - --minor = 4, -- minor version number - --patch = 10, -- patch version number - --vers_string = "0.4.9-git", -- full version string - --state = "Active" -- current client state + -- DO NOT USE IN MODS WITHOUT A GOOD REASON + serialization_version = 26, -- serialization version used by client + major = 0, -- major version number + minor = 4, -- minor version number + patch = 10, -- patch version number + version_string = "0.4.9-git", -- full version string + platform = "Linux", -- Equivalent to the "PLATFORM" variable + sysinfo = "Linux/5.4.0-109-generic x86_64", + state = "Active" -- current client state } * `minetest.mkdir(path)`: returns success. diff --git a/src/client/client.cpp b/src/client/client.cpp index 4c8a88ea8..9361e99b9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1300,13 +1300,20 @@ 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 ff1456ee4..95e3c972a 100644 --- a/src/clientiface.h +++ b/src/clientiface.h @@ -332,7 +332,15 @@ 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 pos = full.find('\x00'); + if (pos != std::string::npos) { + m_platform = full.substr(pos + 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,7 +348,9 @@ public: u8 getMinor() const { return m_version_minor; } u8 getPatch() const { return m_version_patch; } const std::string &getFullVer() const { return m_full_version; } - + const std::string &getPlatform() const { return m_platform; } + const std::string &getSysInfo() const { return m_sysinfo; } + void setLangCode(const std::string &code) { m_lang_code = code; } const std::string &getLangCode() const { return m_lang_code; } @@ -426,6 +436,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/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index a5b5742e2..da7811bb3 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -250,6 +250,14 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushstring(L, info.vers_string.c_str()); lua_settable(L, table); + lua_pushstring(L,"platform"); + lua_pushstring(L, info.platform.c_str()); + lua_settable(L, table); + + lua_pushstring(L,"sysinfo"); + lua_pushstring(L, info.sysinfo.c_str()); + lua_settable(L, table); + lua_pushstring(L,"state"); lua_pushstring(L, ClientInterface::state2Name(info.state).c_str()); lua_settable(L, table); diff --git a/src/server.cpp b/src/server.cpp index 1103dc521..43b8f02a8 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1281,6 +1281,8 @@ bool Server::getClientInfo(session_t peer_id, ClientInfo &ret) ret.minor = client->getMinor(); ret.patch = client->getPatch(); ret.vers_string = client->getFullVer(); + ret.platform = client->getPlatform(); + ret.sysinfo = client->getSysInfo(); ret.lang_code = client->getLangCode(); diff --git a/src/server.h b/src/server.h index e17b3ffb0..5e33d5b49 100644 --- a/src/server.h +++ b/src/server.h @@ -147,7 +147,7 @@ struct ClientInfo { u8 ser_vers; u16 prot_vers; u8 major, minor, patch; - std::string vers_string, lang_code; + std::string vers_string, platform, sysinfo, lang_code; }; class Server : public con::PeerHandler, public MapEventReceiver,