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) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | Copyright (C) 2001 Mark Wedel |
5 | * Copyright (C) 2001 Mark Wedel |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | |
7 | * |
8 | 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 |
9 | 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 |
10 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
11 | * (at your option) any later version. |
12 | |
12 | * |
13 | 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, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | |
17 | * |
18 | 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 |
19 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | |
21 | * |
22 | 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /** \file |
25 | /** \file |
26 | * Image related communication |
26 | * Image related communication |
27 | * |
27 | * |
28 | * \date 2003-12-02 |
28 | * \date 2003-12-02 |
… | |
… | |
33 | * things like all the structures as globals. |
33 | * things like all the structures as globals. |
34 | */ |
34 | */ |
35 | |
35 | |
36 | #include <global.h> |
36 | #include <global.h> |
37 | #include <sproto.h> |
37 | #include <sproto.h> |
|
|
38 | |
|
|
39 | #include "crc.h" |
38 | |
40 | |
39 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
41 | #define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ |
40 | |
42 | |
41 | /** Information about one image */ |
43 | /** Information about one image */ |
42 | typedef struct FaceInfo |
44 | typedef struct FaceInfo |
… | |
… | |
280 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
282 | LOG (llevError, "read_client_images: Image num %d not in 0..%d\n%s", num, nrofpixmaps, buf); |
281 | abort (); |
283 | abort (); |
282 | } |
284 | } |
283 | |
285 | |
284 | /* Skip accross the number data */ |
286 | /* Skip accross the number data */ |
285 | for (cp = buf + 6; *cp != ' '; cp++); |
287 | for (cp = buf + 6; *cp != ' '; cp++) |
|
|
288 | ; |
|
|
289 | |
286 | len = atoi (cp); |
290 | len = atoi (cp); |
287 | if (len == 0 || len > MAX_IMAGE_SIZE) |
291 | if (len == 0 || len > MAX_IMAGE_SIZE) |
288 | { |
292 | { |
289 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
293 | LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); |
290 | abort (); |
294 | abort (); |
… | |
… | |
299 | { |
303 | { |
300 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
304 | LOG (llevError, "read_client_images: Did not read desired amount of data, wanted %d, got %d\n%s", len, i, buf); |
301 | abort (); |
305 | abort (); |
302 | } |
306 | } |
303 | |
307 | |
304 | facesets[fileno].faces[num].checksum = 0; |
308 | crc32 chksum; |
|
|
309 | |
305 | for (i = 0; i < len; i++) |
310 | for (i = 0; i < len; i++) |
306 | { |
311 | chksum (facesets[fileno].faces[num].data[i]); |
307 | ROTATE_RIGHT (facesets[fileno].faces[num].checksum); |
312 | |
308 | facesets[fileno].faces[num].checksum += facesets[fileno].faces[num].data[i]; |
|
|
309 | facesets[fileno].faces[num].checksum &= 0xffffffff; |
313 | facesets[fileno].faces[num].checksum = chksum; |
310 | } |
|
|
311 | } |
314 | } |
312 | |
315 | |
313 | close_and_delete (infile, compressed); |
316 | close_and_delete (infile, compressed); |
314 | } /* For fileno < MAX_FACE_SETS */ |
317 | } /* For fileno < MAX_FACE_SETS */ |
315 | } |
318 | } |
… | |
… | |
414 | void |
417 | void |
415 | send_image_info (client *ns, char *params) |
418 | send_image_info (client *ns, char *params) |
416 | { |
419 | { |
417 | packet sl; |
420 | packet sl; |
418 | |
421 | |
419 | sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); |
422 | sl.printf ("replyinfo image_info\n%d\n%u\n", nrofpixmaps - 1, (unsigned int)bmaps_checksum); |
420 | |
423 | |
421 | for (int i = 0; i < MAX_FACE_SETS; i++) |
424 | for (int i = 0; i < MAX_FACE_SETS; i++) |
422 | if (facesets[i].prefix) |
425 | if (facesets[i].prefix) |
423 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
426 | sl.printf ("%d:%s:%s:%d:%s:%s:%s", i, |
424 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
427 | facesets[i].prefix, facesets[i].fullname , facesets[i].fallback, |
… | |
… | |
438 | */ |
441 | */ |
439 | void |
442 | void |
440 | send_image_sums (client *ns, char *params) |
443 | send_image_sums (client *ns, char *params) |
441 | { |
444 | { |
442 | int start, stop; |
445 | int start, stop; |
443 | char *cp, buf[MAX_BUF]; |
446 | char *cp; |
444 | |
447 | |
445 | packet sl; |
448 | packet sl; |
446 | |
449 | |
447 | start = atoi (params); |
450 | start = atoi (params); |
448 | for (cp = params; *cp != '\0'; cp++) |
451 | for (cp = params; *cp != '\0'; cp++) |
… | |
… | |
463 | for (int i = start; i <= stop; i++) |
466 | for (int i = start; i <= stop; i++) |
464 | { |
467 | { |
465 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
468 | ns->faces_sent[i] |= NS_FACESENT_FACE; |
466 | |
469 | |
467 | int qq = get_face_fallback (ns->faceset, i); |
470 | int qq = get_face_fallback (ns->faceset, i); |
|
|
471 | |
|
|
472 | if (sl.room () < 2 + 4 + 1 + new_faces[i].name.length () + 1) |
|
|
473 | break; |
468 | |
474 | |
469 | sl << uint16 (i) |
475 | sl << uint16 (i) |
470 | << uint32 (facesets[qq].faces[i].checksum) |
476 | << uint32 (facesets[qq].faces[i].checksum) |
471 | << uint8 (qq) |
477 | << uint8 (qq) |
472 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
478 | << data8 (&new_faces[i].name, new_faces[i].name.length () + 1); |
… | |
… | |
475 | /* It would make more sense to catch this pre-emptively in the code above. |
481 | /* It would make more sense to catch this pre-emptively in the code above. |
476 | * however, if this really happens, we probably just want to cut down the |
482 | * however, if this really happens, we probably just want to cut down the |
477 | * size to less than 1000, since that is what we claim the protocol would |
483 | * size to less than 1000, since that is what we claim the protocol would |
478 | * support. |
484 | * support. |
479 | */ |
485 | */ |
|
|
486 | //TODO: taken care of above, should simply abort or make sure the above code is correct |
480 | if (sl.length () >= MAXSOCKBUF) |
487 | if (sl.length () >= MAXSOCKBUF) |
481 | { |
488 | { |
482 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
489 | LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF); |
483 | abort (); |
490 | abort (); |
484 | } |
491 | } |