(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.

-Feature: show NewGRF compatability of network games in the Game List window; a green square if you got the same OpenTTD version and have the needed NewGRF, a red square if the version does not match and a yellow square if the version matches, but the client is missing at least one of the NewGRFs.
This commit is contained in:
rubidium
2006-12-18 12:26:55 +00:00
parent f010066c1b
commit 32db875d97
9 changed files with 333 additions and 23 deletions

View File

@@ -9,6 +9,7 @@
#include "string.h"
#include "saveload.h"
#include "md5.h"
#include "network_data.h"
#include "newgrf.h"
#include "newgrf_config.h"
@@ -83,9 +84,12 @@ bool FillGRFDetails(GRFConfig *config, bool is_static)
void ClearGRFConfig(GRFConfig *config)
{
free(config->filename);
free(config->name);
free(config->info);
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
if (!HASBIT(config->flags, GCF_COPY)) {
free(config->filename);
free(config->name);
free(config->info);
}
free(config);
}
@@ -264,6 +268,55 @@ const GRFConfig *FindGRFConfig(uint32 grfid, uint8 *md5sum)
return NULL;
}
/** Structure for UnknownGRFs; this is a lightweight variant of GRFConfig */
typedef struct UnknownGRF UnknownGRF;
struct UnknownGRF {
UnknownGRF *next;
uint32 grfid;
uint8 md5sum[16];
char name[NETWORK_GRF_NAME_LENGTH];
};
/**
* Finds the name of a NewGRF in the list of names for unknown GRFs. An
* unknown GRF is a GRF where the .grf is not found during scanning.
*
* The names are resolved via UDP calls to servers that should know the name,
* though the replies may not come. This leaves "<Unknown>" as name, though
* that shouldn't matter _very_ much as they need GRF crawler or so to look
* up the GRF anyway and that works better with the GRF ID.
*
* @param grfid the GRF ID part of the 'unique' GRF identifier
* @param md5sum the MD5 checksum part of the 'unique' GRF identifier
* @param create whether to create a new GRFConfig if the GRFConfig did not
* exist in the fake list of GRFConfigs.
* @return the GRFConfig with the given GRF ID and MD5 checksum or NULL when
* it does not exist and create is false. This value must NEVER be
* freed by the caller.
*/
char *FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
{
UnknownGRF *grf;
static UnknownGRF *unknown_grfs = NULL;
for (grf = unknown_grfs; grf != NULL; grf = grf->next) {
if (grf->grfid == grfid) {
if (memcmp(md5sum, grf->md5sum, sizeof(grf->md5sum)) == 0) return grf->name;
}
}
if (!create) return NULL;
grf = calloc(1, sizeof(*grf));
grf->grfid = grfid;
grf->next = unknown_grfs;
ttd_strlcpy(grf->name, UNKNOWN_GRF_NAME_PLACEHOLDER, sizeof(grf->name));
memcpy(grf->md5sum, md5sum, sizeof(grf->md5sum));
unknown_grfs = grf;
return grf->name;
}
/* Retrieve a NewGRF from the current config by its grfid */
GRFConfig *GetGRFConfig(uint32 grfid)