summaryrefslogtreecommitdiff
path: root/src/network/core/game_info.cpp
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-07-18 13:42:01 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-07-18 19:36:38 +0200
commit3eaa4706325556bfb1351d2ff392b5bc205fd238 (patch)
treed32e1124e7f9eaa019e7334ac74a2131aed69256 /src/network/core/game_info.cpp
parent5dd524139fe46c0ea28206e30fb2311acb72ae82 (diff)
downloadopenttd-3eaa4706325556bfb1351d2ff392b5bc205fd238.tar.xz
Feature: [Network] Optionally send NewGRF names with NewGRFs in GameInfo
Before 8a2da49 the NewGRF names were synchronized using UDP packets, however those have been removed. With this a new version of the GameInfo packet is introduced that allows to specify the type of serialisation happens for NewGRFs. Either only the GRF ID and checksum, or those two plus the name of the NewGRF. On this request for local servers will send the NewGRFs names. The Game Coordinator will get the names on the first registration, and after that only the GRF ID and checksum.
Diffstat (limited to 'src/network/core/game_info.cpp')
-rw-r--r--src/network/core/game_info.cpp58
1 files changed, 47 insertions, 11 deletions
diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp
index d3c0491ba..138053b05 100644
--- a/src/network/core/game_info.cpp
+++ b/src/network/core/game_info.cpp
@@ -159,14 +159,15 @@ const NetworkServerGameInfo *GetCurrentNetworkServerGameInfo()
* a NetworkGameInfo. Only grfid and md5sum are set, the rest is zero. This
* function must set all appropriate fields. This GRF is later appended to
* the grfconfig list of the NetworkGameInfo.
- * @param config the GRF to handle.
+ * @param config The GRF to handle.
+ * @param name The name of the NewGRF, empty when unknown.
*/
-static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
+static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::string name)
{
/* Find the matching GRF file */
const GRFConfig *f = FindGRFConfig(config->ident.grfid, FGCM_EXACT, config->ident.md5sum);
if (f == nullptr) {
- AddGRFTextToList(config->name, GetString(STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN));
+ AddGRFTextToList(config->name, name.empty() ? GetString(STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN) : name);
config->status = GCS_NOT_FOUND;
} else {
config->filename = f->filename;
@@ -182,7 +183,7 @@ static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
* @param p the packet to write the data to.
* @param info the NetworkGameInfo struct to serialize from.
*/
-void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info)
+void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool send_newgrf_names)
{
p->Send_uint8 (NETWORK_GAME_INFO_VERSION);
@@ -194,6 +195,9 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info)
/* Update the documentation in game_info.h on changes
* to the NetworkGameInfo wire-protocol! */
+ /* NETWORK_GAME_INFO_VERSION = 6 */
+ p->Send_uint8(send_newgrf_names ? NST_GRFID_MD5_NAME : NST_GRFID_MD5);
+
/* NETWORK_GAME_INFO_VERSION = 5 */
GameInfo *game_info = Game::GetInfo();
p->Send_uint32(game_info == nullptr ? -1 : (uint32)game_info->GetVersion());
@@ -216,7 +220,10 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info)
/* Send actual GRF Identifications */
for (c = info->grfconfig; c != nullptr; c = c->next) {
- if (!HasBit(c->flags, GCF_STATIC)) SerializeGRFIdentifier(p, &c->ident);
+ if (HasBit(c->flags, GCF_STATIC)) continue;
+
+ SerializeGRFIdentifier(p, &c->ident);
+ if (send_newgrf_names) p->Send_string(c->GetName());
}
}
@@ -232,12 +239,10 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info)
/* NETWORK_GAME_INFO_VERSION = 1 */
p->Send_string(info->server_name);
p->Send_string(info->server_revision);
- p->Send_uint8 (0); // Used to be server-lang.
p->Send_bool (info->use_password);
p->Send_uint8 (info->clients_max);
p->Send_uint8 (info->clients_on);
p->Send_uint8 (info->spectators_on);
- p->Send_string(""); // Used to be map-name.
p->Send_uint16(info->map_width);
p->Send_uint16(info->map_height);
p->Send_uint8 (info->landscape);
@@ -254,6 +259,7 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
static const Date MAX_DATE = ConvertYMDToDate(MAX_YEAR, 11, 31); // December is month 11
byte game_info_version = p->Recv_uint8();
+ NewGRFSerializationType newgrf_serialisation = NST_GRFID_MD5;
/*
* Please observe the order.
@@ -264,6 +270,11 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
* to the NetworkGameInfo wire-protocol! */
switch (game_info_version) {
+ case 6:
+ newgrf_serialisation = (NewGRFSerializationType)p->Recv_uint8();
+ if (newgrf_serialisation >= NST_END) return;
+ FALLTHROUGH;
+
case 5: {
info->gamescript_version = (int)p->Recv_uint32();
info->gamescript_name = p->Recv_string(NETWORK_NAME_LENGTH);
@@ -279,9 +290,23 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
for (i = 0; i < num_grfs; i++) {
+ NamedGRFIdentifier grf;
+ switch (newgrf_serialisation) {
+ case NST_GRFID_MD5:
+ DeserializeGRFIdentifier(p, &grf.ident);
+ break;
+
+ case NST_GRFID_MD5_NAME:
+ DeserializeGRFIdentifierWithName(p, &grf);
+ break;
+
+ default:
+ NOT_REACHED();
+ }
+
GRFConfig *c = new GRFConfig();
- DeserializeGRFIdentifier(p, &c->ident);
- HandleIncomingNetworkGameInfoGRFConfig(c);
+ c->ident = grf.ident;
+ HandleIncomingNetworkGameInfoGRFConfig(c, grf.name);
/* Append GRFConfig to the list */
*dst = c;
@@ -304,7 +329,7 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
case 1:
info->server_name = p->Recv_string(NETWORK_NAME_LENGTH);
info->server_revision = p->Recv_string(NETWORK_REVISION_LENGTH);
- p->Recv_uint8 (); // Used to contain server-lang.
+ if (game_info_version < 6) p->Recv_uint8 (); // Used to contain server-lang.
info->use_password = p->Recv_bool ();
info->clients_max = p->Recv_uint8 ();
info->clients_on = p->Recv_uint8 ();
@@ -313,7 +338,7 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
info->game_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR;
info->start_date = p->Recv_uint16() + DAYS_TILL_ORIGINAL_BASE_YEAR;
}
- while (p->Recv_uint8() != 0) {} // Used to contain the map-name.
+ if (game_info_version < 6) while (p->Recv_uint8() != 0) {} // Used to contain the map-name.
info->map_width = p->Recv_uint16();
info->map_height = p->Recv_uint16();
info->landscape = p->Recv_uint8 ();
@@ -350,3 +375,14 @@ void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
grf->md5sum[j] = p->Recv_uint8();
}
}
+
+/**
+ * Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet
+ * @param p the packet to read the data from.
+ * @param grf the NamedGRFIdentifier to deserialize.
+ */
+void DeserializeGRFIdentifierWithName(Packet *p, NamedGRFIdentifier *grf)
+{
+ DeserializeGRFIdentifier(p, &grf->ident);
+ grf->name = p->Recv_string(NETWORK_GRF_NAME_LENGTH);
+}