implements client enhanced information
* closes https://codeberg.org/minenux/minetest-engine-multicraft2/issues/49 * it takes from https://github.com/MultiCraft/MultiCraft2/pull/50 * backported from "Add platform information to get_player_information"
This commit is contained in:
parent
b9971da87a
commit
0edc870820
@ -4087,7 +4087,9 @@ Utilities
|
|||||||
major = 5, -- major version number
|
major = 5, -- major version number
|
||||||
minor = 2, -- minor version number
|
minor = 2, -- minor version number
|
||||||
patch = 1, -- patch 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
|
state = "Active" -- current client state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1244,13 +1244,21 @@ 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();
|
||||||
|
|
||||||
NetworkPacket pkt(TOSERVER_CLIENT_READY,
|
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
|
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());
|
||||||
pkt << (u16)FORMSPEC_API_VERSION;
|
pkt << (u16)FORMSPEC_API_VERSION;
|
||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
@ -332,7 +332,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 */
|
||||||
@ -340,6 +346,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; }
|
||||||
const std::string &getFull() const { return m_full_version; }
|
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:
|
private:
|
||||||
// Version is stored in here after INIT before INIT2
|
// Version is stored in here after INIT before INIT2
|
||||||
u8 m_pending_serialization_version = SER_FMT_VER_INVALID;
|
u8 m_pending_serialization_version = SER_FMT_VER_INVALID;
|
||||||
@ -413,6 +421,8 @@ private:
|
|||||||
u8 m_version_patch = 0;
|
u8 m_version_patch = 0;
|
||||||
|
|
||||||
std::string m_full_version = "unknown";
|
std::string m_full_version = "unknown";
|
||||||
|
std::string m_platform = "unknown";
|
||||||
|
std::string m_sysinfo = "unknown";
|
||||||
|
|
||||||
u16 m_deployed_compression = 0;
|
u16 m_deployed_compression = 0;
|
||||||
|
|
||||||
|
@ -935,6 +935,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,
|
||||||
|
@ -162,7 +162,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)) { \
|
||||||
@ -182,7 +184,7 @@ int ModApiServer::l_get_player_information(lua_State *L)
|
|||||||
&avg_jitter))
|
&avg_jitter))
|
||||||
|
|
||||||
ERET(getServer(L)->getClientInfo(player->getPeerId(), &state, &uptime, &ser_vers,
|
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);
|
lua_newtable(L);
|
||||||
int table = lua_gettop(L);
|
int table = lua_gettop(L);
|
||||||
@ -254,7 +256,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");
|
||||||
|
@ -1263,7 +1263,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);
|
||||||
@ -1282,7 +1284,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();
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ public:
|
|||||||
bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
|
bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
|
||||||
bool getClientInfo(session_t peer_id, ClientState *state, u32 *uptime,
|
bool getClientInfo(session_t 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);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user