# network_internal.h

Go to the documentation of this file.

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