From 3b8dfab9f530bcca36d0d3b5abb428ff9045b065 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 24 Jan 2025 16:28:31 +0100 Subject: [PATCH 01/17] Explose client version information in non-debug builds --- doc/lua_api.md | 16 ++++++++++------ src/script/lua_api/l_server.cpp | 10 +++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 0cc797a069c7c..e4b542ee2016b 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5716,14 +5716,18 @@ Utilities min_jitter = 0.01, -- minimum packet time jitter max_jitter = 0.5, -- maximum packet time jitter avg_jitter = 0.03, -- average packet time jitter + + -- The version information is provided by the client and may be spoofed or + -- inconsistent in engine forks. Only use if other information isn't enough. + major = 0, -- major version number + minor = 4, -- minor version number + patch = 10, -- patch version number + version_string = "0.4.9-git", -- full version string + -- the following information is available in a debug build only!!! -- DO NOT USE IN MODS - --serialization_version = 26, -- serialization version used by client - --major = 0, -- major version number - --minor = 4, -- minor version number - --patch = 10, -- patch version number - --version_string = "0.4.9-git", -- full version string - --state = "Active" -- current client state + serialization_version = 26, -- serialization version used by client + state = "Active" -- current client state } ``` diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 061dbb206ffbc..32beffe156e62 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -239,11 +239,6 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushstring(L, info.lang_code.c_str()); lua_settable(L, table); -#ifndef NDEBUG - lua_pushstring(L,"serialization_version"); - lua_pushnumber(L, info.ser_vers); - lua_settable(L, table); - lua_pushstring(L,"major"); lua_pushnumber(L, info.major); lua_settable(L, table); @@ -260,6 +255,11 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushstring(L, info.vers_string.c_str()); lua_settable(L, table); +#ifndef NDEBUG + lua_pushstring(L,"serialization_version"); + lua_pushnumber(L, info.ser_vers); + lua_settable(L, table); + lua_pushstring(L,"state"); lua_pushstring(L, ClientInterface::state2Name(info.state).c_str()); lua_settable(L, table); From 1acfbbef930871dccd5162e9667b2a871341dd47 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 24 Jan 2025 16:35:46 +0100 Subject: [PATCH 02/17] trim trailing whitespace --- doc/lua_api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index e4b542ee2016b..4e8c6b1ed762c 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5716,7 +5716,7 @@ Utilities min_jitter = 0.01, -- minimum packet time jitter max_jitter = 0.5, -- maximum packet time jitter avg_jitter = 0.03, -- average packet time jitter - + -- The version information is provided by the client and may be spoofed or -- inconsistent in engine forks. Only use if other information isn't enough. major = 0, -- major version number From 7d137ef585960cfcceb1857f36937bd3d296e3b6 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 24 Jan 2025 16:51:53 +0100 Subject: [PATCH 03/17] Better wording --- doc/lua_api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 4e8c6b1ed762c..e00cbb7036fad 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5718,7 +5718,8 @@ Utilities avg_jitter = 0.03, -- average packet time jitter -- The version information is provided by the client and may be spoofed or - -- inconsistent in engine forks. Only use if other information isn't enough. + -- inconsistent in engine forks. You should use the protocol_version value -- instead for checking feature availability of clients. + -- Use this ONLY as a last resort! major = 0, -- major version number minor = 4, -- minor version number patch = 10, -- patch version number From 696176303e280536cea76927b9fe24d9c622a569 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 24 Jan 2025 16:55:48 +0100 Subject: [PATCH 04/17] Update lua_api.md --- doc/lua_api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index e00cbb7036fad..5d6954bafc381 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5718,7 +5718,8 @@ Utilities avg_jitter = 0.03, -- average packet time jitter -- The version information is provided by the client and may be spoofed or - -- inconsistent in engine forks. You should use the protocol_version value -- instead for checking feature availability of clients. + -- inconsistent in engine forks. You should use the protocol_version value + -- instead for checking feature availability of clients. -- Use this ONLY as a last resort! major = 0, -- major version number minor = 4, -- minor version number From fa4397d979f72fab96cb3532210c07f85a56db5d Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Fri, 24 Jan 2025 17:02:01 +0100 Subject: [PATCH 05/17] More wording update --- doc/lua_api.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 5d6954bafc381..ed3718b6912d2 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5718,9 +5718,10 @@ Utilities avg_jitter = 0.03, -- average packet time jitter -- The version information is provided by the client and may be spoofed or - -- inconsistent in engine forks. You should use the protocol_version value - -- instead for checking feature availability of clients. - -- Use this ONLY as a last resort! + -- inconsistent in engine forks. You must not use this for checking + -- feature availability of clients, please use protocol_version whenever + -- it is possible. + -- Use this ONLY as a last resort!!! major = 0, -- major version number minor = 4, -- minor version number patch = 10, -- patch version number From 1f0f872911e4df6c5bcd88ca19d8ffbdc8cce602 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Mon, 27 Jan 2025 18:21:14 +0100 Subject: [PATCH 06/17] Update doc/lua_api.md Co-authored-by: SmallJoker --- doc/lua_api.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index ed3718b6912d2..8d4dce45731c2 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5719,9 +5719,9 @@ Utilities -- The version information is provided by the client and may be spoofed or -- inconsistent in engine forks. You must not use this for checking - -- feature availability of clients, please use protocol_version whenever - -- it is possible. - -- Use this ONLY as a last resort!!! + -- feature availability of clients. Instead, do use the fields + -- `protocol_version` and `formspec_version` where it matters. + -- These version fields may only be used for analysis purposes. major = 0, -- major version number minor = 4, -- minor version number patch = 10, -- patch version number From f833477e75868bf8b62d6cd2b4da7aa4b764093c Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Mon, 27 Jan 2025 18:22:58 +0100 Subject: [PATCH 07/17] Move back everything but version_string behind debug check --- src/script/lua_api/l_server.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 32beffe156e62..602e2b0fe746d 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -239,6 +239,15 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushstring(L, info.lang_code.c_str()); lua_settable(L, table); + lua_pushstring(L,"version_string"); + lua_pushstring(L, info.vers_string.c_str()); + lua_settable(L, table); + +#ifndef NDEBUG + lua_pushstring(L,"serialization_version"); + lua_pushnumber(L, info.ser_vers); + lua_settable(L, table); + lua_pushstring(L,"major"); lua_pushnumber(L, info.major); lua_settable(L, table); @@ -251,15 +260,6 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushnumber(L, info.patch); lua_settable(L, table); - lua_pushstring(L,"version_string"); - lua_pushstring(L, info.vers_string.c_str()); - lua_settable(L, table); - -#ifndef NDEBUG - lua_pushstring(L,"serialization_version"); - lua_pushnumber(L, info.ser_vers); - lua_settable(L, table); - lua_pushstring(L,"state"); lua_pushstring(L, ClientInterface::state2Name(info.state).c_str()); lua_settable(L, table); From 69ce690649d4e455cf9635a593cb9a83d84dd873 Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Mon, 27 Jan 2025 18:24:55 +0100 Subject: [PATCH 08/17] update docs to go along --- doc/lua_api.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 8d4dce45731c2..ebe86555867bf 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5717,19 +5717,19 @@ Utilities max_jitter = 0.5, -- maximum packet time jitter avg_jitter = 0.03, -- average packet time jitter - -- The version information is provided by the client and may be spoofed or - -- inconsistent in engine forks. You must not use this for checking + -- The version information is provided by the client and may be spoofed + -- or inconsistent in engine forks. You must not use this for checking -- feature availability of clients. Instead, do use the fields -- `protocol_version` and `formspec_version` where it matters. - -- These version fields may only be used for analysis purposes. - major = 0, -- major version number - minor = 4, -- minor version number - patch = 10, -- patch version number + -- This version string may only be used for analysis purposes. version_string = "0.4.9-git", -- full version string -- the following information is available in a debug build only!!! -- DO NOT USE IN MODS serialization_version = 26, -- serialization version used by client + major = 0, -- major version number + minor = 4, -- minor version number + patch = 10, -- patch version number state = "Active" -- current client state } ``` From 4f0ea4aa3e481e670ced3e2a1d62e62c9535abbb Mon Sep 17 00:00:00 2001 From: ROllerozxa Date: Mon, 27 Jan 2025 18:25:57 +0100 Subject: [PATCH 09/17] put them back as comments --- doc/lua_api.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index ebe86555867bf..a0b3f84b4228e 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5726,11 +5726,11 @@ Utilities -- the following information is available in a debug build only!!! -- DO NOT USE IN MODS - serialization_version = 26, -- serialization version used by client - major = 0, -- major version number - minor = 4, -- minor version number - patch = 10, -- patch version number - state = "Active" -- current client state + --serialization_version = 26, -- serialization version used by client + --major = 0, -- major version number + --minor = 4, -- minor version number + --patch = 10, -- patch version number + --state = "Active" -- current client state } ``` From 953bb875542811e7084c9ac6dbdb0a743cd1969d Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sat, 8 Feb 2025 13:32:12 +0100 Subject: [PATCH 10/17] Add `core.protocol_versions` for modder convenience --- builtin/game/init.lua | 1 + builtin/game/protocol_versions.lua | 16 ++++++++++++++++ doc/lua_api.md | 8 ++++++++ src/network/networkprotocol.cpp | 1 + 4 files changed, 26 insertions(+) create mode 100644 builtin/game/protocol_versions.lua diff --git a/builtin/game/init.lua b/builtin/game/init.lua index b3c64e72955a6..2b574182291f4 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -8,6 +8,7 @@ local gamepath = scriptpath .. "game".. DIR_DELIM local builtin_shared = {} dofile(gamepath .. "constants.lua") +dofile(gamepath .. "protocol_versions.lua") assert(loadfile(commonpath .. "item_s.lua"))(builtin_shared) assert(loadfile(gamepath .. "item.lua"))(builtin_shared) assert(loadfile(commonpath .. "register.lua"))(builtin_shared) diff --git a/builtin/game/protocol_versions.lua b/builtin/game/protocol_versions.lua new file mode 100644 index 0000000000000..9a85c48f4c272 --- /dev/null +++ b/builtin/game/protocol_versions.lua @@ -0,0 +1,16 @@ +-- c.f. https://content.luanti.org/api/minetest_versions/ +-- see also src/network/networkprotocol.cpp +core.protocol_versions = { + ["5.0"] = 37, + ["5.1"] = 38, + ["5.2"] = 39, + ["5.3"] = 39, + ["5.4"] = 39, + ["5.5"] = 40, + ["5.6"] = 41, + ["5.7"] = 42, + ["5.8"] = 43, + ["5.9"] = 44, + ["5.10"] = 46, + ["5.11"] = 47, +} diff --git a/doc/lua_api.md b/doc/lua_api.md index a0b3f84b4228e..00a9ea32c6465 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5721,6 +5721,7 @@ Utilities -- or inconsistent in engine forks. You must not use this for checking -- feature availability of clients. Instead, do use the fields -- `protocol_version` and `formspec_version` where it matters. + -- You can use `core.protocol_versions` to map Luanti versions to protocol versions. -- This version string may only be used for analysis purposes. version_string = "0.4.9-git", -- full version string @@ -5734,6 +5735,13 @@ Utilities } ``` +* `core.protocol_versions`: + * Table mapping minor Luanti 5.x versions to + corresponding protocol versions for modder convenience. + * For example, to check whether a client has at least the feature set + of Luanti 5.8 or newer, you could do: + `core.get_player_information(player_name).protocol_version >= core.protocol_versions["5.8"]` + * Available since 5.11 * `core.get_player_window_information(player_name)`: ```lua diff --git a/src/network/networkprotocol.cpp b/src/network/networkprotocol.cpp index f77e85d3cb99d..456ec0025f660 100644 --- a/src/network/networkprotocol.cpp +++ b/src/network/networkprotocol.cpp @@ -64,6 +64,7 @@ [scheduled bump for 5.11.0] */ +// Note: Also update builtin/game/protocol_versions.lua when bumping const u16 LATEST_PROTOCOL_VERSION = 47; // See also formspec [Version History] in doc/lua_api.md From 94c281d9e87c4e8adf7fa8f3b32a255bab1deb49 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sun, 9 Feb 2025 16:03:29 +0100 Subject: [PATCH 11/17] Make explicit that `core.features` / `core.has_feature` is server-side --- doc/lua_api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 00a9ea32c6465..1beb4ab5ddb3e 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5580,7 +5580,7 @@ Utilities * It's possible that multiple Luanti instances are running at the same time, which may lead to corruption if you are not careful. * `core.is_singleplayer()` -* `core.features`: Table containing API feature flags +* `core.features`: Table containing *server-side* API feature flags ```lua { @@ -5695,6 +5695,7 @@ Utilities ``` * `core.has_feature(arg)`: returns `boolean, missing_features` + * checks for *server-side* feature availability * `arg`: string or table in format `{foo=true, bar=true}` * `missing_features`: `{foo=true, bar=true}` * `core.get_player_information(player_name)`: Table containing information From 24cca6986947477bb315668cadc0b3f648bbe403 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sun, 9 Feb 2025 16:20:22 +0100 Subject: [PATCH 12/17] Add protocol version unit test --- games/devtest/.luacheckrc | 2 +- games/devtest/mods/unittests/init.lua | 2 +- .../mods/unittests/{get_version.lua => version.lua} | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) rename games/devtest/mods/unittests/{get_version.lua => version.lua} (62%) diff --git a/games/devtest/.luacheckrc b/games/devtest/.luacheckrc index c5a7119a4c56a..2ef36d2095108 100644 --- a/games/devtest/.luacheckrc +++ b/games/devtest/.luacheckrc @@ -31,7 +31,7 @@ read_globals = { "PcgRandom", string = {fields = {"split", "trim"}}, - table = {fields = {"copy", "getn", "indexof", "insert_all"}}, + table = {fields = {"copy", "getn", "indexof", "insert_all", "key_value_swap"}}, math = {fields = {"hypot", "round"}}, } diff --git a/games/devtest/mods/unittests/init.lua b/games/devtest/mods/unittests/init.lua index a971632c95bfd..22057f26a0f8c 100644 --- a/games/devtest/mods/unittests/init.lua +++ b/games/devtest/mods/unittests/init.lua @@ -192,7 +192,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 .. "/version.lua") dofile(modpath .. "/itemstack_equals.lua") dofile(modpath .. "/content_ids.lua") dofile(modpath .. "/metadata.lua") diff --git a/games/devtest/mods/unittests/get_version.lua b/games/devtest/mods/unittests/version.lua similarity index 62% rename from games/devtest/mods/unittests/get_version.lua rename to games/devtest/mods/unittests/version.lua index 9903ac381bb7e..ed9a420b8448a 100644 --- a/games/devtest/mods/unittests/get_version.lua +++ b/games/devtest/mods/unittests/version.lua @@ -1,4 +1,3 @@ - unittests.register("test_get_version", function() local version = core.get_version() assert(type(version) == "table") @@ -14,3 +13,9 @@ unittests.register("test_get_version", function() assert(version.hash == nil) end end) + +unittests.register("test_protocol_versions", function(player) + local info = core.get_player_information(player:get_player_name()) + -- Newest protocol version should be in mapping of protocol versions + assert(table.key_value_swap(core.protocol_versions)[info.protocol_version]) +end, {player = true}) From 3c1920eca4fa5b7a6839d8380f3336e3f46f28f3 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sun, 9 Feb 2025 16:20:37 +0100 Subject: [PATCH 13/17] Add *all* 5.x protocol versions to `core.protocol_versions` --- builtin/game/protocol_versions.lua | 25 +++++++++++++------------ doc/lua_api.md | 13 +++++++++++-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/builtin/game/protocol_versions.lua b/builtin/game/protocol_versions.lua index 9a85c48f4c272..24c465639ab0f 100644 --- a/builtin/game/protocol_versions.lua +++ b/builtin/game/protocol_versions.lua @@ -1,16 +1,17 @@ -- c.f. https://content.luanti.org/api/minetest_versions/ -- see also src/network/networkprotocol.cpp core.protocol_versions = { - ["5.0"] = 37, - ["5.1"] = 38, - ["5.2"] = 39, - ["5.3"] = 39, - ["5.4"] = 39, - ["5.5"] = 40, - ["5.6"] = 41, - ["5.7"] = 42, - ["5.8"] = 43, - ["5.9"] = 44, - ["5.10"] = 46, - ["5.11"] = 47, + ["5.0.0"] = 37, + ["5.1.0"] = 38, + ["5.2.0"] = 39, + ["5.3.0"] = 39, + ["5.4.0"] = 39, + ["5.5.0"] = 40, + ["5.6.0"] = 41, + ["5.7.0"] = 42, + ["5.8.0"] = 43, + ["5.9.0"] = 44, + ["5.9.1"] = 45, + ["5.10.0"] = 46, + ["5.11.0"] = 47, } diff --git a/doc/lua_api.md b/doc/lua_api.md index 1beb4ab5ddb3e..4cf9878eff6e0 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5740,9 +5740,18 @@ Utilities * Table mapping minor Luanti 5.x versions to corresponding protocol versions for modder convenience. * For example, to check whether a client has at least the feature set - of Luanti 5.8 or newer, you could do: - `core.get_player_information(player_name).protocol_version >= core.protocol_versions["5.8"]` + of Luanti 5.8.0 or newer, you could do: + `core.get_player_information(player_name).protocol_version >= core.protocol_versions["5.8.0"]` * Available since 5.11 + + ```lua + { + [version string] = protocol version at time of release + -- every major and minor version has an entry + -- patch versions only for the first release whose protocol version is not already present in the table + } + ``` + * `core.get_player_window_information(player_name)`: ```lua From 9aa8452bce0311c276369640f9082907d516f58e Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 9 Feb 2025 17:46:50 +0100 Subject: [PATCH 14/17] more comprehensive test --- games/devtest/mods/unittests/version.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/games/devtest/mods/unittests/version.lua b/games/devtest/mods/unittests/version.lua index ed9a420b8448a..26f2be663e865 100644 --- a/games/devtest/mods/unittests/version.lua +++ b/games/devtest/mods/unittests/version.lua @@ -14,8 +14,25 @@ unittests.register("test_get_version", function() end end) -unittests.register("test_protocol_versions", function(player) +unittests.register("test_protocol_version", function(player) local info = core.get_player_information(player:get_player_name()) - -- Newest protocol version should be in mapping of protocol versions - assert(table.key_value_swap(core.protocol_versions)[info.protocol_version]) + + local maxver = 0 + for _, v in pairs(core.protocol_versions) do + maxver = math.max(maxver, v) + end + assert(maxver > 0) -- table must contain something valid + + -- If the client is older than a known version then it's pointless. + if info.protocol_version < maxver then + core.log("warning", "test_protocol_version: client is outdated, skipping test!") + return + elseif info.version_string ~= core.get_version().string then + core.log("warning", "test_protocol_version: client is not the same version. False-positive possible.") + end + + -- The protocol version the client and server agreed on must exist in the table. + local match = table.key_value_swap(core.protocol_versions)[info.protocol_version] + assert(match ~= nil) + print(string.format("client proto matched: %s sent: %s", match, info.version_string)) end, {player = true}) From 6f145e13f1a1e7bf1f46aef6d4c75d1db248e8a8 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 9 Feb 2025 17:52:48 +0100 Subject: [PATCH 15/17] style/docs --- builtin/game/init.lua | 1 - builtin/game/misc_s.lua | 20 ++++++++++++++++++++ builtin/game/protocol_versions.lua | 17 ----------------- doc/lua_api.md | 9 ++++----- src/network/networkprotocol.cpp | 2 +- src/script/lua_api/l_server.cpp | 2 +- 6 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 builtin/game/protocol_versions.lua diff --git a/builtin/game/init.lua b/builtin/game/init.lua index 2b574182291f4..b3c64e72955a6 100644 --- a/builtin/game/init.lua +++ b/builtin/game/init.lua @@ -8,7 +8,6 @@ local gamepath = scriptpath .. "game".. DIR_DELIM local builtin_shared = {} dofile(gamepath .. "constants.lua") -dofile(gamepath .. "protocol_versions.lua") assert(loadfile(commonpath .. "item_s.lua"))(builtin_shared) assert(loadfile(gamepath .. "item.lua"))(builtin_shared) assert(loadfile(commonpath .. "register.lua"))(builtin_shared) diff --git a/builtin/game/misc_s.lua b/builtin/game/misc_s.lua index 1e9b6d952fb3b..61d1377ca08ab 100644 --- a/builtin/game/misc_s.lua +++ b/builtin/game/misc_s.lua @@ -112,3 +112,23 @@ if core.set_push_moveresult1 then end) core.set_push_moveresult1 = nil end + +-- Protocol version table +-- see also src/network/networkprotocol.cpp +core.protocol_versions = { + ["5.0.0"] = 37, + ["5.1.0"] = 38, + ["5.2.0"] = 39, + ["5.3.0"] = 39, + ["5.4.0"] = 39, + ["5.5.0"] = 40, + ["5.6.0"] = 41, + ["5.7.0"] = 42, + ["5.8.0"] = 43, + ["5.9.0"] = 44, + ["5.9.1"] = 45, + ["5.10.0"] = 46, + ["5.11.0"] = 47, +} + +setmetatable(core.protocol_versions, {__newindex = function() end}) diff --git a/builtin/game/protocol_versions.lua b/builtin/game/protocol_versions.lua deleted file mode 100644 index 24c465639ab0f..0000000000000 --- a/builtin/game/protocol_versions.lua +++ /dev/null @@ -1,17 +0,0 @@ --- c.f. https://content.luanti.org/api/minetest_versions/ --- see also src/network/networkprotocol.cpp -core.protocol_versions = { - ["5.0.0"] = 37, - ["5.1.0"] = 38, - ["5.2.0"] = 39, - ["5.3.0"] = 39, - ["5.4.0"] = 39, - ["5.5.0"] = 40, - ["5.6.0"] = 41, - ["5.7.0"] = 42, - ["5.8.0"] = 43, - ["5.9.0"] = 44, - ["5.9.1"] = 45, - ["5.10.0"] = 46, - ["5.11.0"] = 47, -} diff --git a/doc/lua_api.md b/doc/lua_api.md index 4cf9878eff6e0..c8f9704977098 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -5722,8 +5722,8 @@ Utilities -- or inconsistent in engine forks. You must not use this for checking -- feature availability of clients. Instead, do use the fields -- `protocol_version` and `formspec_version` where it matters. - -- You can use `core.protocol_versions` to map Luanti versions to protocol versions. - -- This version string may only be used for analysis purposes. + -- Use `core.protocol_versions` to map Luanti versions to protocol versions. + -- This version string is only suitable for analysis purposes. version_string = "0.4.9-git", -- full version string -- the following information is available in a debug build only!!! @@ -5737,12 +5737,11 @@ Utilities ``` * `core.protocol_versions`: - * Table mapping minor Luanti 5.x versions to - corresponding protocol versions for modder convenience. + * Table mapping Luanti versions to corresponding protocol versions for modder convenience. * For example, to check whether a client has at least the feature set of Luanti 5.8.0 or newer, you could do: `core.get_player_information(player_name).protocol_version >= core.protocol_versions["5.8.0"]` - * Available since 5.11 + * (available since 5.11) ```lua { diff --git a/src/network/networkprotocol.cpp b/src/network/networkprotocol.cpp index 456ec0025f660..85096930f59d5 100644 --- a/src/network/networkprotocol.cpp +++ b/src/network/networkprotocol.cpp @@ -64,7 +64,7 @@ [scheduled bump for 5.11.0] */ -// Note: Also update builtin/game/protocol_versions.lua when bumping +// Note: Also update core.protocol_versions in builtin when bumping const u16 LATEST_PROTOCOL_VERSION = 47; // See also formspec [Version History] in doc/lua_api.md diff --git a/src/script/lua_api/l_server.cpp b/src/script/lua_api/l_server.cpp index 602e2b0fe746d..74ee5e5c9a2a3 100644 --- a/src/script/lua_api/l_server.cpp +++ b/src/script/lua_api/l_server.cpp @@ -239,7 +239,7 @@ int ModApiServer::l_get_player_information(lua_State *L) lua_pushstring(L, info.lang_code.c_str()); lua_settable(L, table); - lua_pushstring(L,"version_string"); + lua_pushstring(L, "version_string"); lua_pushstring(L, info.vers_string.c_str()); lua_settable(L, table); From b3ce2ffc268637b0664ee2ccfac0f36ba58b49fb Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sun, 9 Feb 2025 17:54:28 +0100 Subject: [PATCH 16/17] minor --- games/devtest/mods/unittests/version.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/games/devtest/mods/unittests/version.lua b/games/devtest/mods/unittests/version.lua index 26f2be663e865..baf4520a46d4f 100644 --- a/games/devtest/mods/unittests/version.lua +++ b/games/devtest/mods/unittests/version.lua @@ -27,7 +27,9 @@ unittests.register("test_protocol_version", function(player) if info.protocol_version < maxver then core.log("warning", "test_protocol_version: client is outdated, skipping test!") return - elseif info.version_string ~= core.get_version().string then + end + local info_server = core.get_version() + if info.version_string ~= (info_server.hash or info_server.string) then core.log("warning", "test_protocol_version: client is not the same version. False-positive possible.") end From 5914c38779e0be007f49f703369250d1c44aa4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sun, 9 Feb 2025 18:04:49 +0100 Subject: [PATCH 17/17] error on attempt to add entry to `core.protocol_versions` --- builtin/game/misc_s.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/game/misc_s.lua b/builtin/game/misc_s.lua index 61d1377ca08ab..e64134e150b94 100644 --- a/builtin/game/misc_s.lua +++ b/builtin/game/misc_s.lua @@ -131,4 +131,6 @@ core.protocol_versions = { ["5.11.0"] = 47, } -setmetatable(core.protocol_versions, {__newindex = function() end}) +setmetatable(core.protocol_versions, {__newindex = function() + error("core.protocol_versions is read-only") +end})