--- deliantra/server/socket/lowlevel.C 2006/12/14 00:01:37 1.12 +++ deliantra/server/socket/lowlevel.C 2006/12/14 01:21:58 1.14 @@ -82,11 +82,11 @@ /*********************************************************************** * - * SockList functions/utilities + * packet functions/utilities * **********************************************************************/ -SockList &SockList::operator <<(const data &v) +packet &packet::operator <<(const data &v) { if (v.len) { @@ -97,30 +97,30 @@ return *this; } -SockList &SockList::operator <<(const data8 &v) +packet &packet::operator <<(const data8 &v) { unsigned int len = min (v.len, 0x00FF); return *this << uint8 (len) << data (v.ptr, len); } -SockList &SockList::operator <<(const data16 &v) +packet &packet::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) +packet &packet::operator <<(const char *v) { return *this << data (v, strlen (v ? v : 0)); } void -SockList::printf (const char *format, ...) +packet::printf (const char *format, ...) { va_list ap; va_start (ap, format); - len += vsprintf ((char *)buf + len, format, ap); + len += vsnprintf ((char *)buf + len, MAXSOCKBUF, format, ap); va_end (ap); } @@ -362,30 +362,40 @@ } } - /** * Takes a string of data, and writes it out to the socket. A very handy * shortcut function. */ + +void +NewSocket::send_packet (packet &sl) +{ + Send_With_Handling (this, &sl); +} + void -cs_write_string (NewSocket *ns, const char *buf, int len) +NewSocket::send_packet (const char *buf, int len) { - SockList sl; + packet sl; - sl.len = len; - sl.buf = (unsigned char *) buf; - Send_With_Handling (ns, &sl); + sl << data (buf, len); + send_packet (sl); } +void +NewSocket::send_packet (const char *buf) +{ + send_packet (buf, strlen (buf)); +} /** * Calls Write_To_Socket to send data to the client. * - * The only difference in this function is that we take a SockList + * The only difference in this function is that we take a packet *, and we prepend the length information. */ void -Send_With_Handling (NewSocket *ns, SockList *msg) +Send_With_Handling (NewSocket *ns, packet *msg) { unsigned char sbuf[4]; @@ -407,21 +417,6 @@ Write_To_Socket (ns, (char *) msg->buf, msg->len); } -/** - * Takes a string of data, and writes it out to the socket. A very handy - * shortcut function. - */ -void -Write_String_To_Socket (NewSocket *ns, char *buf, int len) -{ - SockList sl; - - sl.len = len; - sl.buf = (unsigned char *) buf; - Send_With_Handling (ns, &sl); -} - - /****************************************************************************** * * statistics logging functions.