author | truebrain |
Fri, 18 Jul 2008 10:15:16 +0000 | |
branch | noai |
changeset 11168 | 3842648184cd |
parent 10829 | 8a0ec0f0f928 |
permissions | -rw-r--r-- |
9724 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9837
diff
changeset
|
3 |
/** @file network_internal.h Variables and function used internally. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9837
diff
changeset
|
4 |
|
9724 | 5 |
#ifndef NETWORK_INTERNAL_H |
6 |
#define NETWORK_INTERNAL_H |
|
7 |
||
8 |
#ifdef ENABLE_NETWORK |
|
9 |
||
10829 | 10 |
#include "network.h" |
11 |
#include "network_func.h" |
|
12 |
#include "core/os_abstraction.h" |
|
13 |
#include "core/core.h" |
|
9724 | 14 |
#include "core/config.h" |
10829 | 15 |
#include "core/packet.h" |
16 |
#include "core/tcp.h" |
|
9724 | 17 |
|
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
18 |
/** |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
19 |
* If this line is enable, every frame will have a sync test |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
20 |
* this is not needed in normal games. Normal is like 1 sync in 100 |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
21 |
* frames. You can enable this if you have a lot of desyncs on a certain |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
22 |
* game. |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
23 |
* Remember: both client and server have to be compiled with this |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
24 |
* option enabled to make it to work. If one of the two has it disabled |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
25 |
* nothing will happen. |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
26 |
*/ |
9724 | 27 |
//#define ENABLE_NETWORK_SYNC_EVERY_FRAME |
28 |
||
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
29 |
/** |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
30 |
* In theory sending 1 of the 2 seeds is enough to check for desyncs |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
31 |
* so in theory, this next define can be left off. |
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
32 |
*/ |
9724 | 33 |
//#define NETWORK_SEND_DOUBLE_SEED |
34 |
||
10829 | 35 |
#define MAX_TEXT_MSG_LEN 1024 /* long long long long sentences :-) */ |
9724 | 36 |
|
10829 | 37 |
enum MapPacket { |
38 |
MAP_PACKET_START, |
|
39 |
MAP_PACKET_NORMAL, |
|
40 |
MAP_PACKET_END, |
|
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
41 |
}; |
9724 | 42 |
|
43 |
||
44 |
enum NetworkJoinStatus { |
|
45 |
NETWORK_JOIN_STATUS_CONNECTING, |
|
46 |
NETWORK_JOIN_STATUS_AUTHORIZING, |
|
47 |
NETWORK_JOIN_STATUS_WAITING, |
|
48 |
NETWORK_JOIN_STATUS_DOWNLOADING, |
|
49 |
NETWORK_JOIN_STATUS_PROCESSING, |
|
50 |
NETWORK_JOIN_STATUS_REGISTERING, |
|
51 |
||
52 |
NETWORK_JOIN_STATUS_GETTING_COMPANY_INFO, |
|
53 |
}; |
|
54 |
||
9837
c9ec4f82e0d0
(svn r12503) [NoAI] -Sync: with trunk r12461:12501.
rubidium
parents:
9826
diff
changeset
|
55 |
/** Language ids for server_lang and client_lang. Do NOT modify the order. */ |
9724 | 56 |
enum NetworkLanguage { |
57 |
NETLANG_ANY = 0, |
|
58 |
NETLANG_ENGLISH, |
|
59 |
NETLANG_GERMAN, |
|
60 |
NETLANG_FRENCH, |
|
61 |
NETLANG_BRAZILIAN, |
|
62 |
NETLANG_BULGARIAN, |
|
63 |
NETLANG_CHINESE, |
|
64 |
NETLANG_CZECH, |
|
65 |
NETLANG_DANISH, |
|
66 |
NETLANG_DUTCH, |
|
67 |
NETLANG_ESPERANTO, |
|
68 |
NETLANG_FINNISH, |
|
69 |
NETLANG_HUNGARIAN, |
|
70 |
NETLANG_ICELANDIC, |
|
71 |
NETLANG_ITALIAN, |
|
72 |
NETLANG_JAPANESE, |
|
73 |
NETLANG_KOREAN, |
|
74 |
NETLANG_LITHUANIAN, |
|
75 |
NETLANG_NORWEGIAN, |
|
76 |
NETLANG_POLISH, |
|
77 |
NETLANG_PORTUGUESE, |
|
78 |
NETLANG_ROMANIAN, |
|
79 |
NETLANG_RUSSIAN, |
|
80 |
NETLANG_SLOVAK, |
|
81 |
NETLANG_SLOVENIAN, |
|
82 |
NETLANG_SPANISH, |
|
83 |
NETLANG_SWEDISH, |
|
84 |
NETLANG_TURKISH, |
|
85 |
NETLANG_UKRAINIAN, |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
86 |
NETLANG_AFRIKAANS, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
87 |
NETLANG_CROATIAN, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
88 |
NETLANG_CATALAN, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
89 |
NETLANG_ESTONIAN, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
90 |
NETLANG_GALICIAN, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
91 |
NETLANG_GREEK, |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9724
diff
changeset
|
92 |
NETLANG_LATVIAN, |
9724 | 93 |
NETLANG_COUNT |
94 |
}; |
|
95 |
||
10829 | 96 |
extern NetworkPlayerInfo _network_player_info[MAX_PLAYERS]; |
9724 | 97 |
|
10829 | 98 |
extern uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode |
99 |
extern uint32 _frame_counter_max; // To where we may go with our clients |
|
9724 | 100 |
|
10829 | 101 |
extern uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients. |
9724 | 102 |
|
103 |
// networking settings |
|
10829 | 104 |
extern uint32 _broadcast_list[MAX_INTERFACES + 1]; |
9724 | 105 |
|
10829 | 106 |
extern uint32 _network_server_bind_ip; |
9724 | 107 |
|
10829 | 108 |
extern uint32 _sync_seed_1, _sync_seed_2; |
109 |
extern uint32 _sync_frame; |
|
110 |
extern bool _network_first_time; |
|
111 |
// Vars needed for the join-GUI |
|
112 |
extern NetworkJoinStatus _network_join_status; |
|
113 |
extern uint8 _network_join_waiting; |
|
114 |
extern uint16 _network_join_kbytes; |
|
115 |
extern uint16 _network_join_kbytes_total; |
|
9724 | 116 |
|
10829 | 117 |
extern uint32 _network_last_host_ip; |
118 |
extern uint8 _network_reconnect; |
|
9724 | 119 |
|
10829 | 120 |
extern bool _network_udp_server; |
121 |
extern uint16 _network_udp_broadcast; |
|
9724 | 122 |
|
10829 | 123 |
extern uint8 _network_advertise_retries; |
124 |
||
125 |
// following externs are instantiated at network.cpp |
|
126 |
extern CommandPacket *_local_command_queue; |
|
127 |
||
128 |
// Here we keep track of the clients |
|
129 |
// (and the client uses [0] for his own communication) |
|
130 |
extern NetworkTCPSocketHandler _clients[MAX_CLIENTS]; |
|
9724 | 131 |
|
132 |
void NetworkTCPQueryServer(const char* host, unsigned short port); |
|
133 |
||
134 |
void NetworkAddServer(const char *b); |
|
135 |
void NetworkRebuildHostList(); |
|
136 |
void UpdateNetworkGameWindow(bool unselect); |
|
137 |
||
138 |
bool IsNetworkCompatibleVersion(const char *version); |
|
139 |
||
10829 | 140 |
void NetworkExecuteCommand(CommandPacket *cp); |
141 |
void NetworkAddCommandQueue(NetworkTCPSocketHandler *cs, CommandPacket *cp); |
|
142 |
||
143 |
// from network.c |
|
144 |
void NetworkCloseClient(NetworkTCPSocketHandler *cs); |
|
145 |
void CDECL NetworkTextMessage(NetworkAction action, ConsoleColour color, bool self_send, const char *name, const char *str, ...); |
|
146 |
void NetworkGetClientName(char *clientname, size_t size, const NetworkTCPSocketHandler *cs); |
|
147 |
uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs); |
|
148 |
byte NetworkGetCurrentLanguageIndex(); |
|
149 |
NetworkTCPSocketHandler *NetworkFindClientStateFromIndex(uint16 client_index); |
|
150 |
unsigned long NetworkResolveHost(const char *hostname); |
|
151 |
char* GetNetworkErrorMsg(char* buf, NetworkErrorCode err, const char* last); |
|
152 |
bool NetworkFindName(char new_name[NETWORK_CLIENT_NAME_LENGTH]); |
|
153 |
||
154 |
#define DEREF_CLIENT(i) (&_clients[i]) |
|
155 |
// This returns the NetworkClientInfo from a NetworkClientState |
|
156 |
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients]) |
|
157 |
||
158 |
// Macros to make life a bit more easier |
|
159 |
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p) |
|
160 |
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command() |
|
161 |
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command |
|
162 |
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkTCPSocketHandler *cs, Packet *p) |
|
163 |
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkTCPSocketHandler *cs) |
|
164 |
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command |
|
165 |
||
166 |
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command |
|
167 |
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command |
|
168 |
||
169 |
#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != endof(_clients) && cs->IsConnected(); cs++) |
|
170 |
||
9724 | 171 |
#endif /* ENABLE_NETWORK */ |
172 |
#endif /* NETWORK_INTERNAL_H */ |