Make strict and non-strict protocol version checking to work more like expected

This commit is contained in:
Perttu Ahola 2012-11-27 00:26:19 +02:00
parent 420de7ad5e
commit 96a286dcf5
3 changed files with 22 additions and 16 deletions

@ -139,8 +139,8 @@
#motd = Welcome to this awesome Minetest server! #motd = Welcome to this awesome Minetest server!
# Maximum number of players connected simultaneously # Maximum number of players connected simultaneously
#max_users = 100 #max_users = 100
# Set to false to allow old clients to connect # Set to true to disallow old clients from connecting
#strict_protocol_version_checking = true #strict_protocol_version_checking = false
# Set to true to enable creative mode (unlimited inventory) # Set to true to enable creative mode (unlimited inventory)
#creative_mode = false #creative_mode = false
# Enable players getting damage and dying # Enable players getting damage and dying

@ -111,7 +111,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("default_game", "minetest"); settings->setDefault("default_game", "minetest");
settings->setDefault("motd", ""); settings->setDefault("motd", "");
settings->setDefault("max_users", "100"); settings->setDefault("max_users", "100");
settings->setDefault("strict_protocol_version_checking", "true"); settings->setDefault("strict_protocol_version_checking", "false");
settings->setDefault("creative_mode", "false"); settings->setDefault("creative_mode", "false");
settings->setDefault("enable_damage", "true"); settings->setDefault("enable_damage", "true");
settings->setDefault("only_peaceful_mobs", "false"); settings->setDefault("only_peaceful_mobs", "false");

@ -2069,33 +2069,39 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
getClient(peer_id)->net_proto_version = net_proto_version; getClient(peer_id)->net_proto_version = net_proto_version;
if(net_proto_version == 0) if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN ||
net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
{ {
actionstream<<"Server: An old tried to connect from "<<addr_s actionstream<<"Server: A mismatched client tried to connect from "<<addr_s
<<std::endl; <<std::endl;
SendAccessDenied(m_con, peer_id, std::wstring( SendAccessDenied(m_con, peer_id, std::wstring(
L"Your client's version is not supported.\n" L"Your client's version is not supported.\n"
L"Server version is ") L"Server version is ")
+ narrow_to_wide(VERSION_STRING) + L"." + narrow_to_wide(VERSION_STRING) + L",\n"
+ L"server's PROTOCOL_VERSION is "
+ narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN))
+ L"..."
+ narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
+ L", client's PROTOCOL_VERSION is "
+ narrow_to_wide(itos(min_net_proto_version))
+ L"..."
+ narrow_to_wide(itos(max_net_proto_version))
); );
return; return;
} }
if(g_settings->getBool("strict_protocol_version_checking")) if(g_settings->getBool("strict_protocol_version_checking"))
{ {
if(net_proto_version < SERVER_PROTOCOL_VERSION_MIN || if(net_proto_version != LATEST_PROTOCOL_VERSION)
net_proto_version > SERVER_PROTOCOL_VERSION_MAX)
{ {
actionstream<<"Server: A mismatched client tried to connect" actionstream<<"Server: A mismatched (strict) client tried to "
<<" from "<<addr_s<<std::endl; <<"connect from "<<addr_s<<std::endl;
SendAccessDenied(m_con, peer_id, std::wstring( SendAccessDenied(m_con, peer_id, std::wstring(
L"Your client's version is not supported.\n" L"Your client's version is not supported.\n"
L"Server version is ") L"Server version is ")
+ narrow_to_wide(VERSION_STRING) + L",\n" + narrow_to_wide(VERSION_STRING) + L",\n"
+ L"server's PROTOCOL_VERSION is " + L"server's PROTOCOL_VERSION (strict) is "
+ narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MIN)) + narrow_to_wide(itos(LATEST_PROTOCOL_VERSION))
+ L"..."
+ narrow_to_wide(itos(SERVER_PROTOCOL_VERSION_MAX))
+ L", client's PROTOCOL_VERSION is " + L", client's PROTOCOL_VERSION is "
+ narrow_to_wide(itos(min_net_proto_version)) + narrow_to_wide(itos(min_net_proto_version))
+ L"..." + L"..."
@ -2343,8 +2349,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
// Warnings about protocol version can be issued here // Warnings about protocol version can be issued here
if(getClient(peer_id)->net_proto_version < LATEST_PROTOCOL_VERSION) if(getClient(peer_id)->net_proto_version < LATEST_PROTOCOL_VERSION)
{ {
SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD " SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT'S "
L"AND MAY NOT FULLY WORK WITH THIS SERVER!"); L"VERSION MAY NOT BE FULLY COMPATIBLE WITH THIS SERVER!");
} }
/* /*