--- deliantra/server/socket/image.C 2006/12/14 01:21:58 1.8 +++ deliantra/server/socket/image.C 2007/02/15 18:09:34 1.19 @@ -1,25 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2001 Mark Wedel - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author can be reached via e-mail to -*/ + * CrossFire, A Multiplayer game + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2001 Mark Wedel + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The author can be reached via e-mail to + */ /** \file * Image related communication @@ -35,27 +36,19 @@ #include #include -#include -#include -#include - #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ /** Information about one image */ typedef struct FaceInfo { - uint8 *data; /**< image data */ - uint16 datalen; /**< length of the xpm data */ - uint32 checksum; /**< Checksum of face data */ } FaceInfo; /** Information about one face set */ typedef struct { - char *prefix; /**< */ char *fullname; @@ -96,6 +89,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); @@ -135,8 +129,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); } @@ -162,12 +158,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); } @@ -189,7 +187,6 @@ * it is just data it needs to allocate. As such, the code is written * to do such. */ - void read_client_images (void) { @@ -206,23 +203,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]); @@ -231,20 +228,23 @@ LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); abort (); } - facesets[len].prefix = strdup_local (cps[1]); - facesets[len].fullname = strdup_local (cps[2]); + facesets[len].prefix = strdup (cps[1]); + facesets[len].fullname = strdup (cps[2]); facesets[len].fallback = atoi (cps[3]); - facesets[len].size = strdup_local (cps[4]); - facesets[len].extension = strdup_local (cps[5]); - facesets[len].comment = strdup_local (cps[6]); + 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. */ @@ -254,6 +254,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); @@ -264,6 +265,7 @@ LOG (llevError, "Unable to open %s\n", filename); abort (); } + while (fgets (buf, HUGE_BUF - 1, infile) != NULL) { if (strncmp (buf, "IMAGE ", 6) != 0) @@ -271,12 +273,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); @@ -285,6 +289,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. */ @@ -295,14 +300,16 @@ 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++) { - ROTATE_RIGHT (facesets[fileno].faces[num].checksum); + rotate_right (facesets[fileno].faces[num].checksum); facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; facesets[fileno].faces[num].checksum &= 0xffffffff; } } + close_and_delete (infile, compressed); } /* For fileno < MAX_FACE_SETS */ } @@ -312,20 +319,15 @@ * the caching attribute. * */ - void -SetFaceMode (char *buf, int len, NewSocket *ns) +SetFaceMode (char *buf, int len, client *ns) { int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); if (mode == CF_FACE_NONE) ns->facecache = 1; else if (mode != CF_FACE_PNG) - { - packet sl; - sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); - ns->send_packet (sl); - } + ns->send_packet_printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); if (mask) ns->facecache = 1; @@ -336,12 +338,10 @@ * This will be called often if the client is * caching images. */ - void -SendFaceCmd (char *buff, int len, NewSocket * 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); @@ -355,9 +355,8 @@ * 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 (NewSocket *ns, short face_num, int nocache) +esrv_send_face (client *ns, short face_num, int nocache) { char fallback; @@ -387,7 +386,7 @@ sl << uint32 (facesets[fallback].faces[face_num].checksum) << new_faces[face_num].name; - Send_With_Handling (ns, &sl); + ns->send_packet (sl); } else { @@ -400,7 +399,7 @@ 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->send_packet (sl); } ns->faces_sent[face_num] |= NS_FACESENT_FACE; @@ -413,19 +412,19 @@ */ void -send_image_info (NewSocket * ns, char *params) +send_image_info (client *ns, char *params) { packet sl; - sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); + sl.printf ("replyinfo image_info\n%d\n%u\n", nrofpixmaps - 1, (unsigned int)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); + 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); - Send_With_Handling (ns, &sl); + ns->send_packet (sl); } /** @@ -438,7 +437,7 @@ * - name */ void -send_image_sums (NewSocket * ns, char *params) +send_image_sums (client *ns, char *params) { int start, stop; char *cp, buf[MAX_BUF]; @@ -478,12 +477,12 @@ * 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); + ns->send_packet (sl); }