OpenTTD Source
1.11.2
|
#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 "../../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 | |
const char * | GetNetworkRevisionString () |
Get the network version string used by this build. More... | |
static const char * | ExtractNetworkRevisionHash (const char *revstr) |
Extract the git hash from the revision string. More... | |
bool | IsNetworkCompatibleVersion (const char *other) |
Checks whether the given version string is compatible with our version. More... | |
void | FillNetworkGameInfo (NetworkGameInfo &ngi) |
Fill a NetworkGameInfo structure with the latest information of the server. More... | |
static void | HandleIncomingNetworkGameInfoGRFConfig (GRFConfig *config) |
Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo. More... | |
void | SerializeNetworkGameInfo (Packet *p, const NetworkGameInfo *info) |
Serializes the NetworkGameInfo struct to the packet. More... | |
void | DeserializeNetworkGameInfo (Packet *p, NetworkGameInfo *info) |
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... | |
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. | |
Functions to convert NetworkGameInfo to Packet and back.
Definition in file game_info.cpp.
void DeserializeGRFIdentifier | ( | Packet * | p, |
GRFIdentifier * | grf | ||
) |
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
p | the packet to read the data from. |
grf | the GRFIdentifier to deserialize. |
Definition at line 319 of file game_info.cpp.
References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Recv_uint32(), and Packet::Recv_uint8().
Referenced by DeserializeNetworkGameInfo(), ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), and ClientNetworkUDPSocketHandler::Receive_SERVER_NEWGRFS().
void DeserializeNetworkGameInfo | ( | Packet * | p, |
NetworkGameInfo * | info | ||
) |
Deserializes the NetworkGameInfo struct from the packet.
p | the packet to read the data from. |
info | the NetworkGameInfo to deserialize into. |
Definition at line 231 of file game_info.cpp.
References Clamp(), NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::companies_max, NetworkGameInfo::companies_on, ConvertYMDToDate(), DAYS_TILL_ORIGINAL_BASE_YEAR, NetworkGameInfo::dedicated, DeserializeGRFIdentifier(), NetworkGameInfo::game_date, NetworkGameInfo::game_info_version, NetworkGameInfo::grfconfig, HandleIncomingNetworkGameInfoGRFConfig(), GRFConfig::ident, NetworkGameInfo::map_height, NetworkServerGameInfo::map_name, NetworkGameInfo::map_set, NetworkGameInfo::map_width, MAX_YEAR, NETWORK_MAX_GRF_COUNT, NETWORK_NUM_LANDSCAPES, NETWORK_NUM_LANGUAGES, GRFConfig::next, Packet::Recv_bool(), Packet::Recv_string(), Packet::Recv_uint16(), Packet::Recv_uint32(), Packet::Recv_uint8(), NetworkGameInfo::server_lang, NetworkGameInfo::server_name, NetworkGameInfo::server_revision, NetworkGameInfo::spectators_max, NetworkGameInfo::spectators_on, NetworkGameInfo::start_date, and NetworkGameInfo::use_password.
Referenced by ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE().
|
static |
Extract the git hash from the revision string.
revstr | The revision string (formatted as DATE-BRANCH-GITHASH). |
Definition at line 85 of file game_info.cpp.
void FillNetworkGameInfo | ( | NetworkGameInfo & | ngi | ) |
Fill a NetworkGameInfo structure with the latest information of the server.
ngi | the NetworkGameInfo struct to fill with data. |
Definition at line 113 of file game_info.cpp.
References _network_game_info, _settings_client, _settings_game, NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::companies_on, ConvertYMDToDate(), GameSettings::game_creation, NetworkSettings::max_clients, ClientSettings::network, NetworkGameInfo::server_lang, NetworkSettings::server_lang, NetworkSettings::server_password, NetworkGameInfo::start_date, GameCreationSettings::starting_year, StrEmpty(), and NetworkGameInfo::use_password.
Referenced by ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), and ServerNetworkGameSocketHandler::SendGameInfo().
const char* GetNetworkRevisionString | ( | ) |
Get the network version string used by this build.
The returned string is guaranteed to be at most NETWORK_REVISON_LENGTH bytes.
Definition at line 41 of file game_info.cpp.
References stredup().
Referenced by IsNetworkCompatibleVersion(), NetworkHTTPSocketHandler::NetworkHTTPSocketHandler(), and ServerNetworkAdminSocketHandler::SendWelcome().
|
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.
config | the GRF to handle. |
Definition at line 145 of file game_info.cpp.
References FGCM_EXACT, GRFConfig::filename, FindGRFConfig(), FindUnknownGRFName(), GRFConfig::flags, GCF_COPY, GCS_NOT_FOUND, GRFIdentifier::grfid, GRFConfig::ident, GRFConfig::info, GRFIdentifier::md5sum, GRFConfig::name, SetBit(), GRFConfig::status, and GRFConfig::url.
Referenced by DeserializeNetworkGameInfo().
bool IsNetworkCompatibleVersion | ( | const char * | 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.
other | the version string to compare to |
Definition at line 95 of file game_info.cpp.
References GetNetworkRevisionString(), and NETWORK_REVISION_LENGTH.
Referenced by ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE().
void SerializeGRFIdentifier | ( | Packet * | p, |
const GRFIdentifier * | grf | ||
) |
Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
p | the packet to write the data to. |
grf | the GRFIdentifier to serialize. |
Definition at line 305 of file game_info.cpp.
References GRFIdentifier::grfid, GRFIdentifier::md5sum, Packet::Send_uint32(), and Packet::Send_uint8().
Referenced by ServerNetworkUDPSocketHandler::Receive_CLIENT_GET_NEWGRFS(), ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), and SerializeNetworkGameInfo().
void SerializeNetworkGameInfo | ( | Packet * | p, |
const NetworkGameInfo * | info | ||
) |
Serializes the NetworkGameInfo struct to the packet.
p | the packet to write the data to. |
info | the NetworkGameInfo struct to serialize from. |
Definition at line 169 of file game_info.cpp.
References NetworkGameInfo::clients_max, NetworkServerGameInfo::clients_on, NetworkGameInfo::companies_max, NetworkGameInfo::companies_on, NetworkGameInfo::dedicated, GRFConfig::flags, NetworkGameInfo::game_date, GCF_STATIC, NetworkGameInfo::grfconfig, HasBit(), GRFConfig::ident, NetworkGameInfo::map_height, NetworkServerGameInfo::map_name, NetworkGameInfo::map_set, NetworkGameInfo::map_width, NETWORK_GAME_INFO_VERSION, GRFConfig::next, Packet::Send_bool(), Packet::Send_string(), Packet::Send_uint16(), Packet::Send_uint32(), Packet::Send_uint8(), SerializeGRFIdentifier(), NetworkGameInfo::server_lang, NetworkGameInfo::server_name, NetworkGameInfo::server_revision, NetworkGameInfo::spectators_max, NetworkGameInfo::spectators_on, NetworkGameInfo::start_date, and NetworkGameInfo::use_password.
Referenced by ServerNetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(), and ServerNetworkGameSocketHandler::SendGameInfo().
|
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 33 of file game_info.cpp.