From 65692ad1b556c4e7b7e815e24270c869e8c20adf Mon Sep 17 00:00:00 2001 From: Buckaroo Banzai <39065740+BuckarooBanzay@users.noreply.github.com> Date: Sat, 6 May 2023 17:16:21 +0200 Subject: [PATCH] Add min/max protocol version to `minetest.get_version()` (#13482) --- doc/lua_api.md | 2 ++ games/devtest/mods/unittests/get_version.lua | 12 ++++++++++++ games/devtest/mods/unittests/init.lua | 1 + src/script/lua_api/l_util.cpp | 7 +++++++ 4 files changed, 22 insertions(+) create mode 100644 games/devtest/mods/unittests/get_version.lua diff --git a/doc/lua_api.md b/doc/lua_api.md index 8a6e4ef15..ba19c1e9c 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5159,6 +5159,8 @@ Utilities engine version. Components: * `project`: Name of the project, eg, "Minetest" * `string`: Simple version, eg, "1.2.3-dev" + * `proto_min`: The minimum supported protocol version + * `proto_max`: The maximum supported protocol version * `hash`: Full git version (only set if available), eg, "1.2.3-dev-01234567-dirty". * `is_dev`: Boolean value indicating whether it's a development build diff --git a/games/devtest/mods/unittests/get_version.lua b/games/devtest/mods/unittests/get_version.lua new file mode 100644 index 000000000..99ddcfde6 --- /dev/null +++ b/games/devtest/mods/unittests/get_version.lua @@ -0,0 +1,12 @@ + +unittests.register("test_get_version", function() + local version = core.get_version() + assert(type(version) == "table") + assert(type(version.project) == "string") + assert(type(version.string) == "string") + assert(type(version.proto_min) == "number") + assert(type(version.proto_max) == "number") + assert(version.proto_max >= version.proto_min) + assert(type(version.hash) == "string") + assert(type(version.is_dev) == "boolean") +end) diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua index 8e51b6d3d..edba2c3d2 100644 --- a/games/devtest/mods/unittests/init.lua +++ b/games/devtest/mods/unittests/init.lua @@ -178,6 +178,7 @@ dofile(modpath .. "/crafting.lua") dofile(modpath .. "/itemdescription.lua") dofile(modpath .. "/async_env.lua") dofile(modpath .. "/entity.lua") +dofile(modpath .. "/get_version.lua") dofile(modpath .. "/itemstack_equals.lua") dofile(modpath .. "/content_ids.lua") dofile(modpath .. "/metadata.lua") diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp index 0d9883bf7..2846f7b3a 100644 --- a/src/script/lua_api/l_util.cpp +++ b/src/script/lua_api/l_util.cpp @@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "common/c_converter.h" #include "common/c_content.h" #include "cpp_api/s_async.h" +#include "network/networkprotocol.h" #include "serialization.h" #include #include @@ -527,6 +528,12 @@ int ModApiUtil::l_get_version(lua_State *L) lua_pushstring(L, g_version_string); lua_setfield(L, table, "string"); + lua_pushnumber(L, SERVER_PROTOCOL_VERSION_MIN); + lua_setfield(L, table, "proto_min"); + + lua_pushnumber(L, SERVER_PROTOCOL_VERSION_MAX); + lua_setfield(L, table, "proto_max"); + if (strcmp(g_version_string, g_version_hash) != 0) { lua_pushstring(L, g_version_hash); lua_setfield(L, table, "hash");