From 142e2d3b74ad886eed83b0fc9d6cfea100dae10a Mon Sep 17 00:00:00 2001 From: sapier Date: Thu, 13 Feb 2014 20:17:42 +0100 Subject: 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 --- src/script/lua_api/l_server.cpp | 132 +++++++++++++++++++++++++++++++++++++++- src/script/lua_api/l_server.h | 3 + 2 files changed, 134 insertions(+), 1 deletion(-) (limited to 'src/script/lua_api') diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index bbf5a707d..531d044ef 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -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); diff --git a/src/script/lua_api/l_server.h b/src/script/lua_api/l_server.h index 0d0aa45c8..4101f2856 100644 --- a/src/script/lua_api/l_server.h +++ b/src/script/lua_api/l_server.h @@ -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); -- cgit v1.2.3