# network_internal.h

Go to the documentation of this file.

    00001 /* $Id: network_internal.h 19622 2010-04-13 19:30:51Z rubidium $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef NETWORK_INTERNAL_H
    00013 #define NETWORK_INTERNAL_H
    00014
    00015 #include "network_func.h"
    00016 #include "core/tcp_game.h"
    00017
    00018 #include "../command_type.h"
    00019
    00020 #ifdef ENABLE_NETWORK
    00021
    00022 #ifdef RANDOM_DEBUG
    00023
    00032 #define ENABLE_NETWORK_SYNC_EVERY_FRAME
    00033
    00038 #define NETWORK_SEND_DOUBLE_SEED
    00039 #endif /* RANDOM_DEBUG */
    00040
    00047 #ifdef DEBUG_DUMP_COMMANDS
    00048 extern bool _ddc_fastforward;
    00049 #else
    00050 #define _ddc_fastforward (false)
    00051 #endif /* DEBUG_DUMP_COMMANDS */
    00052
    00053 enum MapPacket {
    00054   MAP_PACKET_START,
    00055   MAP_PACKET_NORMAL,
    00056   MAP_PACKET_END,
    00057 };
    00058
    00059
    00060 enum NetworkJoinStatus {
    00061   NETWORK_JOIN_STATUS_CONNECTING,
    00062   NETWORK_JOIN_STATUS_AUTHORIZING,
    00063   NETWORK_JOIN_STATUS_WAITING,
    00064   NETWORK_JOIN_STATUS_DOWNLOADING,
    00065   NETWORK_JOIN_STATUS_PROCESSING,
    00066   NETWORK_JOIN_STATUS_REGISTERING,
    00067
    00068   NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO,
    00069   NETWORK_JOIN_STATUS_END,
    00070 };
    00071
    00073 enum NetworkLanguage {
    00074   NETLANG_ANY = 0,
    00075   NETLANG_ENGLISH,
    00076   NETLANG_GERMAN,
    00077   NETLANG_FRENCH,
    00078   NETLANG_BRAZILIAN,
    00079   NETLANG_BULGARIAN,
    00080   NETLANG_CHINESE,
    00081   NETLANG_CZECH,
    00082   NETLANG_DANISH,
    00083   NETLANG_DUTCH,
    00084   NETLANG_ESPERANTO,
    00085   NETLANG_FINNISH,
    00086   NETLANG_HUNGARIAN,
    00087   NETLANG_ICELANDIC,
    00088   NETLANG_ITALIAN,
    00089   NETLANG_JAPANESE,
    00090   NETLANG_KOREAN,
    00091   NETLANG_LITHUANIAN,
    00092   NETLANG_NORWEGIAN,
    00093   NETLANG_POLISH,
    00094   NETLANG_PORTUGUESE,
    00095   NETLANG_ROMANIAN,
    00096   NETLANG_RUSSIAN,
    00097   NETLANG_SLOVAK,
    00098   NETLANG_SLOVENIAN,
    00099   NETLANG_SPANISH,
    00100   NETLANG_SWEDISH,
    00101   NETLANG_TURKISH,
    00102   NETLANG_UKRAINIAN,
    00103   NETLANG_AFRIKAANS,
    00104   NETLANG_CROATIAN,
    00105   NETLANG_CATALAN,
    00106   NETLANG_ESTONIAN,
    00107   NETLANG_GALICIAN,
    00108   NETLANG_GREEK,
    00109   NETLANG_LATVIAN,
    00110   NETLANG_COUNT
    00111 };
    00112
    00113 extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
    00114 extern uint32 _frame_counter_max; // To where we may go with our clients
    00115 extern uint32 _frame_counter;
    00116
    00117 extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
    00118
    00119 /* networking settings */
    00120 extern NetworkAddressList _broadcast_list;
    00121
    00122 extern uint32 _sync_seed_1;
    00123 #ifdef NETWORK_SEND_DOUBLE_SEED
    00124 extern uint32 _sync_seed_2;
    00125 #endif
    00126 extern uint32 _sync_frame;
    00127 extern bool _network_first_time;
    00128 /* Vars needed for the join-GUI */
    00129 extern NetworkJoinStatus _network_join_status;
    00130 extern uint8 _network_join_waiting;
    00131 extern uint32 _network_join_bytes;
    00132 extern uint32 _network_join_bytes_total;
    00133
    00134 extern uint8 _network_reconnect;
    00135
    00136 extern bool _network_udp_server;
    00137 extern uint16 _network_udp_broadcast;
    00138
    00139 extern uint8 _network_advertise_retries;
    00140
    00141 extern CompanyMask _network_company_passworded;
    00142
    00143 void NetworkTCPQueryServer(NetworkAddress address);
    00144
    00145 void GetBindAddresses(NetworkAddressList *addresses, uint16 port);
    00146 void NetworkAddServer(const char *b);
    00147 void NetworkRebuildHostList();
    00148 void UpdateNetworkGameWindow(bool unselect);
    00149
    00150 bool IsNetworkCompatibleVersion(const char *version);
    00151
    00152 /* From network_command.cpp */
    00156 struct CommandPacket : CommandContainer {
    00157   CommandPacket *next;
    00158   CompanyByte company;
    00159   uint32 frame;
    00160   bool my_cmd;
    00161 };
    00162
    00163 void NetworkAddCommandQueue(CommandPacket cp, NetworkClientSocket *cs = NULL);
    00164 void NetworkExecuteLocalCommandQueue();
    00165 void NetworkFreeLocalCommandQueue();
    00166 void NetworkSyncCommandQueue(NetworkClientSocket *cs);
    00167
    00168 /* from network.c */
    00169 NetworkRecvStatus NetworkCloseClient(NetworkClientSocket *cs, NetworkRecvStatus status);
    00170 void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str = "", int64 data = 0);
    00171 void NetworkGetClientName(char *clientname, size_t size, const NetworkClientSocket *cs);
    00172 uint NetworkCalculateLag(const NetworkClientSocket *cs);
    00173 byte NetworkGetCurrentLanguageIndex();
    00174 NetworkClientSocket *NetworkFindClientStateFromClientID(ClientID client_id);
    00175 StringID GetNetworkErrorMsg(NetworkErrorCode err);
    00176 bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]);
    00177
    00178 /* Macros to make life a bit more easier */
    00179 #define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p)
    00180 #define DEF_CLIENT_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command()
    00181 #define DEF_CLIENT_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
    00182 #define DEF_SERVER_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(NetworkClientSocket *cs, Packet *p)
    00183 #define DEF_SERVER_SEND_COMMAND(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command(NetworkClientSocket *cs)
    00184 #define DEF_SERVER_SEND_COMMAND_PARAM(type) NetworkRecvStatus NetworkPacketSend_ ## type ## _command
    00185
    00186 #define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command
    00187 #define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command
    00188
    00189 #endif /* ENABLE_NETWORK */
    00190 #endif /* NETWORK_INTERNAL_H */