--- deliantra/server/socket/image.C 2006/10/08 16:51:51 1.5 +++ deliantra/server/socket/image.C 2006/12/14 02:37:37 1.10 @@ -314,28 +314,21 @@ */ void -SetFaceMode (char *buf, int len, NewSocket * ns) +SetFaceMode (char *buf, int len, client_socket *ns) { - char tmp[256]; - int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); if (mode == CF_FACE_NONE) - { - ns->facecache = 1; - } + ns->facecache = 1; else if (mode != CF_FACE_PNG) { - sprintf (tmp, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); - Write_String_To_Socket (ns, tmp, strlen (tmp)); -#ifdef ESRV_DEBUG - LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode); -#endif + packet sl; + sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); + ns->send_packet (sl); } + if (mask) - { - ns->facecache = 1; - } + ns->facecache = 1; } /** @@ -345,7 +338,7 @@ */ void -SendFaceCmd (char *buff, int len, NewSocket * ns) +SendFaceCmd (char *buff, int len, client_socket * ns) { long tmpnum = atoi (buff); short facenum = tmpnum & 0xffff; @@ -364,9 +357,8 @@ */ void -esrv_send_face (NewSocket * ns, short face_num, int nocache) +esrv_send_face (client_socket *ns, short face_num, int nocache) { - SockList sl; char fallback; if (face_num <= 0 || face_num >= nrofpixmaps) @@ -375,7 +367,7 @@ return; } - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); + packet sl; fallback = get_face_fallback (ns->faceset, face_num); if (facesets[fallback].faces[face_num].data == NULL) @@ -386,40 +378,32 @@ if (ns->facecache && !nocache) { - if (ns->image2) - strcpy ((char *) sl.buf, "face2 "); - else if (ns->sc_version >= 1026) - strcpy ((char *) sl.buf, "face1 "); - else - strcpy ((char *) sl.buf, "face "); + sl << (ns->image2 ? "face2 " : "face1 ") + << uint16 (face_num); - sl.len = strlen ((const char *) sl.buf); - SockList_AddShort (&sl, face_num); if (ns->image2) - SockList_AddChar (&sl, fallback); - if (ns->sc_version >= 1026) - SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); - strcpy ((char *) sl.buf + sl.len, new_faces[face_num].name); - sl.len += strlen (new_faces[face_num].name); + sl << uint8 (fallback); + + sl << uint32 (facesets[fallback].faces[face_num].checksum) + << new_faces[face_num].name; + Send_With_Handling (ns, &sl); } else { + sl << (ns->image2 ? "image2 " : "image ") + << uint32 (face_num); + if (ns->image2) - strcpy ((char *) sl.buf, "image2 "); - else - strcpy ((char *) sl.buf, "image "); - sl.len = strlen ((char *) sl.buf); - SockList_AddInt (&sl, face_num); - if (ns->image2) - SockList_AddChar (&sl, fallback); - SockList_AddInt (&sl, facesets[fallback].faces[face_num].datalen); - memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); - sl.len += facesets[fallback].faces[face_num].datalen; + sl << uint8 (fallback); + + sl << uint32 (facesets[fallback].faces[face_num].datalen) + << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); + Send_With_Handling (ns, &sl); } + ns->faces_sent[face_num] |= NS_FACESENT_FACE; - free (sl.buf); } /** @@ -429,26 +413,19 @@ */ void -send_image_info (NewSocket * ns, char *params) +send_image_info (client_socket * ns, char *params) { - SockList sl; - int i; + packet sl; - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); + sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); + + for (int i = 0; i < MAX_FACE_SETS; i++) + if (facesets[i].prefix) + sl.printf ("%d:%s:%s:%d:%s:%s:%s", + i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, + facesets[i].size, facesets[i].extension, facesets[i].comment); - sprintf ((char *) sl.buf, "replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); - for (i = 0; i < MAX_FACE_SETS; i++) - { - if (facesets[i].prefix) - { - sprintf ((char *) sl.buf + strlen ((const char *) sl.buf), "%d:%s:%s:%d:%s:%s:%s", - i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, - facesets[i].size, facesets[i].extension, facesets[i].comment); - } - } - sl.len = strlen ((const char *) sl.buf); Send_With_Handling (ns, &sl); - free (sl.buf); } /** @@ -461,15 +438,12 @@ * - name */ void -send_image_sums (NewSocket * ns, char *params) +send_image_sums (client_socket * ns, char *params) { int start, stop; - short i; - char qq; char *cp, buf[MAX_BUF]; - SockList sl; - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); + packet sl; start = atoi (params); for (cp = params; *cp != '\0'; cp++) @@ -479,39 +453,37 @@ stop = atoi (cp); if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) { - sprintf (buf, "replyinfo image_sums %d %d", start, stop); - cs_write_string (ns, buf, strlen (buf)); + sl.printf ("replyinfo image_sums %d %d", start, stop); + ns->send_packet (sl); + sl.reset (); return; } - sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); - sl.len = strlen ((const char *) sl.buf); + sl.printf ("replyinfo image_sums %d %d ", start, stop); - for (i = start; i <= stop; i++) + for (int i = start; i <= stop; i++) { - SockList_AddShort (&sl, i); ns->faces_sent[i] |= NS_FACESENT_FACE; - qq = get_face_fallback (ns->faceset, i); - SockList_AddInt (&sl, facesets[qq].faces[i].checksum); - SockList_AddChar (&sl, qq); - - qq = strlen (new_faces[i].name); - SockList_AddChar (&sl, (char) (qq + 1)); - strcpy ((char *) sl.buf + sl.len, new_faces[i].name); - sl.len += qq; - SockList_AddChar (&sl, 0); + int qq = get_face_fallback (ns->faceset, i); + + sl << uint16 (i) + << uint32 (facesets[qq].faces[i].checksum) + << uint8 (qq) + << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); } + /* It would make more sense to catch this pre-emptively in the code above. * however, if this really happens, we probably just want to cut down the * size to less than 1000, since that is what we claim the protocol would * support. */ - if (sl.len >= MAXSOCKBUF) + if (sl.length () >= MAXSOCKBUF) { - LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); + LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); abort (); } + Send_With_Handling (ns, &sl); - free (sl.buf); } +