--- deliantra/server/socket/image.C 2007/03/10 19:48:17 1.23 +++ deliantra/server/socket/image.C 2007/03/11 02:12:45 1.24 @@ -88,7 +88,7 @@ { if (facesets[num].prefix) { - for (q = 0; q < nrofpixmaps; q++) + for (q = 0; q < faces.size (); q++) if (facesets[num].faces[q].data) free (facesets[num].faces[q].data); @@ -174,150 +174,6 @@ #define MAX_IMAGE_SIZE 10000 /** - * Loads all the image types into memory. - * - * This way, we can easily send them to the client. We should really do something - * better than abort on any errors - on the other hand, these are all fatal - * to the server (can't work around them), but the abort just seems a bit - * messy (exit would probably be better.) - * - * Couple of notes: We assume that the faces are in a continous block. - * This works fine for now, but this could perhaps change in the future - * - * Function largely rewritten May 2000 to be more general purpose. - * The server itself does not care what the image data is - to the server, - * it is just data it needs to allocate. As such, the code is written - * to do such. - */ -void -read_client_images (void) -{ - char filename[400]; - char buf[HUGE_BUF]; - char *cp, *cps[7]; - FILE *infile; - int num, len, compressed, fileno, i, badline; - - memset (facesets, 0, sizeof (facesets)); - sprintf (filename, "%s/image_info", settings.datadir); - if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) - { - 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 (badline) - LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); - else - { - len = atoi (cps[0]); - if (len >= MAX_FACE_SETS) - { - LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); - abort (); - } - facesets[len].prefix = strdup (cps[1]); - facesets[len].fullname = strdup (cps[2]); - facesets[len].fallback = atoi (cps[3]); - facesets[len].size = strdup (cps[4]); - facesets[len].extension = strdup (cps[5]); - 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. - */ - - for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) - { - /* 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); - LOG (llevDebug, "Loading image file %s\n", filename); - - if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) - { - LOG (llevError, "Unable to open %s\n", filename); - abort (); - } - - while (fgets (buf, HUGE_BUF - 1, infile) != NULL) - { - if (strncmp (buf, "IMAGE ", 6) != 0) - { - 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); - if (len == 0 || len > MAX_IMAGE_SIZE) - { - 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. - */ - facesets[fileno].faces[num].datalen = len; - facesets[fileno].faces[num].data = (uint8 *) malloc (len); - if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) - { - LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); - abort (); - } - - crc32 chksum; - - for (i = 0; i < len; i++) - chksum (facesets[fileno].faces[num].data[i]); - - facesets[fileno].faces[num].checksum = chksum; - } - - close_and_delete (infile, compressed); - } /* For fileno < MAX_FACE_SETS */ -} - -/** * Client tells us what type of faces it wants. Also sets * the caching attribute. * @@ -350,6 +206,17 @@ esrv_send_face (ns, facenum, 1); } +// how lame +static void print_facename (packet &sl, const facedata &d) +{ + sl.printf ("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + d.chksum [ 0], d.chksum [ 1], d.chksum [ 2], d.chksum [ 3], + d.chksum [ 4], d.chksum [ 5], d.chksum [ 6], d.chksum [ 7], + d.chksum [ 8], d.chksum [ 9], d.chksum [10], d.chksum [11], + d.chksum [12], d.chksum [13], d.chksum [14], d.chksum [15]); +} + /** * Sends a face to a client if they are in pixmap mode * nothing gets sent in bitmap mode. @@ -361,22 +228,15 @@ void esrv_send_face (client *ns, short face_num, int nocache) { - char fallback; - - if (face_num <= 0 || face_num >= nrofpixmaps) + if (face_num <= 0 || face_num >= faces.size ()) { LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); return; } - packet sl; - fallback = get_face_fallback (ns->faceset, face_num); + const facedata *d = face_data (face_num, ns->faceset); - if (facesets[fallback].faces[face_num].data == NULL) - { - LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); - return; - } + packet sl; if (ns->facecache && !nocache) { @@ -384,10 +244,12 @@ << uint16 (face_num); if (ns->image2) - sl << uint8 (fallback); + sl << uint8 (0); + + sl << uint32 (0); - sl << uint32 (facesets[fallback].faces[face_num].checksum) - << new_faces[face_num].name; + // how lame + print_facename (sl, *d); ns->send_packet (sl); } @@ -397,10 +259,10 @@ << uint32 (face_num); if (ns->image2) - sl << uint8 (fallback); + sl << uint8 (0); - sl << uint32 (facesets[fallback].faces[face_num].datalen) - << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); + sl << uint32 (d->data.size ()) + << data (d->data.data (), d->data.size ()); ns->send_packet (sl); } @@ -419,13 +281,10 @@ { packet sl; - sl.printf ("replyinfo image_info\n%d\n%u\n", nrofpixmaps - 1, (unsigned int)bmaps_checksum); + //TODO: second parameter is a checksum, but it makes no sense in this current framework + sl.printf ("replyinfo image_info\n%d\n%u\n", MAX_FACES, 0); - 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 << "0:base:standard:0:32x32:none:The old 32x32 faceset.\n"; ns->send_packet (sl); } @@ -453,7 +312,7 @@ break; stop = atoi (cp); - if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) + if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= MAX_FACES) { sl.printf ("replyinfo image_sums %d %d", start, stop); ns->send_packet (sl); @@ -463,19 +322,20 @@ sl.printf ("replyinfo image_sums %d %d ", start, stop); - for (int i = start; i <= stop; i++) + for (int i = start; i <= stop && i < faces.size (); i++) { ns->faces_sent[i] |= NS_FACESENT_FACE; - int qq = get_face_fallback (ns->faceset, i); + const facedata *d = face_data (i, ns->faceset); - if (sl.room () < 2 + 4 + 1 + new_faces[i].name.length () + 1) + if (sl.room () < 2 + 4 + 1 + d->data.size () + 1) break; sl << uint16 (i) - << uint32 (facesets[qq].faces[i].checksum) - << uint8 (qq) - << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); + << uint32 (0) // checksum + << uint8 (ns->faceset); + + print_facename (sl, *d); sl << uint8 (0); } /* It would make more sense to catch this pre-emptively in the code above.