Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose client version information in non-debug builds #15708

Merged
merged 17 commits into from
Feb 9, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builtin/game/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions builtin/game/protocol_versions.lua
Original file line number Diff line number Diff line change
@@ -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,
}
17 changes: 16 additions & 1 deletion doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5716,17 +5716,32 @@ 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. 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

-- 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
}
```

* `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
Expand Down
1 change: 1 addition & 0 deletions src/network/networkprotocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/script/lua_api/l_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ 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);
Expand All @@ -256,10 +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);

lua_pushstring(L,"state");
lua_pushstring(L, ClientInterface::state2Name(info.state).c_str());
lua_settable(L, table);
Expand Down
Loading