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

OpenTTD Source 15.3

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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
97 struct NetworkServerGameInfo {
98 GRFConfigList grfconfig;
99 TimerGameCalendar::Date calendar_start;
100 TimerGameCalendar::Date calendar_date;
101 TimerGameTick::TickCounter ticks_playing;
102 uint16_t map_width;
103 uint16_t map_height;
104 std::string server_name;
105 std::string server_revision;
106 bool dedicated;
107 bool use_password;
108 uint8_t clients_on;
109 uint8_t clients_max;
110 uint8_t companies_on;
111 uint8_t companies_max;
112 uint8_t spectators_on;
113 LandscapeType landscape;
114 int gamescript_version;
115 std::string gamescript_name;
116};
117
122 struct NetworkGameInfo : NetworkServerGameInfo {
123 bool version_compatible;
124 bool compatible;
125};
126
131 struct NamedGRFIdentifier {
132 GRFIdentifier ident;
133 std::string name;
134};
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 */
TimerGameTick::TickCounter
uint64_t TickCounter
The type that the tick counter is stored in.
Definition timer_game_tick.h:25
config.h
Configuration options of the network stuff.
core.h
Base for all network types (UDP and TCP)
LandscapeType
LandscapeType
Landscape types.
Definition landscape_type.h:16
GRFIdentifier
Basic data to distinguish a GRF.
Definition newgrf_config.h:83
NamedGRFIdentifier
Container to hold the GRF identifier (GRF ID + MD5 checksum) and the name associated with that NewGRF...
Definition network_game_info.h:131
NamedGRFIdentifier::name
std::string name
The name of the NewGRF.
Definition network_game_info.h:133
NamedGRFIdentifier::ident
GRFIdentifier ident
The unique identifier of the NewGRF.
Definition network_game_info.h:132
NetworkGameInfo
The game information that is sent from the server to the clients with extra information only required...
Definition network_game_info.h:122
NetworkGameInfo::version_compatible
bool version_compatible
Can we connect to this server or not? (based on server_revision)
Definition network_game_info.h:123
NetworkGameInfo::compatible
bool compatible
Can we connect to this server or not? (based on server_revision and grf_match.
Definition network_game_info.h:124
NetworkServerGameInfo
The game information that is sent from the server to the client.
Definition network_game_info.h:97
NetworkServerGameInfo::calendar_start
TimerGameCalendar::Date calendar_start
When the game started.
Definition network_game_info.h:99
NetworkServerGameInfo::dedicated
bool dedicated
Is this a dedicated server?
Definition network_game_info.h:106
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:105
NetworkServerGameInfo::use_password
bool use_password
Is this server passworded?
Definition network_game_info.h:107
NetworkServerGameInfo::clients_max
uint8_t clients_max
Max clients allowed on server.
Definition network_game_info.h:109
NetworkServerGameInfo::spectators_on
uint8_t spectators_on
How many spectators do we have?
Definition network_game_info.h:112
NetworkServerGameInfo::grfconfig
GRFConfigList grfconfig
List of NewGRF files used.
Definition network_game_info.h:98
NetworkServerGameInfo::map_height
uint16_t map_height
Map height.
Definition network_game_info.h:103
NetworkServerGameInfo::server_name
std::string server_name
Server name.
Definition network_game_info.h:104
NetworkServerGameInfo::map_width
uint16_t map_width
Map width.
Definition network_game_info.h:102
NetworkServerGameInfo::ticks_playing
TimerGameTick::TickCounter ticks_playing
Amount of ticks the game has been running unpaused.
Definition network_game_info.h:101
NetworkServerGameInfo::landscape
LandscapeType landscape
The used landscape.
Definition network_game_info.h:113
NetworkServerGameInfo::companies_max
uint8_t companies_max
Max companies allowed on server.
Definition network_game_info.h:111
NetworkServerGameInfo::gamescript_name
std::string gamescript_name
Name of the gamescript.
Definition network_game_info.h:115
NetworkServerGameInfo::calendar_date
TimerGameCalendar::Date calendar_date
Current calendar date.
Definition network_game_info.h:100
NetworkServerGameInfo::gamescript_version
int gamescript_version
Version of the gamescript.
Definition network_game_info.h:114
NetworkServerGameInfo::companies_on
uint8_t companies_on
How many started companies do we have.
Definition network_game_info.h:110
NetworkServerGameInfo::clients_on
uint8_t clients_on
Current count of clients on server.
Definition network_game_info.h:108
Packet
Internal entity of a packet.
Definition packet.h:43
StrongType::Typedef
Templated helper to make a type-safe 'typedef' representing a single POD value.
Definition strong_typedef_type.hpp:130