ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/lowlevel.C
(Generate patch)

Comparing deliantra/server/socket/lowlevel.C (file contents):
Revision 1.12 by root, Thu Dec 14 00:01:37 2006 UTC vs.
Revision 1.14 by root, Thu Dec 14 01:21:58 2006 UTC

80#endif 80#endif
81} 81}
82 82
83/*********************************************************************** 83/***********************************************************************
84 * 84 *
85 * SockList functions/utilities 85 * packet functions/utilities
86 * 86 *
87 **********************************************************************/ 87 **********************************************************************/
88 88
89SockList &SockList::operator <<(const data &v) 89packet &packet::operator <<(const data &v)
90{ 90{
91 if (v.len) 91 if (v.len)
92 { 92 {
93 memcpy (buf + len, v.ptr, v.len); 93 memcpy (buf + len, v.ptr, v.len);
94 len += v.len; 94 len += v.len;
95 } 95 }
96 96
97 return *this; 97 return *this;
98} 98}
99 99
100SockList &SockList::operator <<(const data8 &v) 100packet &packet::operator <<(const data8 &v)
101{ 101{
102 unsigned int len = min (v.len, 0x00FF); 102 unsigned int len = min (v.len, 0x00FF);
103 return *this << uint8 (len) << data (v.ptr, len); 103 return *this << uint8 (len) << data (v.ptr, len);
104} 104}
105 105
106SockList &SockList::operator <<(const data16 &v) 106packet &packet::operator <<(const data16 &v)
107{ 107{
108 unsigned int len = min (v.len, 0xFFFF); 108 unsigned int len = min (v.len, 0xFFFF);
109 return *this << uint16 (len) << data (v.ptr, len); 109 return *this << uint16 (len) << data (v.ptr, len);
110} 110}
111 111
112SockList &SockList::operator <<(const char *v) 112packet &packet::operator <<(const char *v)
113{ 113{
114 return *this << data (v, strlen (v ? v : 0)); 114 return *this << data (v, strlen (v ? v : 0));
115} 115}
116 116
117void 117void
118SockList::printf (const char *format, ...) 118packet::printf (const char *format, ...)
119{ 119{
120 va_list ap; 120 va_list ap;
121 va_start (ap, format); 121 va_start (ap, format);
122 122
123 len += vsprintf ((char *)buf + len, format, ap); 123 len += vsnprintf ((char *)buf + len, MAXSOCKBUF, format, ap);
124 124
125 va_end (ap); 125 va_end (ap);
126} 126}
127 127
128/****************************************************************************** 128/******************************************************************************
360 cst_lst.obytes += amt; 360 cst_lst.obytes += amt;
361#endif 361#endif
362 } 362 }
363} 363}
364 364
365
366/** 365/**
367 * Takes a string of data, and writes it out to the socket. A very handy 366 * Takes a string of data, and writes it out to the socket. A very handy
368 * shortcut function. 367 * shortcut function.
369 */ 368 */
370void
371cs_write_string (NewSocket *ns, const char *buf, int len)
372{
373 SockList sl;
374 369
375 sl.len = len; 370void
376 sl.buf = (unsigned char *) buf; 371NewSocket::send_packet (packet &sl)
372{
377 Send_With_Handling (ns, &sl); 373 Send_With_Handling (this, &sl);
378} 374}
379 375
376void
377NewSocket::send_packet (const char *buf, int len)
378{
379 packet sl;
380
381 sl << data (buf, len);
382 send_packet (sl);
383}
384
385void
386NewSocket::send_packet (const char *buf)
387{
388 send_packet (buf, strlen (buf));
389}
380 390
381/** 391/**
382 * Calls Write_To_Socket to send data to the client. 392 * Calls Write_To_Socket to send data to the client.
383 * 393 *
384 * The only difference in this function is that we take a SockList 394 * The only difference in this function is that we take a packet
385 *, and we prepend the length information. 395 *, and we prepend the length information.
386 */ 396 */
387void 397void
388Send_With_Handling (NewSocket *ns, SockList *msg) 398Send_With_Handling (NewSocket *ns, packet *msg)
389{ 399{
390 unsigned char sbuf[4]; 400 unsigned char sbuf[4];
391 401
392 if (ns->status == Ns_Dead || !msg) 402 if (ns->status == Ns_Dead || !msg)
393 return; 403 return;
404 sbuf[1] = ((uint32) (msg->len)) & 0xFF; 414 sbuf[1] = ((uint32) (msg->len)) & 0xFF;
405 if (ns->status != Ns_Old) 415 if (ns->status != Ns_Old)
406 Write_To_Socket (ns, (char *) sbuf, 2); 416 Write_To_Socket (ns, (char *) sbuf, 2);
407 Write_To_Socket (ns, (char *) msg->buf, msg->len); 417 Write_To_Socket (ns, (char *) msg->buf, msg->len);
408} 418}
409
410/**
411 * Takes a string of data, and writes it out to the socket. A very handy
412 * shortcut function.
413 */
414void
415Write_String_To_Socket (NewSocket *ns, char *buf, int len)
416{
417 SockList sl;
418
419 sl.len = len;
420 sl.buf = (unsigned char *) buf;
421 Send_With_Handling (ns, &sl);
422}
423
424 419
425/****************************************************************************** 420/******************************************************************************
426 * 421 *
427 * statistics logging functions. 422 * statistics logging functions.
428 * 423 *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines