(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.
--- a/src/network/network.cpp Wed Feb 28 23:52:04 2007 +0000
+++ b/src/network/network.cpp Thu Mar 01 00:58:09 2007 +0000
@@ -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 Wed Feb 28 23:52:04 2007 +0000
+++ b/src/network/network.h Thu Mar 01 00:58:09 2007 +0000
@@ -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 Wed Feb 28 23:52:04 2007 +0000
+++ b/src/network/network_server.cpp Thu Mar 01 00:58:09 2007 +0000
@@ -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 Wed Feb 28 23:52:04 2007 +0000
+++ b/src/network/network_udp.cpp Thu Mar 01 00:58:09 2007 +0000
@@ -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;