OpenTTD
network_internal.h
Go to the documentation of this file.
1 /* $Id: network_internal.h 26488 2014-04-23 21:19:54Z rubidium $ */
2 
3 /*
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/>.
8  */
9 
12 #ifndef NETWORK_INTERNAL_H
13 #define NETWORK_INTERNAL_H
14 
15 #include "network_func.h"
16 #include "core/tcp_game.h"
17 
18 #include "../command_type.h"
19 
20 #ifdef ENABLE_NETWORK
21 
22 #ifdef RANDOM_DEBUG
23 
32 #define ENABLE_NETWORK_SYNC_EVERY_FRAME
33 
38 #define NETWORK_SEND_DOUBLE_SEED
39 #endif /* RANDOM_DEBUG */
40 
48 #ifdef DEBUG_DUMP_COMMANDS
49 extern bool _ddc_fastforward;
50 #else
51 #define _ddc_fastforward (false)
52 #endif /* DEBUG_DUMP_COMMANDS */
53 
54 typedef class ServerNetworkGameSocketHandler NetworkClientSocket;
55 
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,
64 
65  NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
66  NETWORK_JOIN_STATUS_END,
67 };
68 
71  NETLANG_ANY = 0,
72  NETLANG_ENGLISH,
73  NETLANG_GERMAN,
74  NETLANG_FRENCH,
75  NETLANG_BRAZILIAN,
76  NETLANG_BULGARIAN,
77  NETLANG_CHINESE,
78  NETLANG_CZECH,
79  NETLANG_DANISH,
80  NETLANG_DUTCH,
81  NETLANG_ESPERANTO,
82  NETLANG_FINNISH,
83  NETLANG_HUNGARIAN,
84  NETLANG_ICELANDIC,
85  NETLANG_ITALIAN,
86  NETLANG_JAPANESE,
87  NETLANG_KOREAN,
88  NETLANG_LITHUANIAN,
89  NETLANG_NORWEGIAN,
90  NETLANG_POLISH,
91  NETLANG_PORTUGUESE,
92  NETLANG_ROMANIAN,
93  NETLANG_RUSSIAN,
94  NETLANG_SLOVAK,
95  NETLANG_SLOVENIAN,
96  NETLANG_SPANISH,
97  NETLANG_SWEDISH,
98  NETLANG_TURKISH,
99  NETLANG_UKRAINIAN,
100  NETLANG_AFRIKAANS,
101  NETLANG_CROATIAN,
102  NETLANG_CATALAN,
103  NETLANG_ESTONIAN,
104  NETLANG_GALICIAN,
105  NETLANG_GREEK,
106  NETLANG_LATVIAN,
107  NETLANG_COUNT
108 };
109 
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;
113 
114 extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
115 
116 /* networking settings */
118 
119 extern uint32 _sync_seed_1;
120 #ifdef NETWORK_SEND_DOUBLE_SEED
121 extern uint32 _sync_seed_2;
122 #endif
123 extern uint32 _sync_frame;
124 extern bool _network_first_time;
125 /* Vars needed for the join-GUI */
127 extern uint8 _network_join_waiting;
128 extern uint32 _network_join_bytes;
129 extern uint32 _network_join_bytes_total;
130 
131 extern uint8 _network_reconnect;
132 
133 extern bool _network_udp_server;
134 extern uint16 _network_udp_broadcast;
135 
136 extern uint8 _network_advertise_retries;
137 
138 extern CompanyMask _network_company_passworded;
139 
140 void NetworkTCPQueryServer(NetworkAddress address);
141 
142 void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
143 void NetworkAddServer(const char *b);
144 void NetworkRebuildHostList();
146 
147 bool IsNetworkCompatibleVersion(const char *version);
148 
149 /* From network_command.cpp */
158  uint32 frame;
159  bool my_cmd;
160 };
161 
165 void NetworkSyncCommandQueue(NetworkClientSocket *cs);
166 
167 void NetworkError(StringID error_string);
168 void NetworkTextMessage(NetworkAction action, TextColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
169 uint NetworkCalculateLag(const NetworkClientSocket *cs);
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);
173 
174 #endif /* ENABLE_NETWORK */
175 #endif /* NETWORK_INTERNAL_H */
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:194
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:1107
NetworkErrorCode
The error codes we send around in the protocols.
Definition: network_type.h:104
CommandPacket()
Make sure the pointer is NULL.
#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:31
uint32 _frame_counter
The current frame.
Definition: network.cpp:72
uint32 _sync_seed_1
Seed to compare during sync checks.
Definition: network.cpp:75
Class for handling the server side of the game connection.
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:70
NetworkAddressList _broadcast_list
List of broadcast addresses.
Definition: network.cpp:74
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:472
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:247
uint32 _frame_counter_max
To where we may go with our clients.
Definition: network.cpp:71
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:310
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
void GetBindAddresses(NetworkAddressList *addresses, uint16 port)
Get the addresses to bind to.
Definition: network.cpp:635
bool _network_udp_server
Is the UDP server started?
Definition: network.cpp:81
void UpdateNetworkGameWindow()
Update the network new window because a new server is found on the network.
Definition: network_gui.cpp:84
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.
NetworkJoinStatus
Status of the clients during joining.
CompanyMask _network_company_passworded
Bitmask of the password status of all companies.
Definition: network.cpp:84
uint16 _network_udp_broadcast
Timeout for the UDP broadcasts.
Definition: network.cpp:82
uint8 _network_reconnect
Reconnect timeout.
Definition: network.cpp:66
uint8 _network_advertise_retries
The number of advertisement retries we did.
Definition: network.cpp:83
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:73
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:80
Owner
Enum for all companies/owners.
Definition: company_type.h:20
uint32 _sync_frame
The frame to perform the sync check.
Definition: network.cpp:79
bool my_cmd
did the command originate from "me"
CommandPacket * next
the next command packet (if in queue)
An invalid company.
Definition: company_type.h:32
NetworkAction
Actions that can be used for NetworkTextMessage.
Definition: network_type.h:89
void NetworkFreeLocalCommandQueue()
Free the local command queues.