implements client enhanced information

* closes https://codeberg.org/minenux/minetest-engine-multicraft2#49
* closes https://codeberg.org/minenux/minetest-engine-minetest/issues/26
* it takes from https://github.com/MultiCraft/MultiCraft2/pull/50
* backported from "Add platform information to get_player_information"
This commit is contained in:
mckaygerhard 2023-09-07 17:10:05 -04:00
parent ff4334f40c
commit e1f5d81550
7 changed files with 45 additions and 11 deletions

View File

@ -2280,7 +2280,7 @@ Helper functions
major = 0, -- major version number major = 0, -- major version number
minor = 4, -- minor version number minor = 4, -- minor version number
patch = 10, -- patch version number patch = 10, -- patch version number
vers_string = "0.4.9-git", -- full version string version_string = "0.4.9", -- full version string
state = "Active" -- current client state state = "Active" -- current client state
} }
* `minetest.mkdir(path)`: returns success. * `minetest.mkdir(path)`: returns success.

View File

@ -1272,15 +1272,23 @@ void Client::sendRespawn()
void Client::sendReady() 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();
DSTACK(FUNCTION_NAME); DSTACK(FUNCTION_NAME);
NetworkPacket pkt(TOSERVER_CLIENT_READY, NetworkPacket pkt(TOSERVER_CLIENT_READY,
1 + 1 + 1 + 1 + 2 + sizeof(char) * strlen(g_version_hash)); 1 + 1 + 1 + 1 + 2 + sizeof(char) * version_len + 2);
pkt << (u8) VERSION_MAJOR << (u8) VERSION_MINOR << (u8) VERSION_PATCH 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.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());
Send(&pkt); Send(&pkt);
} }

View File

@ -354,7 +354,13 @@ public:
m_version_major = major; m_version_major = major;
m_version_minor = minor; m_version_minor = minor;
m_version_patch = patch; 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 */ /* read version information */
@ -362,6 +368,8 @@ public:
u8 getMinor() const { return m_version_minor; } u8 getMinor() const { return m_version_minor; }
u8 getPatch() const { return m_version_patch; } u8 getPatch() const { return m_version_patch; }
std::string getFull() const { return m_full_version; } std::string getFull() const { return m_full_version; }
std::string getPlatform() const { return m_platform; }
std::string getSysInfo() const { return m_sysinfo; }
private: private:
// Version is stored in here after INIT before INIT2 // Version is stored in here after INIT before INIT2
u8 m_pending_serialization_version; u8 m_pending_serialization_version;
@ -427,7 +435,9 @@ private:
u8 m_version_minor; u8 m_version_minor;
u8 m_version_patch; u8 m_version_patch;
std::string m_full_version; std::string m_full_version = "unknown or hacker";
std::string m_platform = "unknown";
std::string m_sysinfo = "unknown";
u16 m_deployed_compression; u16 m_deployed_compression;

View File

@ -881,6 +881,8 @@ enum ToServerCommand
u8 reserved u8 reserved
u16 len u16 len
u8[len] full_version_string u8[len] full_version_string
u8[len] platform
u8[len] sysinfo
*/ */
TOSERVER_FIRST_SRP = 0x50, TOSERVER_FIRST_SRP = 0x50,

View File

@ -167,7 +167,9 @@ int ModApiServer::l_get_player_information(lua_State *L)
u32 uptime; u32 uptime;
u16 prot_vers; u16 prot_vers;
u8 ser_vers,major,minor,patch; u8 ser_vers,major,minor,patch;
std::string vers_string; std::string version_string;
std::string platform;
std::string sysinfo;
#define ERET(code) \ #define ERET(code) \
if (!(code)) { \ if (!(code)) { \
@ -185,7 +187,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
ERET(getServer(L)->getClientInfo(player->peer_id, ERET(getServer(L)->getClientInfo(player->peer_id,
&state, &uptime, &ser_vers, &prot_vers, &state, &uptime, &ser_vers, &prot_vers,
&major, &minor, &patch, &vers_string)) &major, &minor, &patch, &version_string, &platform, $sysinfo))
lua_newtable(L); lua_newtable(L);
int table = lua_gettop(L); int table = lua_gettop(L);
@ -253,7 +255,15 @@ int ModApiServer::l_get_player_information(lua_State *L)
lua_settable(L, table); lua_settable(L, table);
lua_pushstring(L,"version_string"); 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_settable(L, table);
lua_pushstring(L,"state"); lua_pushstring(L,"state");

View File

@ -1410,7 +1410,9 @@ bool Server::getClientInfo(
u8* major, u8* major,
u8* minor, u8* minor,
u8* patch, u8* patch,
std::string* vers_string std::string* version_string
std::string* platform,
std::string* sysinfo
) )
{ {
*state = m_clients.getClientState(peer_id); *state = m_clients.getClientState(peer_id);
@ -1429,7 +1431,9 @@ bool Server::getClientInfo(
*major = client->getMajor(); *major = client->getMajor();
*minor = client->getMinor(); *minor = client->getMinor();
*patch = client->getPatch(); *patch = client->getPatch();
*vers_string = client->getFull(); *version_string = client->getFull();
*platform = client->getPlatform();
*sysinfo = client->getSysInfo();
m_clients.unlock(); m_clients.unlock();

View File

@ -359,7 +359,7 @@ public:
bool getClientConInfo(u16 peer_id, con::rtt_stat_type type,float* retval); bool getClientConInfo(u16 peer_id, con::rtt_stat_type type,float* retval);
bool getClientInfo(u16 peer_id,ClientState* state, u32* uptime, bool getClientInfo(u16 peer_id,ClientState* state, u32* uptime,
u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch, 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); void printToConsoleOnly(const std::string &text);