# network_internal.h

Go to the documentation of this file.

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