author | truelight |
Thu, 24 Mar 2005 14:43:40 +0000 | |
changeset 1540 | 6eef12dab5bf |
parent 1466 | 93e67e9654c5 |
child 1804 | fbe724472bb4 |
permissions | -rw-r--r-- |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
1 |
#ifndef NETWORK_DATA_H |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
2 |
#define NETWORK_DATA_H |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
3 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
4 |
#include "ttd.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
5 |
#include "network.h" |
1441
3c9130c733f3
(svn r1945) - CodeChange: re-commit of rev 1835: "Reduce the visibility of network_core.h (Tron)".
darkvater
parents:
1341
diff
changeset
|
6 |
#include "network_core.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
7 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
8 |
// Is the network enabled? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
9 |
#ifdef ENABLE_NETWORK |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
10 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
11 |
#define SEND_MTU 1460 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
12 |
#define MAX_TEXT_MSG_LEN 1024 /* long long long long sentences :-) */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
13 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
14 |
// The client-info-server-index is always 1 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
15 |
#define NETWORK_SERVER_INDEX 1 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
16 |
#define NETWORK_EMPTY_INDEX 0 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
17 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
18 |
// What version of game-info do we use? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
19 |
#define NETWORK_GAME_INFO_VERSION 1 |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
20 |
// What version of company info is this? |
1188
c322ea2768bc
(svn r1691) -Fix: oops, forgot to bump the company-info-version
truelight
parents:
1093
diff
changeset
|
21 |
#define NETWORK_COMPANY_INFO_VERSION 3 |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
619
diff
changeset
|
22 |
// What version of master-server-protocol do we use? |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
619
diff
changeset
|
23 |
#define NETWORK_MASTER_SERVER_VERSION 1 |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
24 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
25 |
typedef uint16 PacketSize; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
26 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
27 |
typedef struct Packet { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
28 |
struct Packet *next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
29 |
PacketSize size; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
PacketSize pos; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
31 |
byte buffer[SEND_MTU]; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
32 |
} Packet; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
33 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
34 |
typedef struct CommandPacket { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
35 |
struct CommandPacket *next; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
36 |
byte player; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
37 |
uint32 cmd; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
38 |
uint32 p1; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
39 |
uint32 p2; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
40 |
uint32 tile; // Always make it uint32, so it is bigmap compatible |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
41 |
uint32 dp[20]; // decode_params |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
42 |
uint32 frame; // In which frame must this packet be executed? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
43 |
byte callback; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
44 |
} CommandPacket; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
45 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
46 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
47 |
STATUS_INACTIVE, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
48 |
STATUS_AUTH, // This means that the client is authorized |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
49 |
STATUS_MAP_WAIT, // This means that the client is put on hold because someone else is getting the map |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
50 |
STATUS_MAP, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
51 |
STATUS_DONE_MAP, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
52 |
STATUS_PRE_ACTIVE, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
53 |
STATUS_ACTIVE, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
54 |
} ClientStatus; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
55 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
56 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
57 |
MAP_PACKET_START, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
58 |
MAP_PACKET_NORMAL, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
59 |
MAP_PACKET_PATCH, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
60 |
MAP_PACKET_END, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
61 |
} MapPacket; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
62 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
63 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
64 |
NETWORK_RECV_STATUS_OKAY, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
65 |
NETWORK_RECV_STATUS_DESYNC, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
66 |
NETWORK_RECV_STATUS_SAVEGAME, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
67 |
NETWORK_RECV_STATUS_CONN_LOST, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
NETWORK_RECV_STATUS_MALFORMED_PACKET, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
NETWORK_RECV_STATUS_SERVER_ERROR, // The server told us we made an error |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
NETWORK_RECV_STATUS_SERVER_FULL, |
841
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
764
diff
changeset
|
71 |
NETWORK_RECV_STATUS_SERVER_BANNED, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
72 |
NETWORK_RECV_STATUS_CLOSE_QUERY, // Done quering the server |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
73 |
} NetworkRecvStatus; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
74 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
76 |
NETWORK_ERROR_GENERAL, // Try to use thisone like never |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
77 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
78 |
// Signals from clients |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
79 |
NETWORK_ERROR_DESYNC, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
80 |
NETWORK_ERROR_SAVEGAME_FAILED, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
81 |
NETWORK_ERROR_CONNECTION_LOST, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
82 |
NETWORK_ERROR_ILLEGAL_PACKET, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
83 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
84 |
// Signals from servers |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
85 |
NETWORK_ERROR_NOT_AUTHORIZED, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
86 |
NETWORK_ERROR_NOT_EXPECTED, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
87 |
NETWORK_ERROR_WRONG_REVISION, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
88 |
NETWORK_ERROR_NAME_IN_USE, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
89 |
NETWORK_ERROR_WRONG_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
90 |
NETWORK_ERROR_PLAYER_MISMATCH, // Happens in CLIENT_COMMAND |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
91 |
NETWORK_ERROR_KICKED, |
748
fa61195ee8a8
(svn r1204) -Add: [Network] Added some cheaters-protection (money-cheat mostly)
truelight
parents:
722
diff
changeset
|
92 |
NETWORK_ERROR_CHEATER, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
93 |
} NetworkErrorCode; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
94 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
95 |
// Actions that can be used for NetworkTextMessage |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
96 |
typedef enum { |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
97 |
NETWORK_ACTION_JOIN, |
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
98 |
NETWORK_ACTION_LEAVE, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
99 |
NETWORK_ACTION_CHAT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
100 |
NETWORK_ACTION_CHAT_PLAYER, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
101 |
NETWORK_ACTION_CHAT_CLIENT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
102 |
NETWORK_ACTION_GIVE_MONEY, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
103 |
NETWORK_ACTION_NAME_CHANGE, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
104 |
} NetworkAction; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
105 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
106 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
107 |
NETWORK_GAME_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
108 |
NETWORK_COMPANY_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
109 |
} NetworkPasswordType; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
110 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
111 |
// To keep the clients all together |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
112 |
typedef struct NetworkClientState { |
1466 | 113 |
SOCKET socket; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
114 |
uint16 index; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
115 |
uint32 last_frame; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
116 |
uint32 last_frame_server; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
117 |
byte lag_test; // This byte is used for lag-testing the client |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
118 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
119 |
ClientStatus status; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
120 |
bool writable; // is client ready to write to? |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
121 |
bool quited; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
122 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
123 |
Packet *packet_queue; // Packets that are awaiting delivery |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
124 |
Packet *packet_recv; // Partially received packet |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
125 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
126 |
CommandPacket *command_queue; // The command-queue awaiting delivery |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
127 |
} NetworkClientState; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
128 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
129 |
// What packet types are there |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
130 |
// WARNING: The first 3 packets can NEVER change order again |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
131 |
// it protects old clients from joining newer servers (because SERVER_ERROR |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
132 |
// is the respond to a wrong revision) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
133 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
134 |
PACKET_SERVER_FULL, |
841
4874b9ce2765
(svn r1322) -Add: banning system (mostly tnx to guru3)
truelight
parents:
764
diff
changeset
|
135 |
PACKET_SERVER_BANNED, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
136 |
PACKET_CLIENT_JOIN, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
137 |
PACKET_SERVER_ERROR, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
138 |
PACKET_CLIENT_COMPANY_INFO, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
139 |
PACKET_SERVER_COMPANY_INFO, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
140 |
PACKET_SERVER_CLIENT_INFO, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
141 |
PACKET_SERVER_NEED_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
142 |
PACKET_CLIENT_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
143 |
PACKET_SERVER_WELCOME, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
144 |
PACKET_CLIENT_GETMAP, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
145 |
PACKET_SERVER_WAIT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
146 |
PACKET_SERVER_MAP, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
147 |
PACKET_CLIENT_MAP_OK, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
148 |
PACKET_SERVER_JOIN, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
149 |
PACKET_SERVER_FRAME, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
150 |
PACKET_SERVER_SYNC, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
151 |
PACKET_CLIENT_ACK, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
152 |
PACKET_CLIENT_COMMAND, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
153 |
PACKET_SERVER_COMMAND, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
154 |
PACKET_CLIENT_CHAT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
155 |
PACKET_SERVER_CHAT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
156 |
PACKET_CLIENT_SET_PASSWORD, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
157 |
PACKET_CLIENT_SET_NAME, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
158 |
PACKET_CLIENT_QUIT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
159 |
PACKET_CLIENT_ERROR, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
160 |
PACKET_SERVER_QUIT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
161 |
PACKET_SERVER_ERROR_QUIT, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
162 |
PACKET_SERVER_SHUTDOWN, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
163 |
PACKET_SERVER_NEWGAME, |
1026
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1011
diff
changeset
|
164 |
PACKET_SERVER_RCON, |
02cc18821508
(svn r1527) -Add: RCon (Remote Connection). A server can set:
truelight
parents:
1011
diff
changeset
|
165 |
PACKET_CLIENT_RCON, |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
166 |
PACKET_END // Should ALWAYS be on the end of this list!! (period) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
167 |
} PacketType; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
168 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
169 |
typedef enum { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
170 |
DESTTYPE_BROADCAST, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
171 |
DESTTYPE_PLAYER, |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
172 |
DESTTYPE_CLIENT |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
173 |
} DestType; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
174 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
175 |
CommandPacket *_local_command_queue; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
176 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
177 |
SOCKET _udp_client_socket; // udp client socket |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
748
diff
changeset
|
178 |
SOCKET _udp_server_socket; // udp server socket |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
748
diff
changeset
|
179 |
SOCKET _udp_master_socket; // udp master socket |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
180 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
181 |
// Here we keep track of the clients |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
182 |
// (and the client uses [0] for his own communication) |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
183 |
NetworkClientState _clients[MAX_CLIENTS]; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
184 |
#define DEREF_CLIENT(i) (&_clients[i]) |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
185 |
// This returns the NetworkClientInfo from a NetworkClientState |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
186 |
#define DEREF_CLIENT_INFO(cs) (&_network_client_info[cs - _clients]) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
187 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
188 |
// Macros to make life a bit more easier |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
189 |
#define DEF_CLIENT_RECEIVE_COMMAND(type) NetworkRecvStatus NetworkPacketReceive_ ## type ## _command(Packet *p) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
190 |
#define DEF_CLIENT_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
191 |
#define DEF_CLIENT_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
192 |
#define DEF_SERVER_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(NetworkClientState *cs, Packet *p) |
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
193 |
#define DEF_SERVER_SEND_COMMAND(type) void NetworkPacketSend_ ## type ## _command(NetworkClientState *cs) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
194 |
#define DEF_SERVER_SEND_COMMAND_PARAM(type) void NetworkPacketSend_ ## type ## _command |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
195 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
196 |
#define SEND_COMMAND(type) NetworkPacketSend_ ## type ## _command |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
197 |
#define RECEIVE_COMMAND(type) NetworkPacketReceive_ ## type ## _command |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
198 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
199 |
#define FOR_ALL_CLIENTS(cs) for (cs = _clients; cs != &_clients[MAX_CLIENTS] && cs->socket != INVALID_SOCKET; cs++) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
200 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
201 |
Packet *NetworkSend_Init(PacketType type); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
202 |
void NetworkSend_uint8(Packet *packet, uint8 data); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
203 |
void NetworkSend_uint16(Packet *packet, uint16 data); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
204 |
void NetworkSend_uint32(Packet *packet, uint32 data); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
205 |
void NetworkSend_uint64(Packet *packet, uint64 data); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
206 |
void NetworkSend_string(Packet *packet, const char* data); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
207 |
void NetworkSend_Packet(Packet *packet, NetworkClientState *cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
208 |
|
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
209 |
uint8 NetworkRecv_uint8(NetworkClientState *cs, Packet *packet); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
210 |
uint16 NetworkRecv_uint16(NetworkClientState *cs, Packet *packet); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
211 |
uint32 NetworkRecv_uint32(NetworkClientState *cs, Packet *packet); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
212 |
uint64 NetworkRecv_uint64(NetworkClientState *cs, Packet *packet); |
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
841
diff
changeset
|
213 |
void NetworkRecv_string(NetworkClientState *cs, Packet *packet, char* buffer, size_t size); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
214 |
Packet *NetworkRecv_Packet(NetworkClientState *cs, NetworkRecvStatus *status); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
215 |
|
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
216 |
bool NetworkSend_Packets(NetworkClientState *cs); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
217 |
void NetworkExecuteCommand(CommandPacket *cp); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
218 |
void NetworkAddCommandQueue(NetworkClientState *cs, CommandPacket *cp); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
219 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
220 |
// from network.c |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
221 |
void NetworkCloseClient(NetworkClientState *cs); |
722
f420fa9bd521
(svn r1174) -Fix: [Network] All strings can now be translated (no more hardcoded strings)
truelight
parents:
716
diff
changeset
|
222 |
void CDECL NetworkTextMessage(NetworkAction action, uint16 color, bool self_send, const char *name, const char *str, ...); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
223 |
void NetworkGetClientName(char *clientname, size_t size, const NetworkClientState *cs); |
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
224 |
uint NetworkCalculateLag(const NetworkClientState *cs); |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1026
diff
changeset
|
225 |
byte NetworkGetCurrentLanguageIndex(void); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
226 |
NetworkClientInfo *NetworkFindClientInfoFromIndex(uint16 client_index); |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
227 |
NetworkClientState *NetworkFindClientStateFromIndex(uint16 client_index); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
228 |
unsigned long NetworkResolveHost(const char *hostname); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
229 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
230 |
#endif /* ENABLE_NETWORK */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
231 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
232 |
#endif // NETWORK_DATA_H |