1 /* $Id: network_internal.h 26370 2014-02-23 19:32:32Z frosch $ */
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file network_internal.h Variables and function used internally. */
12 #ifndef NETWORK_INTERNAL_H
13 #define NETWORK_INTERNAL_H
15 #include "network_func.h"
16 #include "core/tcp_game.h"
18 #include "../command_type.h"
24 * If this line is enable, every frame will have a sync test
25 * this is not needed in normal games. Normal is like 1 sync in 100
26 * frames. You can enable this if you have a lot of desyncs on a certain
28 * Remember: both client and server have to be compiled with this
29 * option enabled to make it to work. If one of the two has it disabled
30 * nothing will happen.
32 #define ENABLE_NETWORK_SYNC_EVERY_FRAME
35 * In theory sending 1 of the 2 seeds is enough to check for desyncs
36 * so in theory, this next define can be left off.
38 #define NETWORK_SEND_DOUBLE_SEED
39 #endif /* RANDOM_DEBUG */
42 * Helper variable to make the dedicated server go fast until the (first) join.
43 * Used to load the desync debug logs, i.e. for reproducing a desync.
44 * There's basically no need to ever enable this, unless you really know what
45 * you are doing, i.e. debugging a desync.
46 * See docs/desync.txt for details.
48 #ifdef DEBUG_DUMP_COMMANDS
49 extern bool _ddc_fastforward
;
51 #define _ddc_fastforward (false)
52 #endif /* DEBUG_DUMP_COMMANDS */
54 typedef class ServerNetworkGameSocketHandler NetworkClientSocket
;
56 /** Status of the clients during joining. */
57 enum NetworkJoinStatus
{
58 NETWORK_JOIN_STATUS_CONNECTING
,
59 NETWORK_JOIN_STATUS_AUTHORIZING
,
60 NETWORK_JOIN_STATUS_WAITING
,
61 NETWORK_JOIN_STATUS_DOWNLOADING
,
62 NETWORK_JOIN_STATUS_PROCESSING
,
63 NETWORK_JOIN_STATUS_REGISTERING
,
65 NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO
,
66 NETWORK_JOIN_STATUS_END
,
69 /** Language ids for server_lang and client_lang. Do NOT modify the order. */
70 enum NetworkLanguage
{
110 extern uint32 _frame_counter_server
; // The frame_counter of the server, if in network-mode
111 extern uint32 _frame_counter_max
; // To where we may go with our clients
112 extern uint32 _frame_counter
;
114 extern uint32 _last_sync_frame
; // Used in the server to store the last time a sync packet was sent to clients.
116 /* networking settings */
117 extern NetworkAddressList _broadcast_list
;
119 extern uint32 _sync_seed_1
;
120 #ifdef NETWORK_SEND_DOUBLE_SEED
121 extern uint32 _sync_seed_2
;
123 extern uint32 _sync_frame
;
124 extern bool _network_first_time
;
125 /* Vars needed for the join-GUI */
126 extern NetworkJoinStatus _network_join_status
;
127 extern uint8 _network_join_waiting
;
128 extern uint32 _network_join_bytes
;
129 extern uint32 _network_join_bytes_total
;
131 extern uint8 _network_reconnect
;
133 extern bool _network_udp_server
;
134 extern uint16 _network_udp_broadcast
;
136 extern uint8 _network_advertise_retries
;
138 extern CompanyMask _network_company_passworded
;
140 void NetworkTCPQueryServer(NetworkAddress address
);
142 void GetBindAddresses(NetworkAddressList
*addresses
, uint16 port
);
143 void NetworkAddServer(const char *b
);
144 void NetworkRebuildHostList();
145 void UpdateNetworkGameWindow();
147 bool IsNetworkCompatibleVersion(const char *version
);
149 /* From network_command.cpp */
151 * Everything we need to know about a command to be able to execute it.
153 struct CommandPacket
: CommandContainer
{
154 /** Make sure the pointer is nullptr. */
155 CommandPacket() : next(nullptr), company(INVALID_COMPANY
), frame(0), my_cmd(false) {}
156 CommandPacket
*next
; ///< the next command packet (if in queue)
157 CompanyID company
; ///< company that is executing the command
158 uint32 frame
; ///< the frame in which this packet is executed
159 bool my_cmd
; ///< did the command originate from "me"
162 void NetworkDistributeCommands();
163 void NetworkExecuteLocalCommandQueue();
164 void NetworkFreeLocalCommandQueue();
165 void NetworkSyncCommandQueue(NetworkClientSocket
*cs
);
167 void NetworkError(StringID error_string
);
168 void NetworkTextMessage(NetworkAction action
, TextColour colour
, bool self_send
, const char *name
, const char *str
= "", NetworkTextMessageData data
= NetworkTextMessageData());
169 uint
NetworkCalculateLag(const NetworkClientSocket
*cs
);
170 StringID
GetNetworkErrorMsg(NetworkErrorCode err
);
171 bool NetworkFindName(char *new_name
, const char *last
);
172 const char *GenerateCompanyPasswordHash(const char *password
, const char *password_server_id
, uint32 password_game_seed
);
174 #endif /* ENABLE_NETWORK */
175 #endif /* NETWORK_INTERNAL_H */