(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.

This commit is contained in:
rubidium 2007-03-01 00:58:09 +00:00
parent 3dc71e3484
commit 66487d59fd
4 changed files with 17 additions and 6 deletions

View File

@ -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 */

View File

@ -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?

View File

@ -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;

View File

@ -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;