--- deliantra/server/socket/lowlevel.C 2006/12/13 18:51:50 1.10 +++ deliantra/server/socket/lowlevel.C 2006/12/13 21:27:09 1.11 @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef __linux__ # include @@ -85,36 +86,43 @@ * **********************************************************************/ -SockList &SockList::operator <<(const data8 &v) +SockList &SockList::operator <<(const data &v) { - *this << uint8 (v.len); - - memcpy (buf + len, v.data, v.len); - len += v.len; + if (v.len) + { + memcpy (buf + len, v.ptr, v.len); + len += v.len; + } return *this; } -SockList &SockList::operator <<(const data16 &v) +SockList &SockList::operator <<(const data8 &v) { - *this << uint16 (v.len); - - memcpy (buf + len, v.data, v.len); - len += v.len; + unsigned int len = min (v.len, 0x00FF); + return *this << uint8 (len) << data (v.ptr, len); +} - return *this; +SockList &SockList::operator <<(const data16 &v) +{ + unsigned int len = min (v.len, 0xFFFF); + return *this << uint16 (len) << data (v.ptr, len); } SockList &SockList::operator <<(const char *v) { - if (v) - { - int l = strlen (v); - memcpy (buf + len, v, l); - len += l; - } + return *this << data (v, strlen (v ? v : 0)); +} - return *this; +void +SockList::printf (const char *format, ...) +{ + va_list ap; + va_start (ap, format); + + len += vsprintf ((char *)buf + len, format, ap); + + va_end (ap); } /* Basically does the reverse of SockList_AddInt, but on @@ -147,7 +155,7 @@ */ int -SockList_ReadPacket (int fd, SockList * sl, int len) +SockList_ReadPacket (int fd, SockList *sl, int len) { int stat, toread; @@ -422,7 +430,7 @@ * shortcut function. */ void -cs_write_string (NewSocket * ns, const char *buf, int len) +cs_write_string (NewSocket *ns, const char *buf, int len) { SockList sl; @@ -439,7 +447,7 @@ *, and we prepend the length information. */ void -Send_With_Handling (NewSocket * ns, SockList * msg) +Send_With_Handling (NewSocket *ns, SockList *msg) { unsigned char sbuf[4]; @@ -466,7 +474,7 @@ * shortcut function. */ void -Write_String_To_Socket (NewSocket * ns, char *buf, int len) +Write_String_To_Socket (NewSocket *ns, char *buf, int len) { SockList sl;