From f8f32cc62817185aaa41cb14b846bb792c56ac6a Mon Sep 17 00:00:00 2001 From: luk3yx Date: Fri, 8 Apr 2022 15:16:23 +1200 Subject: [PATCH] Make protocol version <37 compatibility a setting --- builtin/settingtypes.txt | 3 +++ multicraft.conf.example | 3 +++ src/defaultsettings.cpp | 1 + src/network/networkprotocol.h | 1 + src/network/serverpackethandler.cpp | 3 ++- src/serverlist.cpp | 3 ++- 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index 681df711d..6045f7131 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1034,6 +1034,9 @@ port (Server port) int 30000 # The network interface that the server listens on. bind_address (Bind address) string +# Disable to prevent clients that don't support protocol version 37 from connecting. +enable_protocol_compat (Enable legacy network protocol compatibility) bool true + # Enable to disallow old clients from connecting. # 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. diff --git a/multicraft.conf.example b/multicraft.conf.example index 0d16efa6c..dc9918268 100644 --- a/multicraft.conf.example +++ b/multicraft.conf.example @@ -1233,6 +1233,9 @@ # type: string # bind_address = +# Disable to prevent clients that don't support protocol version 37 from connecting. +# enable_proto_compat = true + # Enable to disallow old clients from connecting. # 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. diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index f42cbc2eb..b7c6aadec 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -384,6 +384,7 @@ void set_default_settings() settings->setDefault("ipv6_server", "false"); settings->setDefault("max_packets_per_iteration","1024"); settings->setDefault("port", "40000"); + settings->setDefault("enable_protocol_compat", "true"); settings->setDefault("strict_protocol_version_checking", "false"); settings->setDefault("player_transfer_distance", "0"); settings->setDefault("max_simultaneous_block_sends_per_client", "40"); diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 60749212a..c1f947e39 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -212,6 +212,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // Server's supported network protocol range #define SERVER_PROTOCOL_VERSION_MIN 25 +#define SERVER_PROTOCOL_VERSION_MIN_NOCOMPAT 37 #define SERVER_PROTOCOL_VERSION_MAX LATEST_PROTOCOL_VERSION // Client's supported network protocol range diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 377274caa..7226f31f2 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -143,9 +143,10 @@ void Server::handleCommand_Init(NetworkPacket* pkt) client->net_proto_version = net_proto_version; + const u16 server_proto_ver_min = g_settings->getBool("enable_protocol_compat") ? SERVER_PROTOCOL_VERSION_MIN : SERVER_PROTOCOL_VERSION_MIN_NOCOMPAT; if ((g_settings->getBool("strict_protocol_version_checking") && net_proto_version != LATEST_PROTOCOL_VERSION) || - net_proto_version < SERVER_PROTOCOL_VERSION_MIN || + net_proto_version < server_proto_ver_min || 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; diff --git a/src/serverlist.cpp b/src/serverlist.cpp index e3158068f..718a94402 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -71,11 +71,12 @@ void sendAnnounce(AnnounceAction action, } if (action != AA_DELETE) { bool strict_checking = g_settings->getBool("strict_protocol_version_checking"); + bool proto_compat = g_settings->getBool("enable_protocol_compat"); server["name"] = g_settings->get("server_name"); server["description"] = g_settings->get("server_description"); server["version"] = g_version_string; server["server_id"] = PROJECT_NAME; - server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : SERVER_PROTOCOL_VERSION_MIN; + server["proto_min"] = strict_checking ? LATEST_PROTOCOL_VERSION : (proto_compat ? SERVER_PROTOCOL_VERSION_MIN : SERVER_PROTOCOL_VERSION_MIN_NOCOMPAT); 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");