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