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.17 by pippijn, Thu Dec 14 14:13:02 2006 UTC vs.
Revision 1.18 by root, Thu Dec 14 20:39:54 2006 UTC

266 266
267/* 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. */
268struct packet 268struct packet
269{ 269{
270 enum { bufsize = MAXSOCKBUF }; 270 enum { bufsize = MAXSOCKBUF };
271 enum { hdrlen = 2 }; // keep this many bytes free at the front
271 272
272 // strategy: only check on variable-length adds 273 // strategy: only check on variable-length adds
273 // and allow 256 bytes for any headers. 274 // and allow 256 bytes for any headers.
274 uint8 *cur; 275 uint8 *cur;
275 uint8 buf [bufsize + 256]; 276 uint8 buf_ [hdrlen + bufsize + 256];
276 277
277 packet () { reset (); } 278 packet () { reset (); }
278 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
279 void reset (int offset = 0) { cur = buf + offset; } 286 void reset (int offset = 0) { cur = buf () + offset; }
280 int length () const { return cur - buf; } 287 int length () const { return cur - buf (); }
281 int room () { return bufsize - (cur - buf); } 288 int room () { return bufsize - (cur - buf ()); }
282 289
283 // unchecked 290 // unchecked
284 packet &operator <<(uint8 v) { *cur++ = v; return *this; } 291 packet &operator <<(uint8 v) { *cur++ = v; return *this; }
285 292
286 packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); } 293 packet &operator <<(uint16 v) { return *this << uint8 (v >> 8) << uint8 (v); }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines