OpenTTD Source: src/network/network_internal.h Source File

OpenTTD Source 1.11.0-RC1

network_internal.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
10 #ifndef NETWORK_INTERNAL_H
11 #define NETWORK_INTERNAL_H
12
13 #include "network_func.h"
14 #include "core/tcp_game.h"
15
16 #include "../command_type.h"
17
18 #ifdef RANDOM_DEBUG
19
28 #define ENABLE_NETWORK_SYNC_EVERY_FRAME
29
34 #define NETWORK_SEND_DOUBLE_SEED
35 #endif /* RANDOM_DEBUG */
36
44 #ifdef DEBUG_DUMP_COMMANDS
45 extern bool _ddc_fastforward;
46 #else
47 #define _ddc_fastforward (false)
48 #endif /* DEBUG_DUMP_COMMANDS */
49
50 typedef class ServerNetworkGameSocketHandler NetworkClientSocket;
51
53 enum NetworkJoinStatus {
54 NETWORK_JOIN_STATUS_CONNECTING,
55 NETWORK_JOIN_STATUS_AUTHORIZING,
56 NETWORK_JOIN_STATUS_WAITING,
57 NETWORK_JOIN_STATUS_DOWNLOADING,
58 NETWORK_JOIN_STATUS_PROCESSING,
59 NETWORK_JOIN_STATUS_REGISTERING,
60
61 NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
62 NETWORK_JOIN_STATUS_END,
63 };
64
66 enum NetworkLanguage {
67 NETLANG_ANY = 0,
68 NETLANG_ENGLISH,
69 NETLANG_GERMAN,
70 NETLANG_FRENCH,
71 NETLANG_BRAZILIAN,
72 NETLANG_BULGARIAN,
73 NETLANG_CHINESE,
74 NETLANG_CZECH,
75 NETLANG_DANISH,
76 NETLANG_DUTCH,
77 NETLANG_ESPERANTO,
78 NETLANG_FINNISH,
79 NETLANG_HUNGARIAN,
80 NETLANG_ICELANDIC,
81 NETLANG_ITALIAN,
82 NETLANG_JAPANESE,
83 NETLANG_KOREAN,
84 NETLANG_LITHUANIAN,
85 NETLANG_NORWEGIAN,
86 NETLANG_POLISH,
87 NETLANG_PORTUGUESE,
88 NETLANG_ROMANIAN,
89 NETLANG_RUSSIAN,
90 NETLANG_SLOVAK,
91 NETLANG_SLOVENIAN,
92 NETLANG_SPANISH,
93 NETLANG_SWEDISH,
94 NETLANG_TURKISH,
95 NETLANG_UKRAINIAN,
96 NETLANG_AFRIKAANS,
97 NETLANG_CROATIAN,
98 NETLANG_CATALAN,
99 NETLANG_ESTONIAN,
100 NETLANG_GALICIAN,
101 NETLANG_GREEK,
102 NETLANG_LATVIAN,
103 NETLANG_COUNT
104 };
105
106 extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
107 extern uint32 _frame_counter_max; // To where we may go with our clients
108 extern uint32 _frame_counter;
109
110 extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
111
112 /* networking settings */
113 extern NetworkAddressList _broadcast_list;
114
115 extern uint32 _sync_seed_1;
116 #ifdef NETWORK_SEND_DOUBLE_SEED
117 extern uint32 _sync_seed_2;
118 #endif
119 extern uint32 _sync_frame;
120 extern bool _network_first_time;
121 /* Vars needed for the join-GUI */
122 extern NetworkJoinStatus _network_join_status;
123 extern uint8 _network_join_waiting;
124 extern uint32 _network_join_bytes;
125 extern uint32 _network_join_bytes_total;
126
127 extern uint8 _network_reconnect;
128
129 extern bool _network_udp_server;
130 extern uint16 _network_udp_broadcast;
131
132 extern uint8 _network_advertise_retries;
133
134 extern CompanyMask _network_company_passworded;
135
136 void NetworkTCPQueryServer(NetworkAddress address);
137
138 void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
139 void NetworkAddServer(const char *b);
140 void NetworkRebuildHostList();
141 void UpdateNetworkGameWindow();
142
143 bool IsNetworkCompatibleVersion(const char *version);
144
145 /* From network_command.cpp */
149 struct CommandPacket : CommandContainer {
151 CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
152 CommandPacket *next;
153 CompanyID company;
154 uint32 frame;
155 bool my_cmd;
156 };
157
158 void NetworkDistributeCommands();
159 void NetworkExecuteLocalCommandQueue();
160 void NetworkFreeLocalCommandQueue();
161 void NetworkSyncCommandQueue(NetworkClientSocket *cs);
162
163 void NetworkError(StringID error_string);
164 void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
165 uint NetworkCalculateLag(const NetworkClientSocket *cs);
166 StringID GetNetworkErrorMsg(NetworkErrorCode err);
167 bool NetworkFindName(char *new_name, const char *last);
168 const char *GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed);
169
170 #endif /* NETWORK_INTERNAL_H */
_network_join_waiting
uint8 _network_join_waiting
The number of clients waiting in front of us.
Definition: network_gui.cpp:1977
_network_reconnect
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:62
NetworkAction
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:91
CommandPacket::frame
uint32 frame
the frame in which this packet is executed
Definition: network_internal.h:154
NetworkJoinStatus
NetworkJoinStatus
Status of the clients during joining.
Definition: network_internal.h:53
_network_join_bytes
uint32 _network_join_bytes
The number of bytes we already downloaded.
Definition: network_gui.cpp:1978
NetworkFindName
bool NetworkFindName(char *new_name, const char *last)
Check whether a name is unique, and otherwise try to make it unique.
Definition: network_server.cpp:1715
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:250
NetworkDistributeCommands
void NetworkDistributeCommands()
Distribute the commands of ourself and the clients.
Definition: network_command.cpp:279
CommandContainer
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:479
_network_first_time
bool _network_first_time
Whether we have finished joining or not.
Definition: network.cpp:76
CommandPacket::next
CommandPacket * next
the next command packet (if in queue)
Definition: network_internal.h:152
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
NetworkLanguage
NetworkLanguage
Language ids for server_lang and client_lang.
Definition: network_internal.h:66
CommandPacket::company
CompanyID company
company that is executing the command
Definition: network_internal.h:153
CommandPacket
Everything we need to know about a command to be able to execute it.
Definition: network_internal.h:149
NetworkAddressList
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
Definition: address.h:20
_network_udp_server
bool _network_udp_server
Is the UDP server started?
Definition: network.cpp:77
_network_udp_broadcast
uint16 _network_udp_broadcast
Timeout for the UDP broadcasts.
Definition: network.cpp:78
_network_company_passworded
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
Definition: network.cpp:80
CommandPacket::my_cmd
bool my_cmd
did the command originate from "me"
Definition: network_internal.h:155
GetBindAddresses
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
Get the addresses to bind to.
Definition: network.cpp:623
ServerNetworkGameSocketHandler
Class for handling the server side of the game connection.
Definition: network_server.h:24
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
_ddc_fastforward
#define _ddc_fastforward
Helper variable to make the dedicated server go fast until the (first) join.
Definition: network_internal.h:47
NetworkAddress
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Definition: address.h:29
_last_sync_frame
uint32 _last_sync_frame
Used in the server to store the last time a sync packet was sent to clients.
Definition: network.cpp:69
CommandPacket::CommandPacket
CommandPacket()
Make sure the pointer is nullptr.
Definition: network_internal.h:151
NetworkSyncCommandQueue
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
Sync our local command queue to the command queue of the given socket.
Definition: network_command.cpp:179
_sync_seed_1
uint32 _sync_seed_1
Seed to compare during sync checks.
Definition: network.cpp:71
_sync_frame
uint32 _sync_frame
The frame to perform the sync check.
Definition: network.cpp:75
_network_join_status
NetworkJoinStatus _network_join_status
The status of joining.
Definition: network_gui.cpp:1976
_frame_counter
uint32 _frame_counter
The current frame.
Definition: network.cpp:68
INVALID_COMPANY
@ INVALID_COMPANY
An invalid company.
Definition: company_type.h:30
NetworkExecuteLocalCommandQueue
void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
Definition: network_command.cpp:191
IsNetworkCompatibleVersion
bool IsNetworkCompatibleVersion(const char *version)
Checks whether the given version string is compatible with our version.
Definition: network.cpp:1147
_network_advertise_retries
uint8 _network_advertise_retries
The number of advertisement retries we did.
Definition: network.cpp:79
GetNetworkErrorMsg
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Definition: network.cpp:299
_broadcast_list
NetworkAddressList _broadcast_list
List of broadcast addresses.
Definition: network.cpp:70
UpdateNetworkGameWindow
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Definition: network_gui.cpp:77
tcp_game.h
_frame_counter_server
uint32 _frame_counter_server
The frame_counter of the server, if in network-mode.
Definition: network.cpp:66
GenerateCompanyPasswordHash
const char * GenerateCompanyPasswordHash(const char *password, const char *password_server_id, uint32 password_game_seed)
Hash the given password using server ID and game seed.
Definition: network.cpp:182
NetworkFreeLocalCommandQueue
void NetworkFreeLocalCommandQueue()
Free the local command queues.
Definition: network_command.cpp:225
_network_join_bytes_total
uint32 _network_join_bytes_total
The total number of bytes to download.
Definition: network_gui.cpp:1979
_frame_counter_max
uint32 _frame_counter_max
To where we may go with our clients.
Definition: network.cpp:67
network_func.h
NetworkErrorCode
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:110