mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Expose client version information in non-debug builds (#15708)
Co-authored-by: SmallJoker <SmallJoker@users.noreply.github.com> Co-authored-by: Lars Mueller <appgurulars@gmx.de> Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
e6cf08169e
commit
dd0070a6b8
8 changed files with 95 additions and 24 deletions
|
@ -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"}},
|
||||
}
|
||||
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
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.is_dev) == "boolean")
|
||||
if version.is_dev then
|
||||
assert(type(version.hash) == "string")
|
||||
else
|
||||
assert(version.hash == nil)
|
||||
end
|
||||
end)
|
|
@ -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")
|
||||
|
|
40
games/devtest/mods/unittests/version.lua
Normal file
40
games/devtest/mods/unittests/version.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
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.is_dev) == "boolean")
|
||||
if version.is_dev then
|
||||
assert(type(version.hash) == "string")
|
||||
else
|
||||
assert(version.hash == nil)
|
||||
end
|
||||
end)
|
||||
|
||||
unittests.register("test_protocol_version", function(player)
|
||||
local info = core.get_player_information(player:get_player_name())
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
-- 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})
|
Loading…
Add table
Add a link
Reference in a new issue