OpenTTD Source 20260108-master-g8ba1860eaa
network_game_info.h File Reference

Convert NetworkGameInfo to Packet and back. More...

#include "config.h"
#include "core.h"
#include "../../newgrf_config.h"
#include "../../timer/timer_game_calendar.h"
#include "../../timer/timer_game_tick.h"
#include "../../landscape_type.h"
#include <unordered_map>

Go to the source code of this file.

Data Structures

struct  NetworkServerGameInfo
 The game information that is sent from the server to the client. More...
 
struct  NetworkGameInfo
 The game information that is sent from the server to the clients with extra information only required at the client side. More...
 
struct  NamedGRFIdentifier
 Container to hold the GRF identifier (GRF ID + MD5 checksum) and the name associated with that NewGRF. More...
 

Typedefs

typedef std::unordered_map< uint32_t, NamedGRFIdentifierGameInfoNewGRFLookupTable
 Lookup table for the GameInfo in case of NST_LOOKUP_ID.
 

Enumerations

enum  NewGRFSerializationType { NST_GRFID_MD5 = 0 , NST_GRFID_MD5_NAME = 1 , NST_LOOKUP_ID = 2 , NST_END }
 The different types/ways a NewGRF can be serialized in the GameInfo since version 6. More...
 

Functions

std::string_view GetNetworkRevisionString ()
 Get the network version string used by this build.
 
bool IsNetworkCompatibleVersion (std::string_view other)
 Checks whether the given version string is compatible with our version.
 
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 NetworkServerGameInfoGetCurrentNetworkServerGameInfo ()
 Get the NetworkServerGameInfo structure with the latest information of the server.
 
void DeserializeGRFIdentifier (Packet &p, GRFIdentifier &grf)
 Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
 
void DeserializeGRFIdentifierWithName (Packet &p, NamedGRFIdentifier &grf)
 Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet.
 
void SerializeGRFIdentifier (Packet &p, const GRFIdentifier &grf)
 Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
 
void DeserializeNetworkGameInfo (Packet &p, NetworkGameInfo &info, const GameInfoNewGRFLookupTable *newgrf_lookup_table=nullptr)
 Deserializes the NetworkGameInfo struct from the packet.
 
void SerializeNetworkGameInfo (Packet &p, const NetworkServerGameInfo &info, bool send_newgrf_names=true)
 Serializes the NetworkGameInfo struct to the packet.
 

Variables

NetworkServerGameInfo _network_game_info
 Information about our game.
 

Detailed Description

Convert NetworkGameInfo to Packet and back.

NetworkGameInfo has several revisions which we still need to support on the wire. The table below shows the version and size for each field of the serialized NetworkGameInfo.

Version: Bytes: Description: all 1 the version of this packet's structure

7+ 8 amount of ticks this game has been running unpaused.

6+ 1 type of storage for the NewGRFs below: 0 = NewGRF ID and MD5 checksum. Used as default for version 5 and below, and for later game updates to the Game Coordinator. 1 = NewGRF ID, MD5 checksum and name. Used for direct requests and the first game update to Game Coordinator. 2 = Index in NewGRF lookup table. Used for sending server listing from the Game Coordinator to the clients.

5+ 4 version number of the Game Script (-1 is case none is selected). 5+ var string with the name of the Game Script.

4+ 1 number of GRFs attached (n). 4+ n * var identifiers for GRF files. Consists of: Note: the 'vN' refers to packet version and 'type' refers to the v6+ type of storage for the NewGRFs.

  • 4 byte variable with the GRF ID. For v4, v5, and v6+ in case of type 0 and/or type 1.
  • 16 bytes with the MD5 checksum of the GRF. For v4, v5, and v6+ in case of type 0 and/or type 1.
  • string with name of NewGRF. For v6+ in case of type 1.
  • 4 byte lookup table index. For v6+ in case of type 2.

3+ 4 current calendar date in days since 1-1-0 (DMY) 3+ 4 calendar start date in days since 1-1-0 (DMY)

2+ 1 maximum number of companies allowed on the server 2+ 1 number of companies on the server 2+ 1 maximum number of spectators allowed on the server

1+ var string with the name of the server 1+ var string with the revision of the server 1 - 5 1 the language run on the server (0 = any, 1 = English, 2 = German, 3 = French) 1+ 1 whether the server uses a password (0 = no, 1 = yes) 1+ 1 maximum number of clients allowed on the server 1+ 1 number of clients on the server 1+ 1 number of spectators on the server 1 & 2 2 current game date in days since 1-1-1920 (DMY) 1 & 2 2 game introduction date in days since 1-1-1920 (DMY) 1 - 5 var string with the name of the map 1+ 2 width of the map in tiles 1+ 2 height of the map in tiles 1+ 1 type of map: (0 = temperate, 1 = arctic, 2 = desert, 3 = toyland) 1+ 1 whether the server is dedicated (0 = no, 1 = yes)

Definition in file network_game_info.h.

Typedef Documentation

◆ GameInfoNewGRFLookupTable

typedef std::unordered_map<uint32_t, NamedGRFIdentifier> GameInfoNewGRFLookupTable

Lookup table for the GameInfo in case of NST_LOOKUP_ID.

Definition at line 134 of file network_game_info.h.

Enumeration Type Documentation

◆ NewGRFSerializationType

The different types/ways a NewGRF can be serialized in the GameInfo since version 6.

Enumerator
NST_GRFID_MD5 

Unique GRF ID and MD5 checksum.

NST_GRFID_MD5_NAME 

Unique GRF ID, MD5 checksum and name.

NST_LOOKUP_ID 

Unique ID into a lookup table that is sent before.

NST_END 

The end of the list (period).

Definition at line 85 of file network_game_info.h.

Function Documentation

◆ CheckGameCompatibility()

◆ DeserializeGRFIdentifier()

void DeserializeGRFIdentifier ( Packet p,
GRFIdentifier grf 
)

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

Parameters
pthe packet to read the data from.
grfthe GRFIdentifier to deserialize.

Definition at line 395 of file network_game_info.cpp.

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

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
pthe packet to read the data from.
grfthe NamedGRFIdentifier to deserialize.

Definition at line 406 of file network_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
pthe packet to read the data from.
infothe NetworkGameInfo to deserialize into.

Definition at line 271 of file network_game_info.cpp.

References NetworkServerGameInfo::calendar_date, NetworkServerGameInfo::calendar_start, Clamp(), NetworkServerGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkServerGameInfo::companies_max, NetworkServerGameInfo::companies_on, Ticks::DAY_TICKS, TimerGameConst< struct Calendar >::DAYS_TILL_ORIGINAL_BASE_YEAR, NetworkServerGameInfo::dedicated, DeserializeGRFIdentifier(), DeserializeGRFIdentifierWithName(), NetworkServerGameInfo::gamescript_name, NetworkServerGameInfo::gamescript_version, NetworkServerGameInfo::grfconfig, HandleIncomingNetworkGameInfoGRFConfig(), NamedGRFIdentifier::ident, NetworkServerGameInfo::landscape, NetworkServerGameInfo::map_height, NetworkServerGameInfo::map_width, TimerGameConst< struct Calendar >::MAX_DATE, NamedGRFIdentifier::name, NETWORK_MAX_GRF_COUNT, NETWORK_NAME_LENGTH, NETWORK_REVISION_LENGTH, NST_END, NST_GRFID_MD5, NST_GRFID_MD5_NAME, NST_LOOKUP_ID, Packet::Recv_bool(), Packet::Recv_string(), Packet::Recv_uint16(), Packet::Recv_uint32(), Packet::Recv_uint64(), Packet::Recv_uint8(), NetworkServerGameInfo::server_name, NetworkServerGameInfo::server_revision, NetworkServerGameInfo::spectators_on, NetworkServerGameInfo::ticks_playing, to_underlying(), and NetworkServerGameInfo::use_password.

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

◆ FillStaticNetworkServerGameInfo()

◆ GetCurrentNetworkServerGameInfo()

◆ GetNetworkRevisionString()

std::string_view GetNetworkRevisionString ( )

Get the network version string used by this build.

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

Definition at line 44 of file network_game_info.cpp.

References Debug, GITHASH_SUFFIX_LEN, and NETWORK_REVISION_LENGTH.

Referenced by FillStaticNetworkServerGameInfo(), IsNetworkCompatibleVersion(), NetworkHTTPInitialize(), ClientNetworkGameSocketHandler::SendJoin(), and ServerNetworkAdminSocketHandler::SendWelcome().

◆ 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
otherthe version string to compare to

Definition at line 102 of file network_game_info.cpp.

References ExtractNetworkRevisionHash(), and GetNetworkRevisionString().

Referenced by CheckGameCompatibility(), and ServerNetworkGameSocketHandler::Receive_CLIENT_JOIN().

◆ SerializeGRFIdentifier()

void SerializeGRFIdentifier ( Packet p,
const GRFIdentifier grf 
)

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

Parameters
pthe packet to write the data to.
grfthe GRFIdentifier to serialize.

Definition at line 384 of file network_game_info.cpp.

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

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

◆ SerializeNetworkGameInfo()

Variable Documentation

◆ _network_game_info