1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Cleanup client init states by bumping protocol version

Don't use TOSERVER_RECEIVED_MEDIA but TOSERVER_CLIENT_READY as indicatio for client ready
Handle clients with protocol version < 23 (almost) same way as before
Make client tell server about it's version
Add client state to not send bogus player position updates prior init complete
Add access to statistics information (peer connction time,rtt,version)
Fix clients standing stalled in world while preloading item visuals (new clients only)
Add get_player_information to read client specific information from lua
This commit is contained in:
sapier 2014-02-13 20:17:42 +01:00
parent 556bdc260a
commit 142e2d3b74
15 changed files with 625 additions and 144 deletions

View file

@ -99,7 +99,7 @@ int ModApiServer::l_get_player_ip(lua_State *L)
}
try
{
Address addr = getServer(L)->getPeerAddress(getEnv(L)->getPlayer(name)->peer_id);
Address addr = getServer(L)->getPeerAddress(player->peer_id);
std::string ip_str = addr.serializeString();
lua_pushstring(L, ip_str.c_str());
return 1;
@ -112,6 +112,135 @@ int ModApiServer::l_get_player_ip(lua_State *L)
}
}
// get_player_information()
int ModApiServer::l_get_player_information(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); // no such player
return 1;
}
Address addr;
try
{
addr = getServer(L)->getPeerAddress(player->peer_id);
}
catch(con::PeerNotFoundException) // unlikely
{
dstream << __FUNCTION_NAME << ": peer was not found" << std::endl;
lua_pushnil(L); // error
return 1;
}
float min_rtt,max_rtt,avg_rtt,min_jitter,max_jitter,avg_jitter;
ClientState state;
u32 uptime;
u16 prot_vers;
u8 ser_vers,major,minor,patch;
std::string vers_string;
#define ERET(code) \
if (!(code)) { \
dstream << __FUNCTION_NAME << ": peer was not found" << std::endl; \
lua_pushnil(L); /* error */ \
return 1; \
}
ERET(getServer(L)->getClientConInfo(player->peer_id,con::MIN_RTT,&min_rtt))
ERET(getServer(L)->getClientConInfo(player->peer_id,con::MAX_RTT,&max_rtt))
ERET(getServer(L)->getClientConInfo(player->peer_id,con::AVG_RTT,&avg_rtt))
ERET(getServer(L)->getClientConInfo(player->peer_id,con::MIN_JITTER,&min_jitter))
ERET(getServer(L)->getClientConInfo(player->peer_id,con::MAX_JITTER,&max_jitter))
ERET(getServer(L)->getClientConInfo(player->peer_id,con::AVG_JITTER,&avg_jitter))
ERET(getServer(L)->getClientInfo(player->peer_id,
&state, &uptime, &ser_vers, &prot_vers,
&major, &minor, &patch, &vers_string))
lua_newtable(L);
int table = lua_gettop(L);
lua_pushstring(L,"address");
lua_pushstring(L, addr.serializeString().c_str());
lua_settable(L, table);
lua_pushstring(L,"ip_version");
if (addr.getFamily() == AF_INET) {
lua_pushnumber(L, 4);
} else if (addr.getFamily() == AF_INET6) {
lua_pushnumber(L, 6);
} else {
lua_pushnumber(L, 0);
}
lua_settable(L, table);
lua_pushstring(L,"min_rtt");
lua_pushnumber(L, min_rtt);
lua_settable(L, table);
lua_pushstring(L,"max_rtt");
lua_pushnumber(L, max_rtt);
lua_settable(L, table);
lua_pushstring(L,"avg_rtt");
lua_pushnumber(L, avg_rtt);
lua_settable(L, table);
lua_pushstring(L,"min_jitter");
lua_pushnumber(L, min_jitter);
lua_settable(L, table);
lua_pushstring(L,"max_jitter");
lua_pushnumber(L, max_jitter);
lua_settable(L, table);
lua_pushstring(L,"avg_jitter");
lua_pushnumber(L, avg_jitter);
lua_settable(L, table);
lua_pushstring(L,"connection_uptime");
lua_pushnumber(L, uptime);
lua_settable(L, table);
#ifndef NDEBUG
lua_pushstring(L,"serialization_version");
lua_pushnumber(L, ser_vers);
lua_settable(L, table);
lua_pushstring(L,"protocol_version");
lua_pushnumber(L, prot_vers);
lua_settable(L, table);
lua_pushstring(L,"major");
lua_pushnumber(L, major);
lua_settable(L, table);
lua_pushstring(L,"minor");
lua_pushnumber(L, minor);
lua_settable(L, table);
lua_pushstring(L,"patch");
lua_pushnumber(L, patch);
lua_settable(L, table);
lua_pushstring(L,"version_string");
lua_pushstring(L, vers_string.c_str());
lua_settable(L, table);
lua_pushstring(L,"state");
lua_pushstring(L,ClientInterface::state2Name(state).c_str());
lua_settable(L, table);
#endif
#undef ERET
return 1;
}
// get_ban_list()
int ModApiServer::l_get_ban_list(lua_State *L)
{
@ -343,6 +472,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(sound_play);
API_FCT(sound_stop);
API_FCT(get_player_information);
API_FCT(get_player_privs);
API_FCT(get_player_ip);
API_FCT(get_ban_list);

View file

@ -67,6 +67,9 @@ private:
// get_player_ip()
static int l_get_player_ip(lua_State *L);
// get_player_information()
static int l_get_player_information(lua_State *L);
// get_ban_list()
static int l_get_ban_list(lua_State *L);