Add min/max protocol version to minetest.get_version() (#13482)

This commit is contained in:
Buckaroo Banzai 2023-05-06 17:16:21 +02:00 committed by GitHub
parent bc4fc6d648
commit 65692ad1b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

@ -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

@ -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)

@ -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")

@ -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 <json/json.h>
#include <zstd.h>
@ -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");