|
@@ -7,24 +7,26 @@
|
|
|
|
|
|
/**
|
|
|
* @file game_info.cpp Functions to convert NetworkGameInfo to Packet and back.
|
|
|
*/
|
|
|
|
|
|
#include "../../stdafx.h"
|
|
|
#include "game_info.h"
|
|
|
#include "../../core/bitmath_func.hpp"
|
|
|
#include "../../company_base.h"
|
|
|
#include "../../date_func.h"
|
|
|
#include "../../debug.h"
|
|
|
#include "../../map_func.h"
|
|
|
#include "../../game/game.hpp"
|
|
|
#include "../../game/game_info.hpp"
|
|
|
#include "../../settings_type.h"
|
|
|
#include "../../string_func.h"
|
|
|
#include "../../rev.h"
|
|
|
#include "../network_func.h"
|
|
|
#include "../network.h"
|
|
|
#include "packet.h"
|
|
|
|
|
|
#include "../../safeguards.h"
|
|
|
|
|
|
|
|
|
/**
|
|
|
* How many hex digits of the git hash to include in network revision string.
|
|
@@ -186,24 +188,29 @@ static void HandleIncomingNetworkGameInf
|
|
|
void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info)
|
|
|
{
|
|
|
p->Send_uint8 (NETWORK_GAME_INFO_VERSION);
|
|
|
|
|
|
/*
|
|
|
* Please observe the order.
|
|
|
* The parts must be read in the same order as they are sent!
|
|
|
*/
|
|
|
|
|
|
/* Update the documentation in game_info.h on changes
|
|
|
* to the NetworkGameInfo wire-protocol! */
|
|
|
|
|
|
/* NETWORK_GAME_INFO_VERSION = 5 */
|
|
|
GameInfo *game_info = Game::GetInfo();
|
|
|
p->Send_uint32(game_info == nullptr ? -1 : (uint32)game_info->GetVersion());
|
|
|
p->Send_string(game_info == nullptr ? "" : game_info->GetName());
|
|
|
|
|
|
/* NETWORK_GAME_INFO_VERSION = 4 */
|
|
|
{
|
|
|
/* Only send the GRF Identification (GRF_ID and MD5 checksum) of
|
|
|
* the GRFs that are needed, i.e. the ones that the server has
|
|
|
* selected in the NewGRF GUI and not the ones that are used due
|
|
|
* to the fact that they are in [newgrf-static] in openttd.cfg */
|
|
|
const GRFConfig *c;
|
|
|
uint count = 0;
|
|
|
|
|
|
/* Count number of GRFs to send information about */
|
|
|
for (c = info->grfconfig; c != nullptr; c = c->next) {
|
|
|
if (!HasBit(c->flags, GCF_STATIC)) count++;
|
|
@@ -251,24 +258,30 @@ void DeserializeNetworkGameInfo(Packet *
|
|
|
|
|
|
byte game_info_version = p->Recv_uint8();
|
|
|
|
|
|
/*
|
|
|
* Please observe the order.
|
|
|
* The parts must be read in the same order as they are sent!
|
|
|
*/
|
|
|
|
|
|
/* Update the documentation in game_info.h on changes
|
|
|
* to the NetworkGameInfo wire-protocol! */
|
|
|
|
|
|
switch (game_info_version) {
|
|
|
case 5: {
|
|
|
info->gamescript_version = (int)p->Recv_uint32();
|
|
|
info->gamescript_name = p->Recv_string(NETWORK_NAME_LENGTH);
|
|
|
FALLTHROUGH;
|
|
|
}
|
|
|
|
|
|
case 4: {
|
|
|
GRFConfig **dst = &info->grfconfig;
|
|
|
uint i;
|
|
|
uint num_grfs = p->Recv_uint8();
|
|
|
|
|
|
/* Broken/bad data. It cannot have that many NewGRFs. */
|
|
|
if (num_grfs > NETWORK_MAX_GRF_COUNT) return;
|
|
|
|
|
|
for (i = 0; i < num_grfs; i++) {
|
|
|
GRFConfig *c = new GRFConfig();
|
|
|
DeserializeGRFIdentifier(p, &c->ident);
|
|
|
HandleIncomingNetworkGameInfoGRFConfig(c);
|