OpenTTD Source: src/network/core/game_info.cpp File Reference

OpenTTD Source 12.0-beta1

Functions | Variables
game_info.cpp File Reference
`#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"`

Go to the source code of this file.

## Functions
std::string_view | GetNetworkRevisionString ()
| Get the network version string used by this build. More...
static std::string_view | ExtractNetworkRevisionHash (std::string_view revision_string)
| Extract the git hash from the revision string. More...
bool | IsNetworkCompatibleVersion (std::string_view other)
| Checks whether the given version string is compatible with our version. More...
void | CheckGameCompatibility (NetworkGameInfo &ngi)
| Check if an game entry is compatible with our client.
void | FillStaticNetworkServerGameInfo ()
| Fill a NetworkServerGameInfo structure with the static content, or things that are so static they can be updated on request from a settings change.
const NetworkServerGameInfo * | GetCurrentNetworkServerGameInfo ()
| Get the NetworkServerGameInfo structure with the latest information of the server. More...
static void | HandleIncomingNetworkGameInfoGRFConfig (GRFConfig *config, std::string name)
| Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo. More...
void | SerializeNetworkGameInfo (Packet *p, const NetworkServerGameInfo *info, bool send_newgrf_names)
| Serializes the NetworkGameInfo struct to the packet. More...
void | DeserializeNetworkGameInfo (Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table)
| Deserializes the NetworkGameInfo struct from the packet. More...
void | SerializeGRFIdentifier (Packet *p, const GRFIdentifier *grf)
| Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet. More...
void | DeserializeGRFIdentifier (Packet *p, GRFIdentifier *grf)
| Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet. More...
void | DeserializeGRFIdentifierWithName (Packet *p, NamedGRFIdentifier *grf)
| Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet. More...

## Variables
static const uint | GITHASH_SUFFIX_LEN = 12
| How many hex digits of the git hash to include in network revision string. More...
NetworkServerGameInfo | _network_game_info
| Information about our game.

## Detailed Description

Functions to convert NetworkGameInfo to Packet and back.

Definition in file game_info.cpp.

## Function Documentation

## ◆ DeserializeGRFIdentifier()

void DeserializeGRFIdentifier | ( | Packet * | p,
|  | GRFIdentifier * | grf
| ) |  |

Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.

Parameters

  p | the packet to read the data from.
  grf | the GRFIdentifier to deserialize.

Definition at line 377 of file game_info.cpp.

References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Recv_uint32(), and Packet::Recv_uint8().

Referenced by DeserializeGRFIdentifierWithName(), DeserializeNetworkGameInfo(), and ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS().

## ◆ DeserializeGRFIdentifierWithName()

void DeserializeGRFIdentifierWithName | ( | Packet * | p,
|  | NamedGRFIdentifier * | grf
| ) |  |

Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet.

Parameters

  p | the packet to read the data from.
  grf | the NamedGRFIdentifier to deserialize.

Definition at line 391 of file game_info.cpp.

References DeserializeGRFIdentifier(), NamedGRFIdentifier::ident, NamedGRFIdentifier::name, NETWORK_GRF_NAME_LENGTH, and Packet::Recv_string().

Referenced by DeserializeNetworkGameInfo(), and ClientNetworkCoordinatorSocketHandler::Receive_GC_NEWGRF_LOOKUP().

## ◆ DeserializeNetworkGameInfo()

void DeserializeNetworkGameInfo | ( | Packet * | p,
|  | NetworkGameInfo * | info,
|  | const GameInfoNewGRFLookupTable * | newgrf_lookup_table
| ) |  |

Deserializes the NetworkGameInfo struct from the packet.

Parameters

  p | the packet to read the data from.
  info | the NetworkGameInfo to deserialize into.

Definition at line 256 of file game_info.cpp.

References ConvertYMDToDate(), DeserializeGRFIdentifier(), DeserializeGRFIdentifierWithName(), NetworkServerGameInfo::gamescript_name, NetworkServerGameInfo::gamescript_version, NetworkServerGameInfo::grfconfig, NamedGRFIdentifier::ident, MAX_YEAR, NETWORK_MAX_GRF_COUNT, NETWORK_NAME_LENGTH, NST_END, NST_GRFID_MD5, NST_GRFID_MD5_NAME, NST_LOOKUP_ID, Packet::Recv_string(), Packet::Recv_uint32(), and Packet::Recv_uint8().

Referenced by ClientNetworkCoordinatorSocketHandler::Receive_GC_LISTING(), and ClientNetworkGameSocketHandler::Receive_SERVER_GAME_INFO().

## ◆ ExtractNetworkRevisionHash()

static std::string_view ExtractNetworkRevisionHash | ( | std::string_view | revision_string | ) |
| static

Extract the git hash from the revision string.

Parameters

  revision_string | The revision string (formatted as DATE-BRANCH-GITHASH).

Returns
  The git has part of the revision.

Definition at line 78 of file game_info.cpp.

## ◆ GetCurrentNetworkServerGameInfo()

const NetworkServerGameInfo* GetCurrentNetworkServerGameInfo | ( |  | ) |

Get the NetworkServerGameInfo structure with the latest information of the server.

Returns
  The current NetworkServerGameInfo.

Definition at line 143 of file game_info.cpp.

References _network_game_info, and NetworkServerGameInfo::companies_on.

Referenced by ServerNetworkGameSocketHandler::SendGameInfo(), and ClientNetworkCoordinatorSocketHandler::SendServerUpdate().

## ◆ GetNetworkRevisionString()

std::string_view GetNetworkRevisionString | ( |  | ) |

Get the network version string used by this build.

The returned string is guaranteed to be at most NETWORK_REVISON_LENGTH bytes including '\0' terminator.

Definition at line 43 of file game_info.cpp.

Referenced by FillStaticNetworkServerGameInfo(), IsNetworkCompatibleVersion(), NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(), and ServerNetworkAdminSocketHandler::SendWelcome().

## ◆ HandleIncomingNetworkGameInfoGRFConfig()

static void HandleIncomingNetworkGameInfoGRFConfig | ( | GRFConfig * | config,
|  | std::string | name
| ) |  |
| static

Function that is called for every GRFConfig that is read when receiving 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.

Parameters

  config | The GRF to handle.
  name | The name of the NewGRF, empty when unknown.

Definition at line 164 of file game_info.cpp.

References AddGRFTextToList(), FGCM_EXACT, FindGRFConfig(), GRFIdentifier::grfid, GRFConfig::ident, GRFIdentifier::md5sum, ScriptInfo::name, and GRFConfig::name.

## ◆ IsNetworkCompatibleVersion()

bool IsNetworkCompatibleVersion | ( | std::string_view | other | ) |

Checks whether the given version string is compatible with our version.

First tries to match the full string, if that fails, attempts to compare just git hashes.

Parameters

  other | the version string to compare to

Definition at line 90 of file game_info.cpp.

References GetNetworkRevisionString().

Referenced by CheckGameCompatibility().

## ◆ SerializeGRFIdentifier()

void SerializeGRFIdentifier | ( | Packet * | p,
|  | const GRFIdentifier * | grf
| ) |  |

Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.

Parameters

  p | the packet to write the data to.
  grf | the GRFIdentifier to serialize.

Definition at line 363 of file game_info.cpp.

References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Send_uint32(), and Packet::Send_uint8().

Referenced by ServerNetworkGameSocketHandler::SendNewGRFCheck(), and SerializeNetworkGameInfo().

## ◆ SerializeNetworkGameInfo()

void SerializeNetworkGameInfo | ( | Packet * | p,
|  | const NetworkServerGameInfo * | info,
|  | bool | send_newgrf_names
| ) |  |

Serializes the NetworkGameInfo struct to the packet.

Parameters

  p | the packet to write the data to.
  info | the NetworkGameInfo struct to serialize from.

Definition at line 185 of file game_info.cpp.

References NetworkServerGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkServerGameInfo::companies_max, NetworkServerGameInfo::companies_on, NetworkServerGameInfo::dedicated, GRFConfig::flags, NetworkServerGameInfo::game_date, GCF_STATIC, Game::GetInfo(), ScriptInfo::GetName(), GRFConfig::GetName(), ScriptInfo::GetVersion(), NetworkServerGameInfo::grfconfig, HasBit(), GRFConfig::ident, NetworkServerGameInfo::landscape, NetworkServerGameInfo::map_height, NetworkServerGameInfo::map_width, NETWORK_GAME_INFO_VERSION, GRFConfig::next, NST_GRFID_MD5, NST_GRFID_MD5_NAME, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint16(), Packet::Send_uint32(), Packet::Send_uint8(), SerializeGRFIdentifier(), NetworkServerGameInfo::server_name, NetworkServerGameInfo::server_revision, NetworkServerGameInfo::spectators_on, NetworkServerGameInfo::start_date, and NetworkServerGameInfo::use_password.

Referenced by ServerNetworkGameSocketHandler::SendGameInfo(), and ClientNetworkCoordinatorSocketHandler::SendServerUpdate().

## Variable Documentation

## ◆ GITHASH_SUFFIX_LEN

const uint GITHASH_SUFFIX_LEN = 12
| static

How many hex digits of the git hash to include in network revision string.

Determined as 10 hex digits + 2 characters for -g/-u/-m prefix.

Definition at line 35 of file game_info.cpp.