ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/image.C
(Generate patch)

Comparing deliantra/server/socket/image.C (file contents):
Revision 1.3 by root, Sun Sep 10 13:43:33 2006 UTC vs.
Revision 1.8 by root, Thu Dec 14 01:21:58 2006 UTC

1
2/*
3 * static char *rcsid_init_c =
4 * "$Id: image.C,v 1.3 2006/09/10 13:43:33 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2001 Mark Wedel 4 Copyright (C) 2001 Mark Wedel
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The author can be reached via e-mail to crossfire-devel@real-time.com 21 The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 22*/
29 23
30/** \file 24/** \file
31 * Image related communication 25 * Image related communication
32 * 26 *
289 if (len == 0 || len > MAX_IMAGE_SIZE) 283 if (len == 0 || len > MAX_IMAGE_SIZE)
290 { 284 {
291 LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf); 285 LOG (llevError, "read_client_images: length not valid: %d > %d \n%s", len, MAX_IMAGE_SIZE, buf);
292 abort (); 286 abort ();
293 } 287 }
294 /* We don't actualy care about the name if the image that 288 /* We don't actualy care about the name of the image that
295 * is embedded in the image file, so just ignore it. 289 * is embedded in the image file, so just ignore it.
296 */ 290 */
297 facesets[fileno].faces[num].datalen = len; 291 facesets[fileno].faces[num].datalen = len;
298 facesets[fileno].faces[num].data = (uint8 *) malloc (len); 292 facesets[fileno].faces[num].data = (uint8 *) malloc (len);
299 if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1) 293 if ((i = fread (facesets[fileno].faces[num].data, len, 1, infile)) != 1)
318 * the caching attribute. 312 * the caching attribute.
319 * 313 *
320 */ 314 */
321 315
322void 316void
323SetFaceMode (char *buf, int len, NewSocket * ns) 317SetFaceMode (char *buf, int len, NewSocket *ns)
324{ 318{
325 char tmp[256];
326
327 int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); 319 int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE);
328 320
329 if (mode == CF_FACE_NONE) 321 if (mode == CF_FACE_NONE)
330 {
331 ns->facecache = 1; 322 ns->facecache = 1;
332 }
333 else if (mode != CF_FACE_PNG) 323 else if (mode != CF_FACE_PNG)
334 { 324 {
325 packet sl;
335 sprintf (tmp, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); 326 sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png");
336 Write_String_To_Socket (ns, tmp, strlen (tmp)); 327 ns->send_packet (sl);
337#ifdef ESRV_DEBUG
338 LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode);
339#endif
340 } 328 }
329
341 if (mask) 330 if (mask)
342 {
343 ns->facecache = 1; 331 ns->facecache = 1;
344 }
345} 332}
346 333
347/** 334/**
348 * Client has requested pixmap that it somehow missed getting. 335 * Client has requested pixmap that it somehow missed getting.
349 * This will be called often if the client is 336 * This will be called often if the client is
368 * 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,
369 * 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.
370 */ 357 */
371 358
372void 359void
373esrv_send_face (NewSocket * ns, short face_num, int nocache) 360esrv_send_face (NewSocket *ns, short face_num, int nocache)
374{ 361{
375 SockList sl;
376 char fallback; 362 char fallback;
377 363
378 if (face_num <= 0 || face_num >= nrofpixmaps) 364 if (face_num <= 0 || face_num >= nrofpixmaps)
379 { 365 {
380 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 366 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num);
381 return; 367 return;
382 } 368 }
383 369
384 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 370 packet sl;
385 fallback = get_face_fallback (ns->faceset, face_num); 371 fallback = get_face_fallback (ns->faceset, face_num);
386 372
387 if (facesets[fallback].faces[face_num].data == NULL) 373 if (facesets[fallback].faces[face_num].data == NULL)
388 { 374 {
389 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); 375 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num);
390 return; 376 return;
391 } 377 }
392 378
393 if (ns->facecache && !nocache) 379 if (ns->facecache && !nocache)
394 { 380 {
381 sl << (ns->image2 ? "face2 " : "face1 ")
382 << uint16 (face_num);
383
395 if (ns->image2) 384 if (ns->image2)
396 strcpy ((char *) sl.buf, "face2 "); 385 sl << uint8 (fallback);
397 else if (ns->sc_version >= 1026) 386
398 strcpy ((char *) sl.buf, "face1 "); 387 sl << uint32 (facesets[fallback].faces[face_num].checksum)
388 << new_faces[face_num].name;
389
390 Send_With_Handling (ns, &sl);
391 }
399 else 392 else
400 strcpy ((char *) sl.buf, "face "); 393 {
394 sl << (ns->image2 ? "image2 " : "image ")
395 << uint32 (face_num);
401 396
402 sl.len = strlen ((const char *) sl.buf);
403 SockList_AddShort (&sl, face_num);
404 if (ns->image2) 397 if (ns->image2)
405 SockList_AddChar (&sl, fallback); 398 sl << uint8 (fallback);
406 if (ns->sc_version >= 1026) 399
407 SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); 400 sl << uint32 (facesets[fallback].faces[face_num].datalen)
408 strcpy ((char *) sl.buf + sl.len, new_faces[face_num].name); 401 << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
409 sl.len += strlen (new_faces[face_num].name); 402
410 Send_With_Handling (ns, &sl); 403 Send_With_Handling (ns, &sl);
411 } 404 }
412 else 405
413 {
414 if (ns->image2)
415 strcpy ((char *) sl.buf, "image2 ");
416 else
417 strcpy ((char *) sl.buf, "image ");
418 sl.len = strlen ((char *) sl.buf);
419 SockList_AddInt (&sl, face_num);
420 if (ns->image2)
421 SockList_AddChar (&sl, fallback);
422 SockList_AddInt (&sl, facesets[fallback].faces[face_num].datalen);
423 memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
424 sl.len += facesets[fallback].faces[face_num].datalen;
425 Send_With_Handling (ns, &sl);
426 }
427 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 406 ns->faces_sent[face_num] |= NS_FACESENT_FACE;
428 free (sl.buf);
429} 407}
430 408
431/** 409/**
432 * Sends the number of images, checksum of the face file, 410 * Sends the number of images, checksum of the face file,
433 * and the image_info file information. See the doc/Developers/protocol 411 * and the image_info file information. See the doc/Developers/protocol
435 */ 413 */
436 414
437void 415void
438send_image_info (NewSocket * ns, char *params) 416send_image_info (NewSocket * ns, char *params)
439{ 417{
440 SockList sl; 418 packet sl;
441 int i;
442 419
443 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
444
445 sprintf ((char *) sl.buf, "replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); 420 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum);
421
446 for (i = 0; i < MAX_FACE_SETS; i++) 422 for (int i = 0; i < MAX_FACE_SETS; i++)
447 {
448 if (facesets[i].prefix) 423 if (facesets[i].prefix)
449 { 424 sl.printf ("%d:%s:%s:%d:%s:%s:%s",
450 sprintf ((char *) sl.buf + strlen ((const char *) sl.buf), "%d:%s:%s:%d:%s:%s:%s",
451 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, 425 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback,
452 facesets[i].size, facesets[i].extension, facesets[i].comment); 426 facesets[i].size, facesets[i].extension, facesets[i].comment);
453 } 427
454 }
455 sl.len = strlen ((const char *) sl.buf);
456 Send_With_Handling (ns, &sl); 428 Send_With_Handling (ns, &sl);
457 free (sl.buf);
458} 429}
459 430
460/** 431/**
461 * Sends requested face information. 432 * Sends requested face information.
462 * \param ns socket to send to 433 * \param ns socket to send to
468 */ 439 */
469void 440void
470send_image_sums (NewSocket * ns, char *params) 441send_image_sums (NewSocket * ns, char *params)
471{ 442{
472 int start, stop; 443 int start, stop;
473 short i;
474 char qq;
475 char *cp, buf[MAX_BUF]; 444 char *cp, buf[MAX_BUF];
476 SockList sl;
477 445
478 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 446 packet sl;
479 447
480 start = atoi (params); 448 start = atoi (params);
481 for (cp = params; *cp != '\0'; cp++) 449 for (cp = params; *cp != '\0'; cp++)
482 if (*cp == ' ') 450 if (*cp == ' ')
483 break; 451 break;
484 452
485 stop = atoi (cp); 453 stop = atoi (cp);
486 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) 454 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps)
487 { 455 {
488 sprintf (buf, "replyinfo image_sums %d %d", start, stop); 456 sl.printf ("replyinfo image_sums %d %d", start, stop);
489 cs_write_string (ns, buf, strlen (buf)); 457 ns->send_packet (sl);
458 sl.reset ();
490 return; 459 return;
491 } 460 }
461
492 sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); 462 sl.printf ("replyinfo image_sums %d %d ", start, stop);
493 463
494 sl.len = strlen ((const char *) sl.buf);
495
496 for (i = start; i <= stop; i++) 464 for (int i = start; i <= stop; i++)
497 { 465 {
498 SockList_AddShort (&sl, i);
499 ns->faces_sent[i] |= NS_FACESENT_FACE; 466 ns->faces_sent[i] |= NS_FACESENT_FACE;
500 467
501 qq = get_face_fallback (ns->faceset, i); 468 int qq = get_face_fallback (ns->faceset, i);
469
470 sl << uint16 (i)
502 SockList_AddInt (&sl, facesets[qq].faces[i].checksum); 471 << uint32 (facesets[qq].faces[i].checksum)
503 SockList_AddChar (&sl, qq); 472 << uint8 (qq)
504 473 << data8 (&new_faces[i].name, new_faces[i].name.length () + 1);
505 qq = strlen (new_faces[i].name);
506 SockList_AddChar (&sl, (char) (qq + 1));
507 strcpy ((char *) sl.buf + sl.len, new_faces[i].name);
508 sl.len += qq;
509 SockList_AddChar (&sl, 0);
510 } 474 }
475
511 /* It would make more sense to catch this pre-emptively in the code above. 476 /* It would make more sense to catch this pre-emptively in the code above.
512 * however, if this really happens, we probably just want to cut down the 477 * however, if this really happens, we probably just want to cut down the
513 * size to less than 1000, since that is what we claim the protocol would 478 * size to less than 1000, since that is what we claim the protocol would
514 * support. 479 * support.
515 */ 480 */
516 if (sl.len >= MAXSOCKBUF) 481 if (sl.len >= MAXSOCKBUF)
517 { 482 {
518 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); 483 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF);
519 abort (); 484 abort ();
520 } 485 }
486
521 Send_With_Handling (ns, &sl); 487 Send_With_Handling (ns, &sl);
522 free (sl.buf);
523} 488}
489

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines