summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/network.cpp13
-rw-r--r--src/network/network.h2
-rw-r--r--src/network/network_server.cpp3
-rw-r--r--src/network/network_udp.cpp5
4 files changed, 17 insertions, 6 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index aa45ef748..c523623ce 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -1421,4 +1421,17 @@ void NetworkShutDown(void)
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 */
diff --git a/src/network/network.h b/src/network/network.h
index d5306af30..4ea8ce9e7 100644
--- a/src/network/network.h
+++ b/src/network/network.h
@@ -178,6 +178,8 @@ bool NetworkClientConnectGame(const char *host, uint16 port);
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?
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index f4653d2df..ce9b9f881 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -621,8 +621,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
#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;
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 9bf7f344c..4dab77b8b 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -261,7 +261,6 @@ public:
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 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE)
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;