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.5 by root, Sun Oct 8 16:51:51 2006 UTC vs.
Revision 1.7 by root, Thu Dec 14 01:12:35 2006 UTC

312 * the caching attribute. 312 * the caching attribute.
313 * 313 *
314 */ 314 */
315 315
316void 316void
317SetFaceMode (char *buf, int len, NewSocket * ns) 317SetFaceMode (char *buf, int len, NewSocket *ns)
318{ 318{
319 char tmp[256];
320
321 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);
322 320
323 if (mode == CF_FACE_NONE) 321 if (mode == CF_FACE_NONE)
324 {
325 ns->facecache = 1; 322 ns->facecache = 1;
326 }
327 else if (mode != CF_FACE_PNG) 323 else if (mode != CF_FACE_PNG)
328 { 324 {
325 SockList sl (MAXSOCKBUF);
329 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");
330 Write_String_To_Socket (ns, tmp, strlen (tmp)); 327 ns->send_packet (sl);
331#ifdef ESRV_DEBUG
332 LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode);
333#endif
334 } 328 }
329
335 if (mask) 330 if (mask)
336 {
337 ns->facecache = 1; 331 ns->facecache = 1;
338 }
339} 332}
340 333
341/** 334/**
342 * Client has requested pixmap that it somehow missed getting. 335 * Client has requested pixmap that it somehow missed getting.
343 * This will be called often if the client is 336 * This will be called often if the client is
362 * 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,
363 * 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.
364 */ 357 */
365 358
366void 359void
367esrv_send_face (NewSocket * ns, short face_num, int nocache) 360esrv_send_face (NewSocket *ns, short face_num, int nocache)
368{ 361{
369 SockList sl;
370 char fallback; 362 char fallback;
371 363
372 if (face_num <= 0 || face_num >= nrofpixmaps) 364 if (face_num <= 0 || face_num >= nrofpixmaps)
373 { 365 {
374 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);
375 return; 367 return;
376 } 368 }
377 369
378 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 370 SockList sl (MAXSOCKBUF);
379 fallback = get_face_fallback (ns->faceset, face_num); 371 fallback = get_face_fallback (ns->faceset, face_num);
380 372
381 if (facesets[fallback].faces[face_num].data == NULL) 373 if (facesets[fallback].faces[face_num].data == NULL)
382 { 374 {
383 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);
384 return; 376 return;
385 } 377 }
386 378
387 if (ns->facecache && !nocache) 379 if (ns->facecache && !nocache)
388 { 380 {
381 sl << (ns->image2 ? "face2 " : "face1 ")
382 << uint16 (face_num);
383
389 if (ns->image2) 384 if (ns->image2)
390 strcpy ((char *) sl.buf, "face2 "); 385 sl << uint8 (fallback);
391 else if (ns->sc_version >= 1026) 386
392 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 }
393 else 392 else
394 strcpy ((char *) sl.buf, "face "); 393 {
394 sl << (ns->image2 ? "image2 " : "image ")
395 << uint32 (face_num);
395 396
396 sl.len = strlen ((const char *) sl.buf);
397 SockList_AddShort (&sl, face_num);
398 if (ns->image2) 397 if (ns->image2)
399 SockList_AddChar (&sl, fallback); 398 sl << uint8 (fallback);
400 if (ns->sc_version >= 1026) 399
401 SockList_AddInt (&sl, facesets[fallback].faces[face_num].checksum); 400 sl << uint32 (facesets[fallback].faces[face_num].datalen)
402 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);
403 sl.len += strlen (new_faces[face_num].name); 402
404 Send_With_Handling (ns, &sl); 403 Send_With_Handling (ns, &sl);
405 } 404 }
406 else 405
407 {
408 if (ns->image2)
409 strcpy ((char *) sl.buf, "image2 ");
410 else
411 strcpy ((char *) sl.buf, "image ");
412 sl.len = strlen ((char *) sl.buf);
413 SockList_AddInt (&sl, face_num);
414 if (ns->image2)
415 SockList_AddChar (&sl, fallback);
416 SockList_AddInt (&sl, facesets[fallback].faces[face_num].datalen);
417 memcpy (sl.buf + sl.len, facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
418 sl.len += facesets[fallback].faces[face_num].datalen;
419 Send_With_Handling (ns, &sl);
420 }
421 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 406 ns->faces_sent[face_num] |= NS_FACESENT_FACE;
422 free (sl.buf); 407 sl.free ();
423} 408}
424 409
425/** 410/**
426 * Sends the number of images, checksum of the face file, 411 * Sends the number of images, checksum of the face file,
427 * and the image_info file information. See the doc/Developers/protocol 412 * and the image_info file information. See the doc/Developers/protocol
429 */ 414 */
430 415
431void 416void
432send_image_info (NewSocket * ns, char *params) 417send_image_info (NewSocket * ns, char *params)
433{ 418{
434 SockList sl; 419 SockList sl (MAXSOCKBUF);
435 int i;
436 420
437 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
438
439 sprintf ((char *) sl.buf, "replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); 421 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum);
422
440 for (i = 0; i < MAX_FACE_SETS; i++) 423 for (int i = 0; i < MAX_FACE_SETS; i++)
441 {
442 if (facesets[i].prefix) 424 if (facesets[i].prefix)
443 { 425 sl.printf ("%d:%s:%s:%d:%s:%s:%s",
444 sprintf ((char *) sl.buf + strlen ((const char *) sl.buf), "%d:%s:%s:%d:%s:%s:%s",
445 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, 426 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback,
446 facesets[i].size, facesets[i].extension, facesets[i].comment); 427 facesets[i].size, facesets[i].extension, facesets[i].comment);
447 } 428
448 }
449 sl.len = strlen ((const char *) sl.buf);
450 Send_With_Handling (ns, &sl); 429 Send_With_Handling (ns, &sl);
451 free (sl.buf); 430 sl.free ();
452} 431}
453 432
454/** 433/**
455 * Sends requested face information. 434 * Sends requested face information.
456 * \param ns socket to send to 435 * \param ns socket to send to
462 */ 441 */
463void 442void
464send_image_sums (NewSocket * ns, char *params) 443send_image_sums (NewSocket * ns, char *params)
465{ 444{
466 int start, stop; 445 int start, stop;
467 short i;
468 char qq;
469 char *cp, buf[MAX_BUF]; 446 char *cp, buf[MAX_BUF];
470 SockList sl;
471 447
472 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 448 SockList sl (MAXSOCKBUF);
473 449
474 start = atoi (params); 450 start = atoi (params);
475 for (cp = params; *cp != '\0'; cp++) 451 for (cp = params; *cp != '\0'; cp++)
476 if (*cp == ' ') 452 if (*cp == ' ')
477 break; 453 break;
478 454
479 stop = atoi (cp); 455 stop = atoi (cp);
480 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) 456 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps)
481 { 457 {
482 sprintf (buf, "replyinfo image_sums %d %d", start, stop); 458 sl.printf ("replyinfo image_sums %d %d", start, stop);
483 cs_write_string (ns, buf, strlen (buf)); 459 ns->send_packet (sl);
460 sl.reset ();
484 return; 461 return;
485 } 462 }
463
486 sprintf ((char *) sl.buf, "replyinfo image_sums %d %d ", start, stop); 464 sl.printf ("replyinfo image_sums %d %d ", start, stop);
487 465
488 sl.len = strlen ((const char *) sl.buf);
489
490 for (i = start; i <= stop; i++) 466 for (int i = start; i <= stop; i++)
491 { 467 {
492 SockList_AddShort (&sl, i);
493 ns->faces_sent[i] |= NS_FACESENT_FACE; 468 ns->faces_sent[i] |= NS_FACESENT_FACE;
494 469
495 qq = get_face_fallback (ns->faceset, i); 470 int qq = get_face_fallback (ns->faceset, i);
471
472 sl << uint16 (i)
496 SockList_AddInt (&sl, facesets[qq].faces[i].checksum); 473 << uint32 (facesets[qq].faces[i].checksum)
497 SockList_AddChar (&sl, qq); 474 << uint8 (qq)
498 475 << data8 (&new_faces[i].name, new_faces[i].name.length () + 1);
499 qq = strlen (new_faces[i].name);
500 SockList_AddChar (&sl, (char) (qq + 1));
501 strcpy ((char *) sl.buf + sl.len, new_faces[i].name);
502 sl.len += qq;
503 SockList_AddChar (&sl, 0);
504 } 476 }
477
505 /* It would make more sense to catch this pre-emptively in the code above. 478 /* It would make more sense to catch this pre-emptively in the code above.
506 * however, if this really happens, we probably just want to cut down the 479 * however, if this really happens, we probably just want to cut down the
507 * size to less than 1000, since that is what we claim the protocol would 480 * size to less than 1000, since that is what we claim the protocol would
508 * support. 481 * support.
509 */ 482 */
510 if (sl.len >= MAXSOCKBUF) 483 if (sl.len >= MAXSOCKBUF)
511 { 484 {
512 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); 485 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF);
513 abort (); 486 abort ();
514 } 487 }
488
515 Send_With_Handling (ns, &sl); 489 Send_With_Handling (ns, &sl);
516 free (sl.buf); 490 sl.free ();
517} 491}
492

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines