--- deliantra/server/socket/image.C 2006/12/16 03:08:26 1.14 +++ deliantra/server/socket/image.C 2006/12/16 22:14:42 1.15 @@ -40,7 +40,6 @@ /** Information about one image */ typedef struct FaceInfo { - uint8 *data; /**< image data */ uint16 datalen; /**< length of the xpm data */ uint32 checksum; /**< Checksum of face data */ @@ -49,7 +48,6 @@ /** Information about one face set */ typedef struct { - char *prefix; /**< */ char *fullname; @@ -90,6 +88,7 @@ for (q = 0; q < nrofpixmaps; q++) if (facesets[num].faces[q].data) free (facesets[num].faces[q].data); + free (facesets[num].prefix); free (facesets[num].fullname); free (facesets[num].size); @@ -129,8 +128,10 @@ LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); return 0; /* use default set */ } + if (facesets[faceset].faces[imageno].data) return faceset; + return get_face_fallback (facesets[faceset].fallback, imageno); } @@ -156,12 +157,14 @@ LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); abort (); } + togo--; if (togo == 0) { LOG (llevError, "Infinite loop found in facesets. aborting.\n"); abort (); } + check_faceset_fallback (fallback, togo); } @@ -183,7 +186,6 @@ * it is just data it needs to allocate. As such, the code is written * to do such. */ - void read_client_images (void) { @@ -200,23 +202,23 @@ LOG (llevError, "Unable to open %s\n", filename); abort (); } + while (fgets (buf, HUGE_BUF - 1, infile) != NULL) { badline = 0; if (buf[0] == '#') continue; + if (!(cps[0] = strtok (buf, ":"))) badline = 1; + for (i = 1; i < 7; i++) - { - if (!(cps[i] = strtok (NULL, ":"))) - badline = 1; - } + if (!(cps[i] = strtok (NULL, ":"))) + badline = 1; + if (badline) - { - LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); - } + LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); else { len = atoi (cps[0]); @@ -233,12 +235,15 @@ facesets[len].comment = strdup (cps[6]); } } + close_and_delete (infile, compressed); + for (i = 0; i < MAX_FACE_SETS; i++) { if (facesets[i].prefix) check_faceset_fallback (i, MAX_FACE_SETS); } + /* Loaded the faceset information - now need to load up the * actual faces. */ @@ -248,6 +253,7 @@ /* if prefix is not set, this is not used */ if (!facesets[fileno].prefix) continue; + facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); @@ -258,6 +264,7 @@ LOG (llevError, "Unable to open %s\n", filename); abort (); } + while (fgets (buf, HUGE_BUF - 1, infile) != NULL) { if (strncmp (buf, "IMAGE ", 6) != 0) @@ -265,12 +272,14 @@ LOG (llevError, "read_client_images:Bad image line - not IMAGE, instead\n%s", buf); abort (); } + num = atoi (buf + 6); if (num < 0 || num >= nrofpixmaps) { LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); abort (); } + /* Skip accross the number data */ for (cp = buf + 6; *cp != ' '; cp++); len = atoi (cp); @@ -279,6 +288,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 of the image that * is embedded in the image file, so just ignore it. */ @@ -289,6 +299,7 @@ LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); abort (); } + facesets[fileno].faces[num].checksum = 0; for (i = 0; i < len; i++) { @@ -297,6 +308,7 @@ facesets[fileno].faces[num].checksum &= 0xffffffff; } } + close_and_delete (infile, compressed); } /* For fileno < MAX_FACE_SETS */ } @@ -306,7 +318,6 @@ * the caching attribute. * */ - void SetFaceMode (char *buf, int len, client *ns) { @@ -326,12 +337,10 @@ * This will be called often if the client is * caching images. */ - void -SendFaceCmd (char *buff, int len, client * ns) +SendFaceCmd (char *buf, int len, client *ns) { - long tmpnum = atoi (buff); - short facenum = tmpnum & 0xffff; + uint16 facenum = atoi (buf); if (facenum != 0) esrv_send_face (ns, facenum, 1); @@ -345,7 +354,6 @@ * face (and askface is the only place that should be setting it). Otherwise, * we look at the facecache, and if set, send the image name. */ - void esrv_send_face (client *ns, short face_num, int nocache) { @@ -403,7 +411,7 @@ */ void -send_image_info (client * ns, char *params) +send_image_info (client *ns, char *params) { packet sl; @@ -411,9 +419,9 @@ 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); + 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); ns->send_packet (sl); } @@ -428,7 +436,7 @@ * - name */ void -send_image_sums (client * ns, char *params) +send_image_sums (client *ns, char *params) { int start, stop; char *cp, buf[MAX_BUF];