aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api/l_server.cpp
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2014-02-13 20:17:42 +0100
committersapier <Sapier at GMX dot net>2014-04-08 21:12:20 +0200
commit142e2d3b74ad886eed83b0fc9d6cfea100dae10a (patch)
tree869bd3599c590e062bc838013b83088280734a81 /src/script/lua_api/l_server.cpp
parent556bdc260a6938ddab8db22e2ebc4033ec3757eb (diff)
downloadminetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.tar.gz
minetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.tar.bz2
minetest-142e2d3b74ad886eed83b0fc9d6cfea100dae10a.zip
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
Diffstat (limited to 'src/script/lua_api/l_server.cpp')
-rw-r--r--src/script/lua_api/l_server.cpp132
1 files changed, 131 insertions, 1 deletions
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);