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 "../../settings_type.h"
20 #include "../../string_func.h"
21 #include "../../rev.h"
22 #include "../network_func.h"
23 #include "../network.h"
26 #include "../../safeguards.h"
44 static char *network_revision =
nullptr;
46 if (!network_revision) {
48 network_revision =
stredup(_openttd_revision);
53 if (_openttd_revision_tagged) {
54 DEBUG(net, 1,
"Network revision name is '%s'", network_revision);
55 return network_revision;
60 assert(_openttd_revision_modified < 3);
62 githash_suffix[1] =
"gum"[_openttd_revision_modified];
64 githash_suffix[i] = _openttd_revision_hash[i-2];
69 ptrdiff_t hashofs = strrchr(_openttd_revision,
'-') - _openttd_revision;
70 if (hashofs + strlen(githash_suffix) + 1 >
NETWORK_REVISION_LENGTH) hashofs = strlen(network_revision) - strlen(githash_suffix);
74 DEBUG(net, 1,
"Network revision name is '%s'", network_revision);
77 return network_revision;
87 return strrchr(revstr,
'-');
102 if (_openttd_revision_tagged)
return false;
106 return hash1 !=
nullptr && hash2 !=
nullptr && strncmp(hash1, hash2,
GITHASH_SUFFIX_LEN) == 0;
254 for (i = 0; i < num_grfs; i++) {
309 for (j = 0; j <
sizeof(grf->
md5sum); j++) {
323 for (j = 0; j <
sizeof(grf->
md5sum); j++) {
The game information that is sent from the server to the clients.
GRFTextWrapper info
NOSAVE: GRF info (author, copyright, ...) (Action 0x08)
static const uint GITHASH_SUFFIX_LEN
How many hex digits of the git hash to include in network revision string.
void Recv_string(char *buffer, size_t size, StringValidationSettings settings=SVS_REPLACE_WITH_QUESTION_MARK)
Reads a string till it finds a '\0' in the stream.
uint8 max_spectators
maximum amount of spectators
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.
byte companies_max
Max companies allowed on server.
void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info)
Deserializes the NetworkGameInfo struct from the packet.
byte landscape
the landscape we're currently in
uint8 max_clients
maximum amount of clients
uint8 server_lang
language of the server
static const uint NETWORK_NUM_LANDSCAPES
The number of landscapes in OpenTTD.
void DeserializeGRFIdentifier(Packet *p, GRFIdentifier *grf)
Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
static const uint NETWORK_NUM_LANGUAGES
Number of known languages (to the network protocol) + 1 for 'any'.
char map_name[NETWORK_NAME_LENGTH]
Map which is played ["random" for a randomized map].
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
bool use_password
Is this server passworded?
The game information that is not generated on-the-fly and has to be sent to the clients.
@ GCS_NOT_FOUND
GRF file was not found in the local cache.
byte game_info_version
Version of the game info.
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.
GRFStatus status
NOSAVE: GRFStatus, enum.
uint16 map_width
Map width.
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)
uint32 grfid
GRF ID (defined by Action 0x08)
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.
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.
void FillNetworkGameInfo(NetworkGameInfo &ngi)
Fill a NetworkGameInfo structure with the latest information of the server.
Date start_date
When the game started.
byte server_lang
Language of the server (we should make a nice table for this)
uint32 Recv_uint32()
Read a 32 bits integer from the packet.
char server_password[NETWORK_PASSWORD_LENGTH]
password for joining this server
Date _date
Current date in days (day counter)
bool IsNetworkCompatibleVersion(const char *other)
Checks whether the given version string is compatible with our version.
Information about GRF, used in the game and (part of it) in savegames.
byte companies_on
How many started companies do we have.
#define DEBUG(name, level,...)
Output a line of debugging information.
void Send_string(const char *data)
Sends a string over the network.
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.
static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config)
Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.
void Send_uint16(uint16 data)
Package a 16 bits integer in the packet.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static uint MapSizeY()
Get the size of the map along the Y.
char server_name[NETWORK_NAME_LENGTH]
name of the server
bool _network_dedicated
are we a dedicated server?
Internal entity of a packet.
char server_name[NETWORK_NAME_LENGTH]
Server name.
static const uint NETWORK_REVISION_LENGTH
The maximum length of the revision, in bytes including '\0'.
void Send_bool(bool data)
Package a boolean in the packet.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
byte clients_max
Max clients allowed on server.
static size_t GetNumItems()
Returns number of valid items in the pool.
bool Recv_bool()
Read a boolean from the packet.
struct GRFConfig * next
NOSAVE: Next item in the linked list.
Year starting_year
starting date
GRFTextWrapper url
NOSAVE: URL belonging to this GRF.
uint8 Recv_uint8()
Read a 8 bits integer from the packet.
const char * GetNetworkRevisionString()
Get the network version string used by this build.
void SerializeNetworkGameInfo(Packet *p, const NetworkGameInfo *info)
Serializes the NetworkGameInfo struct to the packet.
Date game_date
Current date.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
GRFConfig * _grfconfig
First item in list of current GRF set up.
static const char * ExtractNetworkRevisionHash(const char *revstr)
Extract the git hash from the revision string.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
char server_revision[NETWORK_REVISION_LENGTH]
The version number the server is using (e.g.: 'r304' or 0.5.0)
NetworkSettings network
settings related to the network
byte spectators_on
How many spectators do we have?
@ FGCM_EXACT
Only find Grfs matching md5sum.
static const byte NETWORK_GAME_INFO_VERSION
What version of game-info do we use?
char * filename
Filename - either with or without full path.
uint16 map_height
Map height.
byte clients_on
Current count of clients on server.
GRFTextWrapper FindUnknownGRFName(uint32 grfid, uint8 *md5sum, bool create)
Finds the name of a NewGRF in the list of names for unknown GRFs.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
GRFConfig * grfconfig
List of NewGRF files used.
#define lastof(x)
Get the last element of an fixed size array.
@ GCF_STATIC
GRF file is used statically (can be used in any MP game)
bool dedicated
Is this a dedicated server?
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,...
byte spectators_max
Max spectators allowed on server.
uint8 max_companies
maximum amount of companies
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,...
byte map_set
Graphical set.