Mercurial > hg > openttd
changeset 6178:e9cecfb299c6 draft
(svn r8949) -Codechange: only test the first NETWORK_REVISION_LENGTH - 1 characters when determining network compatability. This makes it possible to have 'long' branch names while still being able to play network games.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Thu, 01 Mar 2007 00:58:09 +0000 |
parents | ed54dc50aeaf |
children | e3e61b92574b |
files | src/network/network.cpp src/network/network.h src/network/network_server.cpp src/network/network_udp.cpp |
diffstat | 4 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -1421,4 +1421,17 @@ NetworkCoreShutdown(); } +/** + * Checks whether the given version string is compatible with our version. + * It'll check the first NETWORK_REVISION_LENGTH - 1 characters (-1 for '\0') + * against the current version and the NOREV_STRING. + * @param other the version string to compare to + */ +bool IsNetworkCompatibleVersion(const char *other) +{ + extern const char _openttd_revision[]; + return strncmp(NOREV_STRING, other, NETWORK_REVISION_LENGTH - 1) == 0 || + strncmp(_openttd_revision, other, NETWORK_REVISION_LENGTH - 1) == 0; +} + #endif /* ENABLE_NETWORK */
--- a/src/network/network.h +++ b/src/network/network.h @@ -178,6 +178,8 @@ void NetworkReboot(void); void NetworkDisconnect(void); +bool IsNetworkCompatibleVersion(const char *version); + VARDEF bool _network_server; ///< network-server is active VARDEF bool _network_available; ///< is network mode available? VARDEF bool _network_dedicated; ///< are we a dedicated server?
--- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -621,8 +621,7 @@ #if defined(WITH_REV) || defined(WITH_REV_HACK) // Check if the client has revision control enabled - if (strcmp(NOREV_STRING, client_revision) != 0 && - strcmp(_network_game_info.server_revision, client_revision) != 0) { + if (!IsNetworkCompatibleVersion(client_revision)) { // Different revisions!! SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_WRONG_REVISION); return;
--- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -261,7 +261,6 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE) { - extern const char _openttd_revision[]; NetworkGameList *item; // Just a fail-safe.. should never happen @@ -316,9 +315,7 @@ snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr)); /* Check if we are allowed on this server based on the revision-match */ - item->info.version_compatible = - strcmp(item->info.server_revision, _openttd_revision) == 0 || - strcmp(item->info.server_revision, NOREV_STRING) == 0; + item->info.version_compatible = IsNetworkCompatibleVersion(item->info.server_revision); item->info.compatible &= item->info.version_compatible; // Already contains match for GRFs item->online = true;