summaryrefslogtreecommitdiff
path: root/src/server.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-11-26 09:49:07 +0200
committerPerttu Ahola <celeron55@gmail.com>2012-11-26 09:49:07 +0200
commit197542c7ec19b41e865be1e84c6c6898de8514d1 (patch)
tree79554122d141ca79ec3885492e67a0bc526aadd0 /src/server.cpp
parentab507f83e2e0b1f442341724bc47a8480667628e (diff)
downloadminetest-197542c7ec19b41e865be1e84c6c6898de8514d1.tar.gz
minetest-197542c7ec19b41e865be1e84c6c6898de8514d1.tar.bz2
minetest-197542c7ec19b41e865be1e84c6c6898de8514d1.zip
New PROTOCOL_VERSION scheme (allow client to support a range of versions)
Diffstat (limited to 'src/server.cpp')
-rw-r--r--src/server.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/server.cpp b/src/server.cpp
index ac243a29c..f4da73fa5 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -2037,11 +2037,22 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
Read and check network protocol version
*/
- u16 net_proto_version = 0;
+ u16 min_net_proto_version = 0;
if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2)
- {
- net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]);
- }
+ min_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE]);
+
+ // Use min if version field doesn't exist (backwards compatibility)
+ u16 max_net_proto_version = min_net_proto_version;
+ if(datasize >= 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2+2)
+ max_net_proto_version = readU16(&data[2+1+PLAYERNAME_SIZE+PASSWORD_SIZE+2]);
+
+ u16 net_proto_version = max_net_proto_version;
+ if(max_net_proto_version != SERVER_PROTOCOL_VERSION && min_net_proto_version <= SERVER_PROTOCOL_VERSION)
+ net_proto_version = SERVER_PROTOCOL_VERSION;
+
+ verbosestream<<"Server: "<<peer_id<<" Protocol version: min: "
+ <<min_net_proto_version<<", max: "<<max_net_proto_version
+ <<", chosen: "<<net_proto_version<<std::endl;
getClient(peer_id)->net_proto_version = net_proto_version;
@@ -2059,7 +2070,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
if(g_settings->getBool("strict_protocol_version_checking"))
{
- if(net_proto_version != PROTOCOL_VERSION)
+ if(net_proto_version != SERVER_PROTOCOL_VERSION)
{
actionstream<<"Server: A mismatched client tried to connect"
<<" from "<<addr_s<<std::endl;
@@ -2068,7 +2079,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
L"Server version is ")
+ narrow_to_wide(VERSION_STRING) + L",\n"
+ L"server's PROTOCOL_VERSION is "
- + narrow_to_wide(itos(PROTOCOL_VERSION))
+ + narrow_to_wide(itos(SERVER_PROTOCOL_VERSION))
+ L", client's PROTOCOL_VERSION is "
+ narrow_to_wide(itos(net_proto_version))
);
@@ -2310,7 +2321,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
// Warnings about protocol version can be issued here
- if(getClient(peer_id)->net_proto_version < PROTOCOL_VERSION)
+ if(getClient(peer_id)->net_proto_version < SERVER_PROTOCOL_VERSION)
{
SendChatMessage(peer_id, L"# Server: WARNING: YOUR CLIENT IS OLD AND MAY WORK PROPERLY WITH THIS SERVER!");
}