ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/newclient.h
(Generate patch)

Comparing deliantra/server/include/newclient.h (file contents):
Revision 1.1.1.1 by root, Fri Feb 3 07:12:49 2006 UTC vs.
Revision 1.19 by root, Fri Dec 15 19:59:19 2006 UTC

1/*
2 * static char *rcsid_newclient_h =
3 * "$Id: newclient.h,v 1.1.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
237struct data
238{
239 unsigned int len;
240 const void *ptr;
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
247struct data8
248{
249 unsigned int len;
250 const void *ptr;
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
257struct data16
258{
259 unsigned int len;
260 const void *ptr;
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. */
240typedef struct SockList { 268struct packet
241 int len; 269{
242 unsigned char *buf; 270 enum { bufsize = MAXSOCKBUF };
243} SockList; 271 enum { hdrlen = 2 }; // keep this many bytes free at the front
244 272
273 // strategy: only check on variable-length adds
274 // and allow 256 bytes for any headers.
275 uint8 *cur;
276 uint8 buf_ [hdrlen + bufsize + 256];
277
278 packet () { reset (); }
279
280 uint8 operator [](unsigned int i) const { return buf_ [i + hdrlen]; }
281 uint8 &operator [](unsigned int i) { return buf_ [i + hdrlen]; }
282
283 uint8 *buf () { return buf_ + hdrlen; }
284 const uint8 *buf () const { return buf_ + hdrlen; }
285
286 void reset (int offset = 0) { cur = buf () + offset; }
287 int length () const { return cur - buf (); }
288 int room () { return bufsize - (cur - buf ()); }
289
290 // unchecked
291 packet &operator <<(uint8 v) { *cur++ = v; return *this; }
292
293 packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); }
294 packet &operator <<(uint32 v) { return *this << uint16 (v >> 16) << uint16 (v); }
295 packet &operator <<(uint64 v) { return *this << uint32 (v >> 32) << uint32 (v); }
296
297 packet &operator <<(sint8 v) { return *this << (uint8 )v; }
298 packet &operator <<(sint16 v) { return *this << (uint16)v; }
299 packet &operator <<(sint32 v) { return *this << (uint32)v; }
300 packet &operator <<(sint64 v) { return *this << (uint64)v; }
301
302 // checked
303 packet &operator <<(const data &v);
304 packet &operator <<(const data8 &v);
305 packet &operator <<(const data16 &v);
306
307 packet &operator <<(const char *v);
308 packet &operator <<(const shstr &sh) { return *this << data (&sh, sh.length ()); }
309
310 void printf (const char *format, ...);
311};
312
313inline uint16 net_uint16 (uint8 *data) { return (data [0] << 8) | data [1]; }
314inline uint32 net_uint32 (uint8 *data) { return (net_uint16 (data) << 16) | net_uint16 (data + 2); }
315inline sint16 net_sint16 (uint8 *data) { return sint16 (net_uint16 (data)); }
316inline sint16 net_sint32 (uint8 *data) { return sint32 (net_uint32 (data)); }
317
245typedef struct CS_Stats { 318struct CS_Stats
319{
246 int ibytes; /* ibytes, obytes are bytes in, out */ 320 int ibytes; /* ibytes, obytes are bytes in, out */
247 int obytes; 321 int obytes;
248 short max_conn; /* Maximum connections received */ 322 short max_conn; /* Maximum connections received */
249 time_t time_start; /* When we started logging this */ 323 time_t time_start; /* When we started logging this */
250} CS_Stats; 324};
251
252 325
253extern CS_Stats cst_tot, cst_lst; 326extern CS_Stats cst_tot, cst_lst;
254 327
255#endif 328#endif
329

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines