diff options
author | rubidium <rubidium@openttd.org> | 2010-01-14 23:06:41 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-01-14 23:06:41 +0000 |
commit | 4ecb3eb33c67c880bbbf08b5aff5483fe9bfb7d6 (patch) | |
tree | f1a9a89f06d42b643ac716f4967f157e81f255d0 /src/network | |
parent | c390e8f00efe2036432dd2d5e7a07b5333952e66 (diff) | |
download | openttd-4ecb3eb33c67c880bbbf08b5aff5483fe9bfb7d6.tar.xz |
(svn r18804) -Codechange: guard against binaries claiming to be compatible with a future (stable) release of OpenTTD.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network_client.cpp | 7 | ||||
-rw-r--r-- | src/network/network_server.cpp | 22 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index dd9f2a7f8..592c210de 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -189,6 +189,13 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_GETMAP) */ Packet *p = new Packet(PACKET_CLIENT_GETMAP); + /* Send the OpenTTD version to the server, let it validate it too. + * But only do it for stable releases because of those we are sure + * that everybody has the same NewGRF version. For trunk and the + * branches we make tarballs of the OpenTTDs compiled from tarball + * will have the lower bits set to 0. As such they would become + * incompatible, which we would like to prevent by this. */ + if (HasBit(_openttd_newgrf_version, 19)) p->Send_uint32(_openttd_newgrf_version); MY_CLIENT->Send_Packet(p); } diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c35e437e5..89d97ae50 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -29,6 +29,7 @@ #include "../company_gui.h" #include "../window_func.h" #include "../roadveh.h" +#include "../rev.h" #include "table/strings.h" @@ -776,6 +777,27 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_GETMAP) { NetworkClientSocket *new_cs; + /* Do an extra version match. We told the client our version already, + * lets confirm that the client isn't lieing to us. + * But only do it for stable releases because of those we are sure + * that everybody has the same NewGRF version. For trunk and the + * branches we make tarballs of the OpenTTDs compiled from tarball + * will have the lower bits set to 0. As such they would become + * incompatible, which we would like to prevent by this. */ + if (HasBit(_openttd_newgrf_version, 19)) { + if (_openttd_newgrf_version != p->Recv_uint32()) { + /* The version we get from the client differs, it must have the + * wrong version. The client must be wrong. */ + SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); + return NETWORK_RECV_STATUS_OKAY; + } + } else if (p->size != 3) { + /* We received a packet from a version that claims to be stable. + * That shouldn't happen. The client must be wrong. */ + SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_NOT_EXPECTED); + return NETWORK_RECV_STATUS_OKAY; + } + /* The client was never joined.. so this is impossible, right? * Ignore the packet, give the client a warning, and close his connection */ if (cs->status < STATUS_AUTH || cs->HasClientQuit()) { |