mirror of https://github.com/OpenTTD/OpenTTD
Codechange: refactor CheckGameCompatibility() from existing function
Later commits use this function in other places too.pull/9123/head
parent
b3003dd163
commit
b57d845e55
|
@ -106,6 +106,21 @@ bool IsNetworkCompatibleVersion(const char *other)
|
||||||
return hash1 != nullptr && hash2 != nullptr && strncmp(hash1, hash2, GITHASH_SUFFIX_LEN) == 0;
|
return hash1 != nullptr && hash2 != nullptr && strncmp(hash1, hash2, GITHASH_SUFFIX_LEN) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if an game entry is compatible with our client.
|
||||||
|
*/
|
||||||
|
void CheckGameCompatibility(NetworkGameInfo &ngi)
|
||||||
|
{
|
||||||
|
/* Check if we are allowed on this server based on the revision-check. */
|
||||||
|
ngi.version_compatible = IsNetworkCompatibleVersion(ngi.server_revision);
|
||||||
|
ngi.compatible = ngi.version_compatible;
|
||||||
|
|
||||||
|
/* Check if we have all the GRFs on the client-system too. */
|
||||||
|
for (const GRFConfig *c = ngi.grfconfig; c != nullptr; c = c->next) {
|
||||||
|
if (c->status == GCS_NOT_FOUND) ngi.compatible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fill a NetworkGameInfo structure with the latest information of the server.
|
* Fill a NetworkGameInfo structure with the latest information of the server.
|
||||||
* @param ngi the NetworkGameInfo struct to fill with data.
|
* @param ngi the NetworkGameInfo struct to fill with data.
|
||||||
|
|
|
@ -93,6 +93,7 @@ extern NetworkServerGameInfo _network_game_info;
|
||||||
|
|
||||||
const char *GetNetworkRevisionString();
|
const char *GetNetworkRevisionString();
|
||||||
bool IsNetworkCompatibleVersion(const char *other);
|
bool IsNetworkCompatibleVersion(const char *other);
|
||||||
|
void CheckGameCompatibility(NetworkGameInfo &ngi);
|
||||||
|
|
||||||
void FillNetworkGameInfo(NetworkGameInfo &ngi);
|
void FillNetworkGameInfo(NetworkGameInfo &ngi);
|
||||||
|
|
||||||
|
|
|
@ -324,10 +324,15 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAd
|
||||||
/* Find next item */
|
/* Find next item */
|
||||||
item = NetworkGameListAddItem(*client_addr);
|
item = NetworkGameListAddItem(*client_addr);
|
||||||
|
|
||||||
|
/* Clear any existing GRFConfig chain. */
|
||||||
ClearGRFConfigList(&item->info.grfconfig);
|
ClearGRFConfigList(&item->info.grfconfig);
|
||||||
|
/* Retrieve the NetworkGameInfo from the packet. */
|
||||||
DeserializeNetworkGameInfo(p, &item->info);
|
DeserializeNetworkGameInfo(p, &item->info);
|
||||||
|
/* Check for compatability with the client. */
|
||||||
|
CheckGameCompatibility(item->info);
|
||||||
|
/* Ensure we consider the server online. */
|
||||||
|
item->online = true;
|
||||||
|
|
||||||
item->info.compatible = true;
|
|
||||||
{
|
{
|
||||||
/* Checks whether there needs to be a request for names of GRFs and makes
|
/* Checks whether there needs to be a request for names of GRFs and makes
|
||||||
* the request if necessary. GRFs that need to be requested are the GRFs
|
* the request if necessary. GRFs that need to be requested are the GRFs
|
||||||
|
@ -341,7 +346,6 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAd
|
||||||
uint in_request_count = 0;
|
uint in_request_count = 0;
|
||||||
|
|
||||||
for (c = item->info.grfconfig; c != nullptr; c = c->next) {
|
for (c = item->info.grfconfig; c != nullptr; c = c->next) {
|
||||||
if (c->status == GCS_NOT_FOUND) item->info.compatible = false;
|
|
||||||
if (c->status != GCS_NOT_FOUND || strcmp(c->GetName(), UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
|
if (c->status != GCS_NOT_FOUND || strcmp(c->GetName(), UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue;
|
||||||
in_request[in_request_count] = c;
|
in_request[in_request_count] = c;
|
||||||
in_request_count++;
|
in_request_count++;
|
||||||
|
@ -369,12 +373,6 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAd
|
||||||
strecat(item->info.server_name, " (IPv6)", lastof(item->info.server_name));
|
strecat(item->info.server_name, " (IPv6)", lastof(item->info.server_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we are allowed on this server based on the revision-match */
|
|
||||||
item->info.version_compatible = IsNetworkCompatibleVersion(item->info.server_revision);
|
|
||||||
item->info.compatible &= item->info.version_compatible; // Already contains match for GRFs
|
|
||||||
|
|
||||||
item->online = true;
|
|
||||||
|
|
||||||
UpdateNetworkGameWindow();
|
UpdateNetworkGameWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue