1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001 Mark Wedel |
5 | * Copyright (C) 2001 Mark Wedel |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /** \file |
25 | /** \file |
25 | * Image related communication |
26 | * Image related communication |
26 | * |
27 | * |
27 | * \date 2003-12-02 |
28 | * \date 2003-12-02 |
… | |
… | |
38 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
39 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
39 | |
40 | |
40 | /** Information about one image */ |
41 | /** Information about one image */ |
41 | typedef struct FaceInfo |
42 | typedef struct FaceInfo |
42 | { |
43 | { |
43 | |
|
|
44 | uint8 *data; /**< image data */ |
44 | uint8 *data; /**< image data */ |
45 | uint16 datalen; /**< length of the xpm data */ |
45 | uint16 datalen; /**< length of the xpm data */ |
46 | uint32 checksum; /**< Checksum of face data */ |
46 | uint32 checksum; /**< Checksum of face data */ |
47 | } FaceInfo; |
47 | } FaceInfo; |
48 | |
48 | |
49 | /** Information about one face set */ |
49 | /** Information about one face set */ |
50 | typedef struct |
50 | typedef struct |
51 | { |
51 | { |
52 | |
|
|
53 | char *prefix; /**< */ |
52 | char *prefix; /**< */ |
54 | char *fullname; |
53 | char *fullname; |
55 | |
54 | |
56 | uint8 fallback; /**< faceset to use when an image is not found in this faceset */ |
55 | uint8 fallback; /**< faceset to use when an image is not found in this faceset */ |
57 | char *size; |
56 | char *size; |
… | |
… | |
88 | if (facesets[num].prefix) |
87 | if (facesets[num].prefix) |
89 | { |
88 | { |
90 | for (q = 0; q < nrofpixmaps; q++) |
89 | for (q = 0; q < nrofpixmaps; q++) |
91 | if (facesets[num].faces[q].data) |
90 | if (facesets[num].faces[q].data) |
92 | free (facesets[num].faces[q].data); |
91 | free (facesets[num].faces[q].data); |
|
|
92 | |
93 | free (facesets[num].prefix); |
93 | free (facesets[num].prefix); |
94 | free (facesets[num].fullname); |
94 | free (facesets[num].fullname); |
95 | free (facesets[num].size); |
95 | free (facesets[num].size); |
96 | free (facesets[num].extension); |
96 | free (facesets[num].extension); |
97 | free (facesets[num].comment); |
97 | free (facesets[num].comment); |
… | |
… | |
127 | if (!facesets[faceset].prefix) |
127 | if (!facesets[faceset].prefix) |
128 | { |
128 | { |
129 | LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); |
129 | LOG (llevError, "get_face_fallback called with unused set (%d)?\n", faceset); |
130 | return 0; /* use default set */ |
130 | return 0; /* use default set */ |
131 | } |
131 | } |
|
|
132 | |
132 | if (facesets[faceset].faces[imageno].data) |
133 | if (facesets[faceset].faces[imageno].data) |
133 | return faceset; |
134 | return faceset; |
|
|
135 | |
134 | return get_face_fallback (facesets[faceset].fallback, imageno); |
136 | return get_face_fallback (facesets[faceset].fallback, imageno); |
135 | } |
137 | } |
136 | |
138 | |
137 | /** |
139 | /** |
138 | * Checks fallback are correctly defined. |
140 | * Checks fallback are correctly defined. |
… | |
… | |
154 | if (!facesets[fallback].prefix) |
156 | if (!facesets[fallback].prefix) |
155 | { |
157 | { |
156 | LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); |
158 | LOG (llevError, "Face set %d falls to non set faceset %d\n", faceset, fallback); |
157 | abort (); |
159 | abort (); |
158 | } |
160 | } |
|
|
161 | |
159 | togo--; |
162 | togo--; |
160 | if (togo == 0) |
163 | if (togo == 0) |
161 | { |
164 | { |
162 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
165 | LOG (llevError, "Infinite loop found in facesets. aborting.\n"); |
163 | abort (); |
166 | abort (); |
164 | } |
167 | } |
|
|
168 | |
165 | check_faceset_fallback (fallback, togo); |
169 | check_faceset_fallback (fallback, togo); |
166 | } |
170 | } |
167 | |
171 | |
168 | #define MAX_IMAGE_SIZE 10000 |
172 | #define MAX_IMAGE_SIZE 10000 |
169 | |
173 | |
… | |
… | |
181 | * Function largely rewritten May 2000 to be more general purpose. |
185 | * Function largely rewritten May 2000 to be more general purpose. |
182 | * The server itself does not care what the image data is - to the server, |
186 | * The server itself does not care what the image data is - to the server, |
183 | * it is just data it needs to allocate. As such, the code is written |
187 | * it is just data it needs to allocate. As such, the code is written |
184 | * to do such. |
188 | * to do such. |
185 | */ |
189 | */ |
186 | |
|
|
187 | void |
190 | void |
188 | read_client_images (void) |
191 | read_client_images (void) |
189 | { |
192 | { |
190 | char filename[400]; |
193 | char filename[400]; |
191 | char buf[HUGE_BUF]; |
194 | char buf[HUGE_BUF]; |
… | |
… | |
198 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
201 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
199 | { |
202 | { |
200 | LOG (llevError, "Unable to open %s\n", filename); |
203 | LOG (llevError, "Unable to open %s\n", filename); |
201 | abort (); |
204 | abort (); |
202 | } |
205 | } |
|
|
206 | |
203 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
207 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
204 | { |
208 | { |
205 | badline = 0; |
209 | badline = 0; |
206 | |
210 | |
207 | if (buf[0] == '#') |
211 | if (buf[0] == '#') |
208 | continue; |
212 | continue; |
|
|
213 | |
209 | if (!(cps[0] = strtok (buf, ":"))) |
214 | if (!(cps[0] = strtok (buf, ":"))) |
210 | badline = 1; |
215 | badline = 1; |
|
|
216 | |
211 | for (i = 1; i < 7; i++) |
217 | for (i = 1; i < 7; i++) |
212 | { |
|
|
213 | if (!(cps[i] = strtok (NULL, ":"))) |
218 | if (!(cps[i] = strtok (NULL, ":"))) |
214 | badline = 1; |
219 | badline = 1; |
215 | } |
220 | |
216 | if (badline) |
221 | if (badline) |
217 | { |
|
|
218 | LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); |
222 | LOG (llevError, "Bad line in image_info file, ignoring line:\n %s", buf); |
219 | } |
|
|
220 | else |
223 | else |
221 | { |
224 | { |
222 | len = atoi (cps[0]); |
225 | len = atoi (cps[0]); |
223 | if (len >= MAX_FACE_SETS) |
226 | if (len >= MAX_FACE_SETS) |
224 | { |
227 | { |
… | |
… | |
231 | facesets[len].size = strdup (cps[4]); |
234 | facesets[len].size = strdup (cps[4]); |
232 | facesets[len].extension = strdup (cps[5]); |
235 | facesets[len].extension = strdup (cps[5]); |
233 | facesets[len].comment = strdup (cps[6]); |
236 | facesets[len].comment = strdup (cps[6]); |
234 | } |
237 | } |
235 | } |
238 | } |
|
|
239 | |
236 | close_and_delete (infile, compressed); |
240 | close_and_delete (infile, compressed); |
|
|
241 | |
237 | for (i = 0; i < MAX_FACE_SETS; i++) |
242 | for (i = 0; i < MAX_FACE_SETS; i++) |
238 | { |
243 | { |
239 | if (facesets[i].prefix) |
244 | if (facesets[i].prefix) |
240 | check_faceset_fallback (i, MAX_FACE_SETS); |
245 | check_faceset_fallback (i, MAX_FACE_SETS); |
241 | } |
246 | } |
|
|
247 | |
242 | /* Loaded the faceset information - now need to load up the |
248 | /* Loaded the faceset information - now need to load up the |
243 | * actual faces. |
249 | * actual faces. |
244 | */ |
250 | */ |
245 | |
251 | |
246 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
252 | for (fileno = 0; fileno < MAX_FACE_SETS; fileno++) |
247 | { |
253 | { |
248 | /* if prefix is not set, this is not used */ |
254 | /* if prefix is not set, this is not used */ |
249 | if (!facesets[fileno].prefix) |
255 | if (!facesets[fileno].prefix) |
250 | continue; |
256 | continue; |
|
|
257 | |
251 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
258 | facesets[fileno].faces = (FaceInfo *) calloc (nrofpixmaps, sizeof (FaceInfo)); |
252 | |
259 | |
253 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
260 | sprintf (filename, "%s/crossfire.%d", settings.datadir, fileno); |
254 | LOG (llevDebug, "Loading image file %s\n", filename); |
261 | LOG (llevDebug, "Loading image file %s\n", filename); |
255 | |
262 | |
256 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
263 | if ((infile = open_and_uncompress (filename, 0, &compressed)) == NULL) |
257 | { |
264 | { |
258 | LOG (llevError, "Unable to open %s\n", filename); |
265 | LOG (llevError, "Unable to open %s\n", filename); |
259 | abort (); |
266 | abort (); |
260 | } |
267 | } |
|
|
268 | |
261 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
269 | while (fgets (buf, HUGE_BUF - 1, infile) != NULL) |
262 | { |
270 | { |
263 | if (strncmp (buf, "IMAGE ", 6) != 0) |
271 | if (strncmp (buf, "IMAGE ", 6) != 0) |
264 | { |
272 | { |
265 | LOG (llevError, "read_client_images:Bad image line - not IMAGE, instead\n%s", buf); |
273 | LOG (llevError, "read_client_images:Bad image line - not IMAGE, instead\n%s", buf); |
266 | abort (); |
274 | abort (); |
267 | } |
275 | } |
|
|
276 | |
268 | num = atoi (buf + 6); |
277 | num = atoi (buf + 6); |
269 | if (num < 0 || num >= nrofpixmaps) |
278 | if (num < 0 || num >= nrofpixmaps) |
270 | { |
279 | { |
271 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
280 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
272 | abort (); |
281 | abort (); |
273 | } |
282 | } |
|
|
283 | |
274 | /* Skip accross the number data */ |
284 | /* Skip accross the number data */ |
275 | for (cp = buf + 6; *cp != ' '; cp++); |
285 | for (cp = buf + 6; *cp != ' '; cp++); |
276 | len = atoi (cp); |
286 | len = atoi (cp); |
277 | if (len == 0 || len > MAX_IMAGE_SIZE) |
287 | if (len == 0 || len > MAX_IMAGE_SIZE) |
278 | { |
288 | { |
279 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
289 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
280 | abort (); |
290 | abort (); |
281 | } |
291 | } |
|
|
292 | |
282 | /* We don't actualy care about the name of the image that |
293 | /* We don't actualy care about the name of the image that |
283 | * is embedded in the image file, so just ignore it. |
294 | * is embedded in the image file, so just ignore it. |
284 | */ |
295 | */ |
285 | facesets[fileno].faces[num].datalen = len; |
296 | facesets[fileno].faces[num].datalen = len; |
286 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
297 | facesets[fileno].faces[num].data = (uint8 *) malloc (len); |
287 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
298 | if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) |
288 | { |
299 | { |
289 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
300 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
290 | abort (); |
301 | abort (); |
291 | } |
302 | } |
|
|
303 | |
292 | facesets[fileno].faces[num].checksum = 0; |
304 | facesets[fileno].faces[num].checksum = 0; |
293 | for (i = 0; i < len; i++) |
305 | for (i = 0; i < len; i++) |
294 | { |
306 | { |
295 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
307 | rotate_right (facesets[fileno].faces[num].checksum); |
296 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
308 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
297 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
309 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
298 | } |
310 | } |
299 | } |
311 | } |
|
|
312 | |
300 | close_and_delete (infile, compressed); |
313 | close_and_delete (infile, compressed); |
301 | } /* For fileno < MAX_FACE_SETS */ |
314 | } /* For fileno < MAX_FACE_SETS */ |
302 | } |
315 | } |
303 | |
316 | |
304 | /** |
317 | /** |
305 | * Client tells us what type of faces it wants. Also sets |
318 | * Client tells us what type of faces it wants. Also sets |
306 | * the caching attribute. |
319 | * the caching attribute. |
307 | * |
320 | * |
308 | */ |
321 | */ |
309 | |
|
|
310 | void |
322 | void |
311 | SetFaceMode (char *buf, int len, client *ns) |
323 | SetFaceMode (char *buf, int len, client *ns) |
312 | { |
324 | { |
313 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
325 | int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); |
314 | |
326 | |
… | |
… | |
324 | /** |
336 | /** |
325 | * Client has requested pixmap that it somehow missed getting. |
337 | * Client has requested pixmap that it somehow missed getting. |
326 | * This will be called often if the client is |
338 | * This will be called often if the client is |
327 | * caching images. |
339 | * caching images. |
328 | */ |
340 | */ |
329 | |
|
|
330 | void |
341 | void |
331 | SendFaceCmd (char *buff, int len, client * ns) |
342 | SendFaceCmd (char *buf, int len, client *ns) |
332 | { |
343 | { |
333 | long tmpnum = atoi (buff); |
344 | uint16 facenum = atoi (buf); |
334 | short facenum = tmpnum & 0xffff; |
|
|
335 | |
345 | |
336 | if (facenum != 0) |
346 | if (facenum != 0) |
337 | esrv_send_face (ns, facenum, 1); |
347 | esrv_send_face (ns, facenum, 1); |
338 | } |
348 | } |
339 | |
349 | |
… | |
… | |
343 | * If nocache is true (nonzero), ignore the cache setting from the client - |
353 | * If nocache is true (nonzero), ignore the cache setting from the client - |
344 | * this is needed for the askface, in which we really do want to send the |
354 | * this is needed for the askface, in which we really do want to send the |
345 | * face (and askface is the only place that should be setting it). Otherwise, |
355 | * face (and askface is the only place that should be setting it). Otherwise, |
346 | * we look at the facecache, and if set, send the image name. |
356 | * we look at the facecache, and if set, send the image name. |
347 | */ |
357 | */ |
348 | |
|
|
349 | void |
358 | void |
350 | esrv_send_face (client *ns, short face_num, int nocache) |
359 | esrv_send_face (client *ns, short face_num, int nocache) |
351 | { |
360 | { |
352 | char fallback; |
361 | char fallback; |
353 | |
362 | |
… | |
… | |
401 | * and the image_info file information. See the doc/Developers/protocol |
410 | * and the image_info file information. See the doc/Developers/protocol |
402 | * if you want further detail. |
411 | * if you want further detail. |
403 | */ |
412 | */ |
404 | |
413 | |
405 | void |
414 | void |
406 | send_image_info (client * ns, char *params) |
415 | send_image_info (client *ns, char *params) |
407 | { |
416 | { |
408 | packet sl; |
417 | packet sl; |
409 | |
418 | |
410 | sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
419 | sl.printf ("replyinfo image_info\n%d\n%u\n", nrofpixmaps - 1, (unsigned int)bmaps_checksum); |
411 | |
420 | |
412 | for (int i = 0; i < MAX_FACE_SETS; i++) |
421 | for (int i = 0; i < MAX_FACE_SETS; i++) |
413 | if (facesets[i].prefix) |
422 | if (facesets[i].prefix) |
414 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", |
423 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
415 | i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, |
424 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
416 | facesets[i].size, facesets[i].extension, facesets[i].comment); |
425 | facesets[i].size , facesets[i].extension, facesets[i].comment); |
417 | |
426 | |
418 | ns->send_packet (sl); |
427 | ns->send_packet (sl); |
419 | } |
428 | } |
420 | |
429 | |
421 | /** |
430 | /** |
… | |
… | |
426 | * For each image in [start..stop] sends |
435 | * For each image in [start..stop] sends |
427 | * - checksum |
436 | * - checksum |
428 | * - name |
437 | * - name |
429 | */ |
438 | */ |
430 | void |
439 | void |
431 | send_image_sums (client * ns, char *params) |
440 | send_image_sums (client *ns, char *params) |
432 | { |
441 | { |
433 | int start, stop; |
442 | int start, stop; |
434 | char *cp, buf[MAX_BUF]; |
443 | char *cp, buf[MAX_BUF]; |
435 | |
444 | |
436 | packet sl; |
445 | packet sl; |