OpenTTD Source  12.0-beta2
game_info.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
12 #ifndef NETWORK_CORE_GAME_INFO_H
13 #define NETWORK_CORE_GAME_INFO_H
14 
15 #include "config.h"
16 #include "core.h"
17 #include "../../newgrf_config.h"
18 #include "../../date_type.h"
19 
20 #include <unordered_map>
21 
22 /*
23  * NetworkGameInfo has several revisions which we still need to support on the
24  * wire. The table below shows the version and size for each field of the
25  * serialized NetworkGameInfo.
26  *
27  * Version: Bytes: Description:
28  * all 1 the version of this packet's structure
29  *
30  * 6+ 1 type of storage for the NewGRFs below:
31  * 0 = NewGRF ID and MD5 checksum.
32  * Used as default for version 5 and below, and for
33  * later game updates to the Game Coordinator.
34  * 1 = NewGRF ID, MD5 checksum and name.
35  * Used for direct requests and the first game
36  * update to Game Coordinator.
37  * 2 = Index in NewGRF lookup table.
38  * Used for sending server listing from the Game
39  * Coordinator to the clients.
40  *
41  * 5+ 4 version number of the Game Script (-1 is case none is selected).
42  * 5+ var string with the name of the Game Script.
43  *
44  * 4+ 1 number of GRFs attached (n).
45  * 4+ n * var identifiers for GRF files. Consists of:
46  * Note: the 'vN' refers to packet version and 'type'
47  * refers to the v6+ type of storage for the NewGRFs.
48  * - 4 byte variable with the GRF ID.
49  * For v4, v5, and v6+ in case of type 0 and/or type 1.
50  * - 16 bytes with the MD5 checksum of the GRF.
51  * For v4, v5, and v6+ in case of type 0 and/or type 1.
52  * - string with name of NewGRF.
53  * For v6+ in case of type 1.
54  * - 4 byte lookup table index.
55  * For v6+ in case of type 2.
56  *
57  * 3+ 4 current game date in days since 1-1-0 (DMY)
58  * 3+ 4 game introduction date in days since 1-1-0 (DMY)
59  *
60  * 2+ 1 maximum number of companies allowed on the server
61  * 2+ 1 number of companies on the server
62  * 2+ 1 maximum number of spectators allowed on the server
63  *
64  * 1+ var string with the name of the server
65  * 1+ var string with the revision of the server
66  * 1 - 5 1 the language run on the server
67  * (0 = any, 1 = English, 2 = German, 3 = French)
68  * 1+ 1 whether the server uses a password (0 = no, 1 = yes)
69  * 1+ 1 maximum number of clients allowed on the server
70  * 1+ 1 number of clients on the server
71  * 1+ 1 number of spectators on the server
72  * 1 & 2 2 current game date in days since 1-1-1920 (DMY)
73  * 1 & 2 2 game introduction date in days since 1-1-1920 (DMY)
74  * 1 - 5 var string with the name of the map
75  * 1+ 2 width of the map in tiles
76  * 1+ 2 height of the map in tiles
77  * 1+ 1 type of map:
78  * (0 = temperate, 1 = arctic, 2 = desert, 3 = toyland)
79  * 1+ 1 whether the server is dedicated (0 = no, 1 = yes)
80  */
81 
88 };
89 
97  uint16 map_width;
98  uint16 map_height;
99  std::string server_name;
100  std::string server_revision;
101  bool dedicated;
103  byte clients_on;
104  byte clients_max;
108  byte landscape;
110  std::string gamescript_name;
111 };
112 
119  bool compatible;
120 };
121 
128  std::string name;
129 };
131 typedef std::unordered_map<uint32, NamedGRFIdentifier> GameInfoNewGRFLookupTable;
132 
134 
135 std::string_view GetNetworkRevisionString();
136 bool IsNetworkCompatibleVersion(std::string_view other);
138 
141 
144 void SerializeGRFIdentifier(Packet *p, const GRFIdentifier *grf);
145 
146 void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table = nullptr);
147 void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool send_newgrf_names = true);
148 
149 #endif /* NETWORK_CORE_GAME_INFO_H */
NST_END
@ NST_END
The end of the list (period).
Definition: game_info.h:87
DeserializeGRFIdentifier
void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
Definition: game_info.cpp:377
NetworkServerGameInfo::gamescript_version
int gamescript_version
Version of the gamescript.
Definition: game_info.h:109
NetworkGameInfo
The game information that is sent from the server to the clients with extra information only required...
Definition: game_info.h:117
NetworkServerGameInfo::gamescript_name
std::string gamescript_name
Name of the gamescript.
Definition: game_info.h:110
NetworkServerGameInfo::game_date
Date game_date
Current date.
Definition: game_info.h:96
NetworkServerGameInfo::server_revision
std::string server_revision
The version number the server is using (e.g.: 'r304' or 0.5.0)
Definition: game_info.h:100
NST_LOOKUP_ID
@ NST_LOOKUP_ID
Unique ID into a lookup table that is sent before.
Definition: game_info.h:86
NST_GRFID_MD5
@ NST_GRFID_MD5
Unique GRF ID and MD5 checksum.
Definition: game_info.h:84
NetworkServerGameInfo::clients_max
byte clients_max
Max clients allowed on server.
Definition: game_info.h:104
NamedGRFIdentifier::name
std::string name
The name of the NewGRF.
Definition: game_info.h:128
SerializeNetworkGameInfo
void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool send_newgrf_names=true)
Serializes the NetworkGameInfo struct to the packet.
Definition: game_info.cpp:185
NetworkServerGameInfo
The game information that is sent from the server to the client.
Definition: game_info.h:93
NamedGRFIdentifier::ident
GRFIdentifier ident
The unique identifier of the NewGRF.
Definition: game_info.h:127
SerializeGRFIdentifier
void SerializeGRFIdentifier(Packet *p, const GRFIdentifier *grf)
Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
Definition: game_info.cpp:363
DeserializeGRFIdentifierWithName
void DeserializeGRFIdentifierWithName(Packet *p, NamedGRFIdentifier *grf)
Deserializes the NamedGRFIdentifier (GRF ID, MD5 checksum and name) from the packet.
Definition: game_info.cpp:391
NetworkGameInfo::version_compatible
bool version_compatible
Can we connect to this server or not? (based on server_revision)
Definition: game_info.h:118
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
CheckGameCompatibility
void CheckGameCompatibility(NetworkGameInfo &ngi)
Check if an game entry is compatible with our client.
Definition: game_info.cpp:107
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:155
Date
int32 Date
The type to store our dates in.
Definition: date_type.h:14
NetworkServerGameInfo::companies_on
byte companies_on
How many started companies do we have.
Definition: game_info.h:105
NetworkServerGameInfo::companies_max
byte companies_max
Max companies allowed on server.
Definition: game_info.h:106
NewGRFSerializationType
NewGRFSerializationType
The different types/ways a NewGRF can be serialized in the GameInfo since version 6.
Definition: game_info.h:83
GetCurrentNetworkServerGameInfo
const NetworkServerGameInfo * GetCurrentNetworkServerGameInfo()
Get the NetworkServerGameInfo structure with the latest information of the server.
Definition: game_info.cpp:143
Packet
Internal entity of a packet.
Definition: packet.h:44
NST_GRFID_MD5_NAME
@ NST_GRFID_MD5_NAME
Unique GRF ID, MD5 checksum and name.
Definition: game_info.h:85
NetworkServerGameInfo::map_width
uint16 map_width
Map width.
Definition: game_info.h:97
NetworkServerGameInfo::dedicated
bool dedicated
Is this a dedicated server?
Definition: game_info.h:101
NetworkServerGameInfo::use_password
bool use_password
Is this server passworded?
Definition: game_info.h:102
FillStaticNetworkServerGameInfo
void FillStaticNetworkServerGameInfo()
Fill a NetworkServerGameInfo structure with the static content, or things that are so static they can...
Definition: game_info.cpp:123
NetworkServerGameInfo::spectators_on
byte spectators_on
How many spectators do we have?
Definition: game_info.h:107
core.h
GameInfoNewGRFLookupTable
std::unordered_map< uint32, NamedGRFIdentifier > GameInfoNewGRFLookupTable
Lookup table for the GameInfo in case of NST_LOOKUP_ID.
Definition: game_info.h:131
config.h
NetworkServerGameInfo::start_date
Date start_date
When the game started.
Definition: game_info.h:95
NetworkServerGameInfo::landscape
byte landscape
The used landscape.
Definition: game_info.h:108
NetworkServerGameInfo::server_name
std::string server_name
Server name.
Definition: game_info.h:99
NetworkServerGameInfo::clients_on
byte clients_on
Current count of clients on server.
Definition: game_info.h:103
GetNetworkRevisionString
std::string_view GetNetworkRevisionString()
Get the network version string used by this build.
Definition: game_info.cpp:43
NetworkServerGameInfo::grfconfig
GRFConfig * grfconfig
List of NewGRF files used.
Definition: game_info.h:94
DeserializeNetworkGameInfo
void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfoNewGRFLookupTable *newgrf_lookup_table=nullptr)
Deserializes the NetworkGameInfo struct from the packet.
Definition: game_info.cpp:256
NamedGRFIdentifier
Container to hold the GRF identifier (GRF ID + MD5 checksum) and the name associated with that NewGRF...
Definition: game_info.h:126
_network_game_info
NetworkServerGameInfo _network_game_info
Information about our game.
Definition: game_info.cpp:37
NetworkGameInfo::compatible
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
Definition: game_info.h:119
NetworkServerGameInfo::map_height
uint16 map_height
Map height.
Definition: game_info.h:98
IsNetworkCompatibleVersion
bool IsNetworkCompatibleVersion(std::string_view other)
Checks whether the given version string is compatible with our version.
Definition: game_info.cpp:90