Skip to content

Commit

Permalink
Manually configurable minimum protocol version
Browse files Browse the repository at this point in the history
Partially address #13483.  Server operators can set a minimum
protocol version to match the game requirements (or any other
restriction they may want), and it's applied as an additional
constraint on top of the baseline compatiblity range, optional
strict_protocol_version_checking, and any kick-on-join used by
the game/mods.
  • Loading branch information
Warr1024 committed Dec 5, 2023
1 parent 55f40a7 commit 514c086
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
8 changes: 8 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,14 @@ bind_address (Bind address) string
# to new servers, but they may not support all new features that you are expecting.
strict_protocol_version_checking (Strict protocol checking) bool false

# Define the oldest clients allowed to connect.
# Older clients are compatible in the sense that they will not crash when connecting
# to new servers, but they may not support all new features that you are expecting.
# This allows more fine-grained control than strict_protocol_version_checking.
# Minetest may still enforce its own internal minimum, and enabling
# strict_protocol_version_checking will effectively override this.
protocol_version_min (Protocol version minimum) int 1 1 65535

# Specifies URL from which client fetches media instead of using UDP.
# $filename should be accessible from $remote_media$filename via cURL
# (obviously, remote_media should end with a slash).
Expand Down
9 changes: 9 additions & 0 deletions minetest.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,15 @@
# type: bool
# strict_protocol_version_checking = false

# Define the oldest clients allowed to connect.
# Older clients are compatible in the sense that they will not crash when connecting
# to new servers, but they may not support all new features that you are expecting.
# This allows more fine-grained control than strict_protocol_version_checking.
# Minetest may still enforce its own internal minimum, and enabling
# strict_protocol_version_checking will effectively override this.
# type: int min: 0 max: 65535
# protocol_version_min = 1

# Specifies URL from which client fetches media instead of using UDP.
# $filename should be accessible from $remote_media$filename via cURL
# (obviously, remote_media should end with a slash).
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ void set_default_settings()
settings->setDefault("max_packets_per_iteration", "1024");
settings->setDefault("port", "30000");
settings->setDefault("strict_protocol_version_checking", "false");
settings->setDefault("protocol_version_min", "1");
settings->setDefault("player_transfer_distance", "0");
settings->setDefault("max_simultaneous_block_sends_per_client", "40");
settings->setDefault("time_send_interval", "5");
Expand Down
8 changes: 5 additions & 3 deletions src/network/serverpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ void Server::handleCommand_Init(NetworkPacket* pkt)

client->net_proto_version = net_proto_version;

if ((g_settings->getBool("strict_protocol_version_checking") &&
net_proto_version != LATEST_PROTOCOL_VERSION) ||
net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
u16 min_proto = g_settings->getU16("protocol_version_min");
if (g_settings->getBool("strict_protocol_version_checking"))
min_proto = LATEST_PROTOCOL_VERSION;
min_proto = rangelim(min_proto, SERVER_PROTOCOL_VERSION_MIN, SERVER_PROTOCOL_VERSION_MAX);
if (net_proto_version < min_proto ||
net_proto_version > SERVER_PROTOCOL_VERSION_MAX) {
actionstream << "Server: A mismatched client tried to connect from " <<
addr_s << " proto_max=" << (int)max_net_proto_version << std::endl;
Expand Down
5 changes: 4 additions & 1 deletion src/serverlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ void sendAnnounce(AnnounceAction action,
server["address"] = g_settings->get("server_address");
}
if (action != AA_DELETE) {
u16 min_proto = g_settings->getU16("protocol_version_min");
if(min_proto < SERVER_PROTOCOL_VERSION_MIN)
min_proto = SERVER_PROTOCOL_VERSION_MIN;
bool strict_checking = g_settings->getBool("strict_protocol_version_checking");
server["name"] = g_settings->get("server_name");
server["description"] = g_settings->get("server_description");
server["version"] = g_version_string;
server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MIN;
server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : min_proto;
server["proto_max"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MAX;
server["url"] = g_settings->get("server_url");
server["creative"] = g_settings->getBool("creative_mode");
Expand Down

0 comments on commit 514c086

Please sign in to comment.