OpenTTD Source 20260206-master-g4d4e37dbf1
network_game_info.cpp File Reference

Functions to convert NetworkGameInfo to Packet and back. More...

#include "../../stdafx.h"
#include "network_game_info.h"
#include "../../company_base.h"
#include "../../timer/timer_game_calendar.h"
#include "../../timer/timer_game_tick.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 "../network_internal.h"
#include "packet.h"
#include "table/strings.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.
static std::string_view ExtractNetworkRevisionHash (std::string_view revision_string)
 Extract the git hash from the revision string.
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.
static void HandleIncomingNetworkGameInfoGRFConfig (GRFConfig &config, std::string_view name)
 Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.
void SerializeNetworkGameInfo (Packet &p, const NetworkServerGameInfo &info, bool send_newgrf_names)
 Serializes the NetworkGameInfo struct to the packet.
void DeserializeNetworkGameInfo (Packet &p, NetworkGameInfo &info, const GameInfoNewGRFLookupTable *newgrf_lookup_table)
 Deserializes the NetworkGameInfo struct from the packet.
void SerializeGRFIdentifier (Packet &p, const GRFIdentifier &grf)
 Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
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.

Variables

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

Detailed Description

Functions to convert NetworkGameInfo to Packet and back.

Definition in file network_game_info.cpp.

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 397 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 408 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.
newgrf_lookup_tableLookup table for index-mapped NewGRFs.

Definition at line 273 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, Temperate, NetworkServerGameInfo::ticks_playing, to_underlying(), and NetworkServerGameInfo::use_password.

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

◆ ExtractNetworkRevisionHash()

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

Extract the git hash from the revision string.

Parameters
revision_stringThe revision string (formatted as DATE-BRANCH-GITHASH).
Returns
The git has part of the revision.

Definition at line 90 of file network_game_info.cpp.

Referenced by IsNetworkCompatibleVersion().

◆ FillStaticNetworkServerGameInfo()

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.

Definition at line 140 of file network_game_info.cpp.

References _grfconfig, _network_dedicated, _network_game_info, _settings_client, _settings_game, TimerGameCalendar::ConvertYMDToDate(), CopyGRFConfigList(), GetNetworkRevisionString(), Map::SizeX(), and Map::SizeY().

Referenced by NetworkServerUpdateGameInfo().

◆ GetCurrentNetworkServerGameInfo()

const NetworkServerGameInfo & GetCurrentNetworkServerGameInfo ( )

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

Returns
The current NetworkServerGameInfo.

Definition at line 160 of file network_game_info.cpp.

References _network_game_info, TimerGameTick::counter, and TimerGameCalendar::date.

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_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().

◆ HandleIncomingNetworkGameInfoGRFConfig()

void HandleIncomingNetworkGameInfoGRFConfig ( GRFConfig & config,
std::string_view 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
configThe GRF to handle.
nameThe name of the NewGRF, empty when unknown.

Definition at line 182 of file network_game_info.cpp.

References AddGRFTextToList(), Copy, FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), GRFConfig::flags, GCS_NOT_FOUND, GetString(), GRFIdentifier::grfid, GRFConfig::ident, GRFConfig::info, GRFIdentifier::md5sum, GRFConfig::name, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Set(), GRFConfig::status, and GRFConfig::url.

Referenced by DeserializeNetworkGameInfo().

◆ 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 386 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

◆ 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 36 of file network_game_info.cpp.

Referenced by GetNetworkRevisionString().