1 | /* |
|
|
2 | * static char *rcsid_newclient_h = |
|
|
3 | * "$Id: newclient.h,v 1.1 2006/02/03 07:12:49 root Exp $"; |
|
|
4 | */ |
|
|
5 | |
|
|
6 | /* |
1 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
8 | |
3 | |
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
10 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
47 | |
42 | |
48 | #ifndef NEWCLIENT_H |
43 | #ifndef NEWCLIENT_H |
49 | #define NEWCLIENT_H |
44 | #define NEWCLIENT_H |
50 | |
45 | |
51 | /* Maximum size of any packet we expect. Using this makes it so we don't need to |
46 | /* Maximum size of any packet we expect. Using this makes it so we don't need to |
52 | * allocated and deallocated teh same buffer over and over again and the price |
47 | * allocated and deallocated the same buffer over and over again and the price |
53 | * of using a bit of extra memory. IT also makes the code simpler. |
48 | * of using a bit of extra memory. It also makes the code simpler. |
|
|
49 | * |
|
|
50 | * The size must be the same in the server and the client (stupid), and its also NOT |
|
|
51 | * the maximum buffer size as one would expect, but the maximum buffer size + 1. |
54 | */ |
52 | */ |
55 | #define MAXSOCKBUF 10240 |
53 | #define MAXSOCKBUF 10240 |
56 | |
54 | |
57 | |
55 | |
58 | #define CS_QUERY_YESNO 0x1 /* Yes/no question */ |
56 | #define CS_QUERY_YESNO 0x1 /* Yes/no question */ |
… | |
… | |
174 | #define NDI_ORANGE 4 |
172 | #define NDI_ORANGE 4 |
175 | #define NDI_BLUE 5 /* Actually, it is Dodger Blue */ |
173 | #define NDI_BLUE 5 /* Actually, it is Dodger Blue */ |
176 | #define NDI_DK_ORANGE 6 /* DarkOrange2 */ |
174 | #define NDI_DK_ORANGE 6 /* DarkOrange2 */ |
177 | #define NDI_GREEN 7 /* SeaGreen */ |
175 | #define NDI_GREEN 7 /* SeaGreen */ |
178 | #define NDI_LT_GREEN 8 /* DarkSeaGreen, which is actually paler */ |
176 | #define NDI_LT_GREEN 8 /* DarkSeaGreen, which is actually paler */ |
179 | /* Than seagreen - also background color */ |
177 | /* Than seagreen - also background color */ |
180 | #define NDI_GREY 9 |
178 | #define NDI_GREY 9 |
181 | #define NDI_BROWN 10 /* Sienna */ |
179 | #define NDI_BROWN 10 /* Sienna */ |
182 | #define NDI_GOLD 11 |
180 | #define NDI_GOLD 11 |
183 | #define NDI_TAN 12 /* Khaki */ |
181 | #define NDI_TAN 12 /* Khaki */ |
184 | |
182 | |
185 | #define NDI_MAX_COLOR 12 /* Last value in */ |
183 | #define NDI_MAX_COLOR 12 /* Last value in */ |
186 | #define NDI_COLOR_MASK 0xff /* Gives lots of room for expansion - we are */ |
184 | #define NDI_COLOR_MASK 0xff /* Gives lots of room for expansion - we are */ |
187 | /* using an int anyways, so we have the space */ |
185 | /* using an int anyways, so we have the space */ |
188 | /* to still do all the flags */ |
186 | /* to still do all the flags */ |
189 | |
187 | |
190 | |
188 | |
191 | #define NDI_UNIQUE 0x100 /* Print this out immediately, don't buffer */ |
189 | #define NDI_UNIQUE 0x100 /* Print this out immediately, don't buffer */ |
192 | #define NDI_ALL 0x200 /* Inform all players of this message */ |
190 | #define NDI_ALL 0x200 /* Inform all players of this message */ |
193 | |
191 | |
… | |
… | |
213 | * are color informatin. For now, only high bit information we need |
211 | * are color informatin. For now, only high bit information we need |
214 | * is floor information. |
212 | * is floor information. |
215 | */ |
213 | */ |
216 | #define FACE_FLOOR 0x80 |
214 | #define FACE_FLOOR 0x80 |
217 | #define FACE_WALL 0x40 /* Or'd into the color value by the server |
215 | #define FACE_WALL 0x40 /* Or'd into the color value by the server |
218 | * right before sending. |
216 | * right before sending. |
219 | */ |
217 | */ |
220 | #define FACE_COLOR_MASK 0xf |
218 | #define FACE_COLOR_MASK 0xf |
221 | |
219 | |
222 | #define UPD_LOCATION 0x01 |
220 | #define UPD_LOCATION 0x01 |
223 | #define UPD_FLAGS 0x02 |
221 | #define UPD_FLAGS 0x02 |
224 | #define UPD_WEIGHT 0x04 |
222 | #define UPD_WEIGHT 0x04 |
… | |
… | |
234 | #define UPD_SP_DAMAGE 0x04 |
232 | #define UPD_SP_DAMAGE 0x04 |
235 | |
233 | |
236 | #define SOUND_NORMAL 0 |
234 | #define SOUND_NORMAL 0 |
237 | #define SOUND_SPELL 1 |
235 | #define SOUND_SPELL 1 |
238 | |
236 | |
|
|
237 | struct data |
|
|
238 | { |
|
|
239 | const void *ptr; |
|
|
240 | unsigned int len; |
|
|
241 | |
|
|
242 | data (const void *ptr, int len) : len (len), ptr (ptr) { } |
|
|
243 | data (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
|
|
244 | data (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } |
|
|
245 | }; |
|
|
246 | |
|
|
247 | struct data8 |
|
|
248 | { |
|
|
249 | const void *ptr; |
|
|
250 | unsigned int len; |
|
|
251 | |
|
|
252 | data8 (const void *ptr, int len) : len (len), ptr (ptr) { } |
|
|
253 | data8 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
|
|
254 | data8 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } |
|
|
255 | }; |
|
|
256 | |
|
|
257 | struct data16 |
|
|
258 | { |
|
|
259 | const void *ptr; |
|
|
260 | unsigned int len; |
|
|
261 | |
|
|
262 | data16 (const void *ptr, int len) : len (len), ptr (ptr) { } |
|
|
263 | data16 (const char *str) : len (strlen (str ? str : 0)), ptr ((void *)str) { } |
|
|
264 | data16 (const shstr &sh) : len (sh.length ()), ptr ((void *)&sh) { } |
|
|
265 | }; |
|
|
266 | |
239 | /* Contains the base information we use to make up a packet we want to send. */ |
267 | /* Contains the base information we use to make up a packet we want to send. */ |
240 | typedef struct SockList { |
268 | struct packet |
|
|
269 | { |
|
|
270 | packet () : buf ((uint8 *)malloc (MAXSOCKBUF)), len (0) { } |
|
|
271 | ~packet () { free (buf); } |
|
|
272 | |
|
|
273 | void reset () { len = 0; } |
|
|
274 | int length () const { return len; } |
|
|
275 | |
|
|
276 | packet &operator <<(uint8 v) { buf [len++] = v; return *this; } |
|
|
277 | |
|
|
278 | packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } |
|
|
279 | packet &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); } |
|
|
280 | packet &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); } |
|
|
281 | |
|
|
282 | packet &operator <<(sint8 v) { return *this << (uint8 )v; } |
|
|
283 | packet &operator <<(sint16 v) { return *this << (uint16)v; } |
|
|
284 | packet &operator <<(sint32 v) { return *this << (uint32)v; } |
|
|
285 | packet &operator <<(sint64 v) { return *this << (uint64)v; } |
|
|
286 | |
|
|
287 | packet &operator <<(const data &v); |
|
|
288 | packet &operator <<(const data8 &v); |
|
|
289 | packet &operator <<(const data16 &v); |
|
|
290 | |
|
|
291 | packet &operator <<(const char *v); |
|
|
292 | packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); } |
|
|
293 | |
|
|
294 | void printf (const char *format, ...); |
|
|
295 | |
|
|
296 | public: |
|
|
297 | uint8 *buf; |
241 | int len; |
298 | int len; |
242 | unsigned char *buf; |
299 | }; |
243 | } SockList; |
|
|
244 | |
300 | |
|
|
301 | inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; } |
|
|
302 | inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); } |
|
|
303 | inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); } |
|
|
304 | inline sint16 net_sint32 (uint8 *data) { return sint32 (net_uint32 (data)); } |
|
|
305 | |
245 | typedef struct CS_Stats { |
306 | struct CS_Stats |
|
|
307 | { |
246 | int ibytes; /* ibytes, obytes are bytes in, out */ |
308 | int ibytes; /* ibytes, obytes are bytes in, out */ |
247 | int obytes; |
309 | int obytes; |
248 | short max_conn; /* Maximum connections received */ |
310 | short max_conn; /* Maximum connections received */ |
249 | time_t time_start; /* When we started logging this */ |
311 | time_t time_start; /* When we started logging this */ |
250 | } CS_Stats; |
312 | }; |
251 | |
|
|
252 | |
313 | |
253 | extern CS_Stats cst_tot, cst_lst; |
314 | extern CS_Stats cst_tot, cst_lst; |
254 | |
315 | |
255 | #endif |
316 | #endif |
|
|
317 | |