OpenTTD Source: src/network/core/network_game_info.h Source File

OpenTTD Source 14.0-beta3

network_game_info.h
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 "../../timer/timer_game_calendar.h"
19 #include "../../timer/timer_game_tick.h"
20
21 #include <unordered_map>
22
23 /*
24 * NetworkGameInfo has several revisions which we still need to support on the
25 * wire. The table below shows the version and size for each field of the
26 * serialized NetworkGameInfo.
27 *
28 * Version: Bytes: Description:
29 * all 1 the version of this packet's structure
30 *
31 * 7+ 8 amount of ticks this game has been running unpaused.
32 *
33 * 6+ 1 type of storage for the NewGRFs below:
34 * 0 = NewGRF ID and MD5 checksum.
35 * Used as default for version 5 and below, and for
36 * later game updates to the Game Coordinator.
37 * 1 = NewGRF ID, MD5 checksum and name.
38 * Used for direct requests and the first game
39 * update to Game Coordinator.
40 * 2 = Index in NewGRF lookup table.
41 * Used for sending server listing from the Game
42 * Coordinator to the clients.
43 *
44 * 5+ 4 version number of the Game Script (-1 is case none is selected).
45 * 5+ var string with the name of the Game Script.
46 *
47 * 4+ 1 number of GRFs attached (n).
48 * 4+ n * var identifiers for GRF files. Consists of:
49 * Note: the 'vN' refers to packet version and 'type'
50 * refers to the v6+ type of storage for the NewGRFs.
51 * - 4 byte variable with the GRF ID.
52 * For v4, v5, and v6+ in case of type 0 and/or type 1.
53 * - 16 bytes with the MD5 checksum of the GRF.
54 * For v4, v5, and v6+ in case of type 0 and/or type 1.
55 * - string with name of NewGRF.
56 * For v6+ in case of type 1.
57 * - 4 byte lookup table index.
58 * For v6+ in case of type 2.
59 *
60 * 3+ 4 current calendar date in days since 1-1-0 (DMY)
61 * 3+ 4 calendar start date in days since 1-1-0 (DMY)
62 *
63 * 2+ 1 maximum number of companies allowed on the server
64 * 2+ 1 number of companies on the server
65 * 2+ 1 maximum number of spectators allowed on the server
66 *
67 * 1+ var string with the name of the server
68 * 1+ var string with the revision of the server
69 * 1 - 5 1 the language run on the server
70 * (0 = any, 1 = English, 2 = German, 3 = French)
71 * 1+ 1 whether the server uses a password (0 = no, 1 = yes)
72 * 1+ 1 maximum number of clients allowed on the server
73 * 1+ 1 number of clients on the server
74 * 1+ 1 number of spectators on the server
75 * 1 & 2 2 current game date in days since 1-1-1920 (DMY)
76 * 1 & 2 2 game introduction date in days since 1-1-1920 (DMY)
77 * 1 - 5 var string with the name of the map
78 * 1+ 2 width of the map in tiles
79 * 1+ 2 height of the map in tiles
80 * 1+ 1 type of map:
81 * (0 = temperate, 1 = arctic, 2 = desert, 3 = toyland)
82 * 1+ 1 whether the server is dedicated (0 = no, 1 = yes)
83 */
84
86 enum NewGRFSerializationType {
87 NST_GRFID_MD5 = 0,
88 NST_GRFID_MD5_NAME = 1,
89 NST_LOOKUP_ID = 2,
90 NST_END
91 };
92
96 struct NetworkServerGameInfo {
97 GRFConfig *grfconfig;
98 TimerGameCalendar::Date calendar_start;
99 TimerGameCalendar::Date calendar_date;
100 TimerGameTick::TickCounter ticks_playing;
101 uint16_t map_width;
102 uint16_t map_height;
103 std::string server_name;
104 std::string server_revision;
105 bool dedicated;
106 bool use_password;
107 byte clients_on;
108 byte clients_max;
109 byte companies_on;
110 byte companies_max;
111 byte spectators_on;
112 byte landscape;
113 int gamescript_version;
114 std::string gamescript_name;
115 };
116
121 struct NetworkGameInfo : NetworkServerGameInfo {
122 bool version_compatible;
123 bool compatible;
124 };
125
130 struct NamedGRFIdentifier {
131 GRFIdentifier ident;
132 std::string name;
133 };
135 typedef std::unordered_map<uint32_t, NamedGRFIdentifier> GameInfoNewGRFLookupTable;
136
137 extern NetworkServerGameInfo _network_game_info;
138
139 std::string_view GetNetworkRevisionString();
140 bool IsNetworkCompatibleVersion(std::string_view other);
141 void CheckGameCompatibility(NetworkGameInfo &ngi);
142
143 void FillStaticNetworkServerGameInfo();
144 const NetworkServerGameInfo &GetCurrentNetworkServerGameInfo();
145
146 void DeserializeGRFIdentifier(Packet &p, GRFIdentifier &grf);
147 void DeserializeGRFIdentifierWithName(Packet &p, NamedGRFIdentifier &grf);
148 void SerializeGRFIdentifier(Packet &p, const GRFIdentifier &grf);
149
150 void DeserializeNetworkGameInfo(Packet &p, NetworkGameInfo &info, const GameInfoNewGRFLookupTable *newgrf_lookup_table = nullptr);
151 void SerializeNetworkGameInfo(Packet &p, const NetworkServerGameInfo &info, bool send_newgrf_names = true);
152
153 #endif /* NETWORK_CORE_GAME_INFO_H */
NetworkServerGameInfo::gamescript_version
int gamescript_version
Version of the gamescript.
Definition: network_game_info.h:113
NetworkGameInfo
The game information that is sent from the server to the clients with extra information only required...
Definition: network_game_info.h:121
NetworkServerGameInfo::gamescript_name
std::string gamescript_name
Name of the gamescript.
Definition: network_game_info.h:114
NetworkServerGameInfo::server_revision
std::string server_revision
The version number the server is using (e.g.: 'r304' or 0.5.0)
Definition: network_game_info.h:104
NetworkServerGameInfo::clients_max
byte clients_max
Max clients allowed on server.
Definition: network_game_info.h:108
NamedGRFIdentifier::name
std::string name
The name of the NewGRF.
Definition: network_game_info.h:132
NetworkServerGameInfo
The game information that is sent from the server to the client.
Definition: network_game_info.h:96
NamedGRFIdentifier::ident
GRFIdentifier ident
The unique identifier of the NewGRF.
Definition: network_game_info.h:131
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition: strong_typedef_type.hpp:150
TimerGameTick::TickCounter
uint64_t TickCounter
The type that the tick counter is stored in.
Definition: timer_game_tick.h:25
NetworkGameInfo::version_compatible
bool version_compatible
Can we connect to this server or not? (based on server_revision)
Definition: network_game_info.h:122
GRFIdentifier
Basic data to distinguish a GRF.
Definition: newgrf_config.h:83
GRFConfig
Information about GRF, used in the game and (part of it) in savegames.
Definition: newgrf_config.h:147
NetworkServerGameInfo::map_height
uint16_t map_height
Map height.
Definition: network_game_info.h:102
NetworkServerGameInfo::companies_on
byte companies_on
How many started companies do we have.
Definition: network_game_info.h:109
NetworkServerGameInfo::companies_max
byte companies_max
Max companies allowed on server.
Definition: network_game_info.h:110
Packet
Internal entity of a packet.
Definition: packet.h:42
NetworkServerGameInfo::dedicated
bool dedicated
Is this a dedicated server?
Definition: network_game_info.h:105
NetworkServerGameInfo::use_password
bool use_password
Is this server passworded?
Definition: network_game_info.h:106
NetworkServerGameInfo::calendar_date
TimerGameCalendar::Date calendar_date
Current calendar date.
Definition: network_game_info.h:99
NetworkServerGameInfo::map_width
uint16_t map_width
Map width.
Definition: network_game_info.h:101
NetworkServerGameInfo::spectators_on
byte spectators_on
How many spectators do we have?
Definition: network_game_info.h:111
core.h
config.h
NetworkServerGameInfo::landscape
byte landscape
The used landscape.
Definition: network_game_info.h:112
NetworkServerGameInfo::server_name
std::string server_name
Server name.
Definition: network_game_info.h:103
NetworkServerGameInfo::clients_on
byte clients_on
Current count of clients on server.
Definition: network_game_info.h:107
NetworkServerGameInfo::grfconfig
GRFConfig * grfconfig
List of NewGRF files used.
Definition: network_game_info.h:97
NetworkServerGameInfo::calendar_start
TimerGameCalendar::Date calendar_start
When the game started.
Definition: network_game_info.h:98
NamedGRFIdentifier
Container to hold the GRF identifier (GRF ID + MD5 checksum) and the name associated with that NewGRF...
Definition: network_game_info.h:130
NetworkGameInfo::compatible
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
Definition: network_game_info.h:123
NetworkServerGameInfo::ticks_playing
TimerGameTick::TickCounter ticks_playing
Amount of ticks the game has been running unpaused.
Definition: network_game_info.h:100