OpenTTD
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 
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 
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 */
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 */
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();
142 
143 bool IsNetworkCompatibleVersion(const char *version);
144 
145 /* From network_command.cpp */
151  CommandPacket() : next(nullptr), company(INVALID_COMPANY), frame(0), my_cmd(false) {}
154  uint32 frame;
155  bool my_cmd;
156 };
157 
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);
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 */
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Basic functions to receive and send TCP packets for game purposes.
void NetworkSyncCommandQueue(NetworkClientSocket *cs)
Sync our local command queue to the command queue of the given socket.
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
NetworkJoinStatus _network_join_status
The status of joining.
bool IsNetworkCompatibleVersion(const char *version)
Checks whether the given version string is compatible with our version.
Definition: network.cpp:1142
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:100
CommandPacket()
Make sure the pointer is nullptr.
#define _ddc_fastforward
Helper variable to make the dedicated server go fast until the (first) join.
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:27
uint32 _frame_counter
The current frame.
Definition: network.cpp:68
uint32 _sync_seed_1
Seed to compare during sync checks.
Definition: network.cpp:71
Class for handling the server side of the game connection.
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
Definition: address.h:18
void NetworkDistributeCommands()
Distribute the commands of ourself and the clients.
uint32 _frame_counter_server
The frame_counter of the server, if in network-mode.
Definition: network.cpp:66
NetworkAddressList _broadcast_list
List of broadcast addresses.
Definition: network.cpp:70
uint32 _network_join_bytes
The number of bytes we already downloaded.
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:475
uint8 _network_join_waiting
The number of clients waiting in front of us.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
uint32 _frame_counter_max
To where we may go with our clients.
Definition: network.cpp:67
NetworkLanguage
Language ids for server_lang and client_lang.
CompanyID company
company that is executing the command
uint32 _network_join_bytes_total
The total number of bytes to download.
uint32 frame
the frame in which this packet is executed
StringID GetNetworkErrorMsg(NetworkErrorCode err)
Retrieve the string id of an internal error number.
Definition: network.cpp:298
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
Get the addresses to bind to.
Definition: network.cpp:619
bool _network_udp_server
Is the UDP server started?
Definition: network.cpp:77
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Definition: network_gui.cpp:82
void NetworkExecuteLocalCommandQueue()
Execute all commands on the local command queue that ought to be executed this frame.
bool NetworkFindName(char *new_name, const char *last)
Check whether a name is unique, and otherwise try to make it unique.
An invalid company.
Definition: company_type.h:30
NetworkJoinStatus
Status of the clients during joining.
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
Definition: network.cpp:80
uint16 _network_udp_broadcast
Timeout for the UDP broadcasts.
Definition: network.cpp:78
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:62
uint8 _network_advertise_retries
The number of advertisement retries we did.
Definition: network.cpp:79
Network functions used by other parts of OpenTTD.
uint32 _last_sync_frame
Used in the server to store the last time a sync packet was sent to clients.
Definition: network.cpp:69
Everything we need to know about a command to be able to execute it.
bool _network_first_time
Whether we have finished joining or not.
Definition: network.cpp:76
uint32 _sync_frame
The frame to perform the sync check.
Definition: network.cpp:75
bool my_cmd
did the command originate from "me"
CommandPacket * next
the next command packet (if in queue)
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:85
void NetworkFreeLocalCommandQueue()
Free the local command queues.