diff options
author | est31 <MTest31@outlook.com> | 2015-02-17 01:37:14 +0100 |
---|---|---|
committer | Loic Blot <loic.blot@unix-experience.fr> | 2015-02-18 16:09:59 +0100 |
commit | 5a0ed780f56a5225b3d7c5f64099586e390e5f39 (patch) | |
tree | 8d027371f69fab8b3b3893841b3663d2a0411d22 /src | |
parent | 8941ea0cc9ae899c8e43743c7a4efc7e9db9c489 (diff) | |
download | minetest-5a0ed780f56a5225b3d7c5f64099586e390e5f39.tar.gz minetest-5a0ed780f56a5225b3d7c5f64099586e390e5f39.tar.bz2 minetest-5a0ed780f56a5225b3d7c5f64099586e390e5f39.zip |
Server: announce MIN/MAX protocol version supported to serverlist. Client: check serverlist
Client now informs about incompatible servers from the list, this permits to prevent the protocol movements.
Server announces its supported protocol versions to master server
Diffstat (limited to 'src')
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 28 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 6 | ||||
-rw-r--r-- | src/serverlist.cpp | 11 |
3 files changed, 43 insertions, 2 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 0d8365106..2bed2a255 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -472,6 +472,7 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) for (unsigned int i = 0; i < servers.size(); i++) { + lua_pushnumber(L,index); lua_newtable(L); @@ -509,6 +510,18 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) lua_settable(L, top_lvl2); } + if (servers[i]["proto_min"].asString().size()) { + lua_pushstring(L,"proto_min"); + lua_pushinteger(L,servers[i]["proto_min"].asInt()); + lua_settable(L, top_lvl2); + } + + if (servers[i]["proto_max"].asString().size()) { + lua_pushstring(L,"proto_max"); + lua_pushinteger(L,servers[i]["proto_max"].asInt()); + lua_settable(L, top_lvl2); + } + if (servers[i]["password"].asString().size()) { lua_pushstring(L,"password"); lua_pushboolean(L,servers[i]["password"].asBool()); @@ -1083,6 +1096,19 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L) } /******************************************************************************/ +int ModApiMainMenu::l_get_min_supp_proto(lua_State *L) +{ + lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MIN); + return 1; +} + +int ModApiMainMenu::l_get_max_supp_proto(lua_State *L) +{ + lua_pushinteger(L, CLIENT_PROTOCOL_VERSION_MAX); + return 1; +} + +/******************************************************************************/ int ModApiMainMenu::l_do_async_callback(lua_State *L) { GUIEngine* engine = getGuiEngine(L); @@ -1142,6 +1168,8 @@ void ModApiMainMenu::Initialize(lua_State *L, int top) API_FCT(gettext); API_FCT(get_video_drivers); API_FCT(get_screen_info); + API_FCT(get_min_supp_proto); + API_FCT(get_max_supp_proto); API_FCT(do_async_callback); } diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index ff61dd97a..8b21a93aa 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -137,6 +137,12 @@ private: static int l_get_video_drivers(lua_State *L); + //version compatibility + static int l_get_min_supp_proto(lua_State *L); + + static int l_get_max_supp_proto(lua_State *L); + + // async static int l_do_async_callback(lua_State *L); diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 472a6b85c..a3353340e 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "filesys.h" #include "porting.h" #include "log.h" +#include "network/networkprotocol.h" #include "json/json.h" #include "convert_json.h" #include "httpfetch.h" @@ -67,8 +68,11 @@ std::vector<ServerListSpec> getLocal() std::vector<ServerListSpec> getOnline() { - Json::Value root = fetchJsonValue( - (g_settings->get("serverlist_url") + "/list").c_str(), NULL); + std::ostringstream geturl; + geturl << g_settings->get("serverlist_url") << + "/list?proto_version_min=" << CLIENT_PROTOCOL_VERSION_MIN << + "&proto_version_max=" << CLIENT_PROTOCOL_VERSION_MAX; + Json::Value root = fetchJsonValue(geturl.str(), NULL); std::vector<ServerListSpec> server_list; @@ -205,9 +209,12 @@ void sendAnnounce(const std::string &action, server["address"] = g_settings->get("server_address"); } if (action != "delete") { + bool strict_checking = g_settings->getBool("strict_protocol_version_checking"); server["name"] = g_settings->get("server_name"); server["description"] = g_settings->get("server_description"); server["version"] = minetest_version_simple; + server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MIN; + server["proto_max"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MAX; server["url"] = g_settings->get("server_url"); server["creative"] = g_settings->getBool("creative_mode"); server["damage"] = g_settings->getBool("enable_damage"); |