--- deliantra/server/socket/image.C 2006/09/14 22:34:05 1.4 +++ deliantra/server/socket/image.C 2006/12/14 01:12:35 1.7 @@ -285,7 +285,7 @@ LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); abort (); } - /* We don't actualy care about the name if the image that + /* We don't actualy care about the name of the image that * is embedded in the image file, so just ignore it. */ facesets[fileno].faces[num].datalen = len; @@ -314,28 +314,21 @@ */ void -SetFaceMode (char *buf, int len, NewSocket * ns) +SetFaceMode (char *buf, int len, NewSocket *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 + SockList sl (MAXSOCKBUF); + 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; } /** @@ -364,9 +357,8 @@ */ void -esrv_send_face (NewSocket * ns, short face_num, int nocache) +esrv_send_face (NewSocket *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); + SockList sl (MAXSOCKBUF); fallback = get_face_fallback (ns->faceset, face_num); if (facesets[fallback].faces[face_num].data == NULL) @@ -386,40 +378,33 @@ 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); + sl.free (); } /** @@ -431,24 +416,18 @@ void send_image_info (NewSocket * ns, char *params) { - SockList sl; - int i; + SockList sl (MAXSOCKBUF); - 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); + sl.free (); } /** @@ -464,12 +443,9 @@ send_image_sums (NewSocket * ns, char *params) { int start, stop; - short i; - char qq; char *cp, buf[MAX_BUF]; - SockList sl; - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); + SockList sl (MAXSOCKBUF); start = atoi (params); for (cp = params; *cp != '\0'; cp++) @@ -479,29 +455,26 @@ 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 @@ -512,6 +485,8 @@ LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); abort (); } + Send_With_Handling (ns, &sl); - free (sl.buf); + sl.free (); } +