[CSM] Add function to get the server protocol version. (#5529)
authorred-001 <red-001@outlook.ie>
Thu, 6 Apr 2017 20:50:45 +0000 (21:50 +0100)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Thu, 6 Apr 2017 20:50:45 +0000 (22:50 +0200)
clientmods/preview/init.lua
doc/client_lua_api.md
src/script/lua_api/l_client.cpp
src/script/lua_api/l_client.h

index 07464e9271f5b282846fa263810c523107e0f3c1..3c96fae555e7203f03460cb1e1cc0be179a71570 100644 (file)
@@ -69,6 +69,7 @@ core.after(2, function()
        print("[PREVIEW] loaded " .. modname .. " mod")
        modstorage:set_string("current_mod", modname)
        print(modstorage:get_string("current_mod"))
+       print("Server version:" .. core.get_protocol_version())
        preview_minimap()
 end)
 
index 25055c98a9d47d5d5926b82444fad5ba5d2ebf11..6d62de8a2eceff66cd698e0cd9c073b43b8e5ed4 100644 (file)
@@ -696,6 +696,9 @@ Call these functions only at load time!
 * `minetest.disconnect()`
     * Disconnect from the server and exit to main menu.
     * Returns `false` if the client is already disconnecting otherwise returns `true`.
+* `minetest.get_protocol_version()`
+    * Returns the protocol version of the server.
+    * Might not be accurate at start up as the client might not be connected to the server yet, in that case it will return 0.
 
 ### Misc.
 * `minetest.parse_json(string[, nullvalue])`: returns something
index 458c1d1f48e2005816825dadcfa148282638fd93..0f4d7eaae4a5bfc58334f53cd6b2999f3e40b3b4 100644 (file)
@@ -234,6 +234,13 @@ int ModApiClient::l_sound_stop(lua_State *L)
        return 0;
 }
 
+// get_protocol_version()
+int ModApiClient::l_get_protocol_version(lua_State *L)
+{
+       lua_pushinteger(L, getClient(L)->getProtoVersion());
+       return 1;
+}
+
 void ModApiClient::Initialize(lua_State *L, int top)
 {
        API_FCT(get_current_modname);
@@ -251,4 +258,5 @@ void ModApiClient::Initialize(lua_State *L, int top)
        API_FCT(get_meta);
        API_FCT(sound_play);
        API_FCT(sound_stop);
+       API_FCT(get_protocol_version);
 }
index 4e7f63d6a639957bc5e8d874e86f67a4be974abe..478b8ed6c20d917697d37512b5e51cb1c78abf4f 100644 (file)
@@ -69,6 +69,9 @@ private:
 
        static int l_sound_stop(lua_State *L);
 
+       // get_protocol_version()
+       static int l_get_protocol_version(lua_State *L);
+
 public:
        static void Initialize(lua_State *L, int top);
 };