OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
12 #include "../../stdafx.h"
14 #include "../../core/bitmath_func.hpp"
15 #include "../../company_base.h"
16 #include "../../date_func.h"
17 #include "../../debug.h"
18 #include "../../map_func.h"
19 #include "../../game/game.hpp"
20 #include "../../game/game_info.hpp"
21 #include "../../settings_type.h"
22 #include "../../string_func.h"
23 #include "../../rev.h"
24 #include "../network_func.h"
25 #include "../network.h"
28 #include "../../safeguards.h"
45 static std::string network_revision;
47 if (network_revision.empty()) {
48 network_revision = _openttd_revision;
49 if (_openttd_revision_tagged) {
54 assert(_openttd_revision_modified < 3);
55 std::string githash_suffix = fmt::format(
"-{}{}",
"gum"[_openttd_revision_modified], _openttd_revision_hash);
59 size_t hash_end = network_revision.find_last_of(
'-');
60 if (hash_end == std::string::npos) hash_end = network_revision.size();
64 network_revision.replace(hash_end, std::string::npos, githash_suffix);
67 Debug(net, 3,
"Network revision name: {}", network_revision);
70 return network_revision;
80 size_t index = revision_string.find_last_of(
'-');
81 if (index == std::string::npos)
return {};
82 return revision_string.substr(index);
97 if (_openttd_revision_tagged)
return false;
101 return hash1 == hash2;
271 switch (game_info_version) {
274 if (newgrf_serialisation >=
NST_END)
return;
291 for (i = 0; i < num_grfs; i++) {
293 switch (newgrf_serialisation) {
303 if (newgrf_lookup_table ==
nullptr)
return;
304 auto it = newgrf_lookup_table->find(p->
Recv_uint32());
305 if (it == newgrf_lookup_table->end())
return;
344 if (game_info_version < 3) {
348 if (game_info_version < 6)
while (p->
Recv_uint8() != 0) {}
367 for (j = 0; j <
sizeof(grf->
md5sum); j++) {
381 for (j = 0; j <
sizeof(grf->
md5sum); j++) {
@ NST_END
The end of the list (period).
void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool send_newgrf_names)
Serializes the NetworkGameInfo struct to the packet.
int gamescript_version
Version of the gamescript.
The game information that is sent from the server to the clients with extra information only required...
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
std::string gamescript_name
Name of the gamescript.
static const uint GITHASH_SUFFIX_LEN
How many hex digits of the git hash to include in network revision string.
void SerializeGRFIdentifier(Packet *p, const GRFIdentifier *grf)
Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
const GRFConfig * FindGRFConfig(uint32 grfid, FindGRFConfigMode mode, const uint8 *md5sum, uint32 desired_version)
Find a NewGRF in the scanned list.
Date game_date
Current date.
byte landscape
the landscape we're currently in
uint8 max_clients
maximum amount of clients
static const uint NETWORK_NAME_LENGTH
The maximum length of the server name and map name, in bytes including '\0'.
std::string server_revision
The version number the server is using (e.g.: 'r304' or 0.5.0)
static class GameInfo * GetInfo()
Get the current GameInfo.
@ NST_LOOKUP_ID
Unique ID into a lookup table that is sent before.
@ NST_GRFID_MD5
Unique GRF ID and MD5 checksum.
byte clients_max
Max clients allowed on server.
void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
std::string name
The name of the NewGRF.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
The game information that is sent from the server to the client.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
std::string_view GetNetworkRevisionString()
Get the network version string used by this build.
GRFIdentifier ident
grfid and md5sum to uniquely identify newgrfs
ClientSettings _settings_client
The current settings for this game.
@ GCF_COPY
The data is copied from a grf in _all_grfs.
GRFIdentifier ident
The unique identifier of the NewGRF.
GRFStatus status
NOSAVE: GRFStatus, enum.
NetworkServerGameInfo _network_game_info
Information about our game.
void Send_uint8(uint8 data)
Package a 8 bits integer in the packet.
uint8 md5sum[16]
MD5 checksum of file to distinguish files with the same GRF ID (eg. newer version of GRF)
bool version_compatible
Can we connect to this server or not? (based on server_revision)
uint32 grfid
GRF ID (defined by Action 0x08)
void FillStaticNetworkServerGameInfo()
Fill a NetworkServerGameInfo structure with the static content, or things that are so static they can...
GameCreationSettings game_creation
settings used during the creation of a game (map)
void Send_uint32(uint32 data)
Package a 32 bits integer in the packet.
std::string Recv_string(size_t length, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads characters (bytes) from the packet until it finds a '\0', or reaches a maximum of length charac...
static uint MapSizeX()
Get the size of the map along the X.
static const uint NETWORK_MAX_GRF_COUNT
Maximum number of GRFs that can be sent.
Basic data to distinguish a GRF.
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
Date _date
Current date in days (day counter)
Information about GRF, used in the game and (part of it) in savegames.
uint8 flags
NOSAVE: GCF_Flags, bitset.
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
int32 Date
The type to store our dates in.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
byte companies_on
How many started companies do we have.
static uint MapSizeY()
Get the size of the map along the Y.
byte companies_max
Max companies allowed on server.
NewGRFSerializationType
The different types/ways a NewGRF can be serialized in the GameInfo since version 6.
bool _network_dedicated
are we a dedicated server?
Internal entity of a packet.
static const uint NETWORK_REVISION_LENGTH
The maximum length of the revision, in bytes including '\0'.
void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table)
Deserializes the NetworkGameInfo struct from the packet.
@ NST_GRFID_MD5_NAME
Unique GRF ID, MD5 checksum and name.
const NetworkServerGameInfo * GetCurrentNetworkServerGameInfo()
Get the NetworkServerGameInfo structure with the latest information of the server.
bool IsNetworkCompatibleVersion(std::string_view other)
Checks whether the given version string is compatible with our version.
void Send_bool(bool data)
Package a boolean in the packet.
std::string server_name
name of the server
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
int GetVersion() const
Get the version of the script.
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
static size_t GetNumItems()
Returns number of valid items in the pool.
uint16 map_width
Map width.
bool Recv_bool()
Read a boolean from the packet.
bool dedicated
Is this a dedicated server?
bool use_password
Is this server passworded?
static const uint NETWORK_GRF_NAME_LENGTH
Maximum length of the name of a GRF.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
std::string server_password
password for joining this server
All static information from an Game like name, version, etc.
Year starting_year
starting date
GRFTextWrapper url
NOSAVE: URL belonging to this GRF.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
byte spectators_on
How many spectators do we have?
void CheckGameCompatibility(NetworkGameInfo &ngi)
Check if an game entry is compatible with our client.
GRFConfig * _grfconfig
First item in list of current GRF set up.
std::unordered_map< uint32, NamedGRFIdentifier > GameInfoNewGRFLookupTable
Lookup table for the GameInfo in case of NST_LOOKUP_ID.
void Send_string(const std::string_view data)
Sends a string over the network.
void DeserializeGRFIdentifierWithName(Packet *p, NamedGRFIdentifier *grf)
Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet.
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
NetworkSettings network
settings related to the network
Date start_date
When the game started.
byte landscape
The used landscape.
std::string server_name
Server name.
@ FGCM_EXACT
Only find Grfs matching md5sum.
const char * GetName() const
Get the Name of the script.
static const byte NETWORK_GAME_INFO_VERSION
What version of game-info do we use?
char * filename
Filename - either with or without full path.
byte clients_on
Current count of clients on server.
const char * name
Full name of the script.
static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::string name)
Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.
GRFConfig * grfconfig
List of NewGRF files used.
Container to hold the GRF identifier (GRF ID + MD5 checksum) and the name associated with that NewGRF...
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
static void AddGRFTextToList(GRFTextList &list, byte langid, const std::string &text_to_add)
Add a new text to a GRFText list.
uint16 map_height
Map height.
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
uint16 Recv_uint16()
Read a 16 bits integer from the packet.
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR,...
const char * GetName() const
Get the name of this grf.
uint8 max_companies
maximum amount of companies
static std::string_view ExtractNetworkRevisionHash(std::string_view revision_string)
Extract the git hash from the revision string.
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...