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.6 by root, Wed Dec 13 21:27:09 2006 UTC vs.
Revision 1.13 by root, Fri Dec 15 19:59:20 2006 UTC

33 */ 33 */
34 34
35#include <global.h> 35#include <global.h>
36#include <sproto.h> 36#include <sproto.h>
37 37
38#include <newclient.h>
39#include <newserver.h>
40#include <loader.h>
41
42#define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */ 38#define MAX_FACE_SETS 20 /**< Maximum number of image sets the program will handle */
43 39
44/** Information about one image */ 40/** Information about one image */
45typedef struct FaceInfo 41typedef struct FaceInfo
46{ 42{
47 43
48 uint8 *data; /**< image data */ 44 uint8 *data; /**< image data */
49
50 uint16 datalen; /**< length of the xpm data */ 45 uint16 datalen; /**< length of the xpm data */
51
52 uint32 checksum; /**< Checksum of face data */ 46 uint32 checksum; /**< Checksum of face data */
53} FaceInfo; 47} FaceInfo;
54 48
55/** Information about one face set */ 49/** Information about one face set */
56typedef struct 50typedef struct
229 if (len >= MAX_FACE_SETS) 223 if (len >= MAX_FACE_SETS)
230 { 224 {
231 LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS); 225 LOG (llevError, "To high a setnum in image_info file: %d > %d\n", len, MAX_FACE_SETS);
232 abort (); 226 abort ();
233 } 227 }
234 facesets[len].prefix = strdup_local (cps[1]); 228 facesets[len].prefix = strdup (cps[1]);
235 facesets[len].fullname = strdup_local (cps[2]); 229 facesets[len].fullname = strdup (cps[2]);
236 facesets[len].fallback = atoi (cps[3]); 230 facesets[len].fallback = atoi (cps[3]);
237 facesets[len].size = strdup_local (cps[4]); 231 facesets[len].size = strdup (cps[4]);
238 facesets[len].extension = strdup_local (cps[5]); 232 facesets[len].extension = strdup (cps[5]);
239 facesets[len].comment = strdup_local (cps[6]); 233 facesets[len].comment = strdup (cps[6]);
240 } 234 }
241 } 235 }
242 close_and_delete (infile, compressed); 236 close_and_delete (infile, compressed);
243 for (i = 0; i < MAX_FACE_SETS; i++) 237 for (i = 0; i < MAX_FACE_SETS; i++)
244 { 238 {
312 * the caching attribute. 306 * the caching attribute.
313 * 307 *
314 */ 308 */
315 309
316void 310void
317SetFaceMode (char *buf, int len, NewSocket * ns) 311SetFaceMode (char *buf, int len, client *ns)
318{ 312{
319 char tmp[256];
320
321 int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE); 313 int mask = (atoi (buf) & CF_FACE_CACHE), mode = (atoi (buf) & ~CF_FACE_CACHE);
322 314
323 if (mode == CF_FACE_NONE) 315 if (mode == CF_FACE_NONE)
324 {
325 ns->facecache = 1; 316 ns->facecache = 1;
326 }
327 else if (mode != CF_FACE_PNG) 317 else if (mode != CF_FACE_PNG)
328 { 318 {
319 packet sl;
329 sprintf (tmp, "drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); 320 sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png");
330 Write_String_To_Socket (ns, tmp, strlen (tmp)); 321 ns->send_packet (sl);
331#ifdef ESRV_DEBUG
332 LOG (llevDebug, "SetFaceMode: Invalid mode from client: %d\n", mode);
333#endif
334 } 322 }
323
335 if (mask) 324 if (mask)
336 {
337 ns->facecache = 1; 325 ns->facecache = 1;
338 }
339} 326}
340 327
341/** 328/**
342 * Client has requested pixmap that it somehow missed getting. 329 * Client has requested pixmap that it somehow missed getting.
343 * This will be called often if the client is 330 * This will be called often if the client is
344 * caching images. 331 * caching images.
345 */ 332 */
346 333
347void 334void
348SendFaceCmd (char *buff, int len, NewSocket * ns) 335SendFaceCmd (char *buff, int len, client * ns)
349{ 336{
350 long tmpnum = atoi (buff); 337 long tmpnum = atoi (buff);
351 short facenum = tmpnum & 0xffff; 338 short facenum = tmpnum & 0xffff;
352 339
353 if (facenum != 0) 340 if (facenum != 0)
362 * face (and askface is the only place that should be setting it). Otherwise, 349 * 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. 350 * we look at the facecache, and if set, send the image name.
364 */ 351 */
365 352
366void 353void
367esrv_send_face (NewSocket *ns, short face_num, int nocache) 354esrv_send_face (client *ns, short face_num, int nocache)
368{ 355{
369 char fallback; 356 char fallback;
370 357
371 if (face_num <= 0 || face_num >= nrofpixmaps) 358 if (face_num <= 0 || face_num >= nrofpixmaps)
372 { 359 {
373 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 360 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num);
374 return; 361 return;
375 } 362 }
376 363
377 SockList sl (MAXSOCKBUF); 364 packet sl;
378 fallback = get_face_fallback (ns->faceset, face_num); 365 fallback = get_face_fallback (ns->faceset, face_num);
379 366
380 if (facesets[fallback].faces[face_num].data == NULL) 367 if (facesets[fallback].faces[face_num].data == NULL)
381 { 368 {
382 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); 369 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num);
392 sl << uint8 (fallback); 379 sl << uint8 (fallback);
393 380
394 sl << uint32 (facesets[fallback].faces[face_num].checksum) 381 sl << uint32 (facesets[fallback].faces[face_num].checksum)
395 << new_faces[face_num].name; 382 << new_faces[face_num].name;
396 383
397 Send_With_Handling (ns, &sl); 384 ns->send_packet (sl);
398 } 385 }
399 else 386 else
400 { 387 {
401 sl << (ns->image2 ? "image2 " : "image ") 388 sl << (ns->image2 ? "image2 " : "image ")
402 << uint32 (face_num); 389 << uint32 (face_num);
405 sl << uint8 (fallback); 392 sl << uint8 (fallback);
406 393
407 sl << uint32 (facesets[fallback].faces[face_num].datalen) 394 sl << uint32 (facesets[fallback].faces[face_num].datalen)
408 << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); 395 << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
409 396
410 Send_With_Handling (ns, &sl); 397 ns->send_packet (sl);
411 } 398 }
412 399
413 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 400 ns->faces_sent[face_num] |= NS_FACESENT_FACE;
414 sl.free ();
415} 401}
416 402
417/** 403/**
418 * Sends the number of images, checksum of the face file, 404 * Sends the number of images, checksum of the face file,
419 * and the image_info file information. See the doc/Developers/protocol 405 * and the image_info file information. See the doc/Developers/protocol
420 * if you want further detail. 406 * if you want further detail.
421 */ 407 */
422 408
423void 409void
424send_image_info (NewSocket * ns, char *params) 410send_image_info (client * ns, char *params)
425{ 411{
426 SockList sl (MAXSOCKBUF); 412 packet sl;
427 413
428 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); 414 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum);
429 415
430 for (int i = 0; i < MAX_FACE_SETS; i++) 416 for (int i = 0; i < MAX_FACE_SETS; i++)
431 if (facesets[i].prefix) 417 if (facesets[i].prefix)
432 sl.printf ("%d:%s:%s:%d:%s:%s:%s", 418 sl.printf ("%d:%s:%s:%d:%s:%s:%s",
433 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, 419 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback,
434 facesets[i].size, facesets[i].extension, facesets[i].comment); 420 facesets[i].size, facesets[i].extension, facesets[i].comment);
435 421
436 Send_With_Handling (ns, &sl); 422 ns->send_packet (sl);
437 sl.free ();
438} 423}
439 424
440/** 425/**
441 * Sends requested face information. 426 * Sends requested face information.
442 * \param ns socket to send to 427 * \param ns socket to send to
445 * For each image in [start..stop] sends 430 * For each image in [start..stop] sends
446 * - checksum 431 * - checksum
447 * - name 432 * - name
448 */ 433 */
449void 434void
450send_image_sums (NewSocket * ns, char *params) 435send_image_sums (client * ns, char *params)
451{ 436{
452 int start, stop; 437 int start, stop;
453 char *cp, buf[MAX_BUF]; 438 char *cp, buf[MAX_BUF];
454 439
455 SockList sl (MAXSOCKBUF); 440 packet sl;
456 441
457 start = atoi (params); 442 start = atoi (params);
458 for (cp = params; *cp != '\0'; cp++) 443 for (cp = params; *cp != '\0'; cp++)
459 if (*cp == ' ') 444 if (*cp == ' ')
460 break; 445 break;
461 446
462 stop = atoi (cp); 447 stop = atoi (cp);
463 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps) 448 if (stop < start || *cp == '\0' || (stop - start) > 1000 || stop >= nrofpixmaps)
464 { 449 {
465 sprintf (buf, "replyinfo image_sums %d %d", start, stop); 450 sl.printf ("replyinfo image_sums %d %d", start, stop);
466 cs_write_string (ns, buf, strlen (buf)); 451 ns->send_packet (sl);
452 sl.reset ();
467 return; 453 return;
468 } 454 }
469 455
470 sl.printf ("replyinfo image_sums %d %d ", start, stop); 456 sl.printf ("replyinfo image_sums %d %d ", start, stop);
471 457
484 /* It would make more sense to catch this pre-emptively in the code above. 470 /* It would make more sense to catch this pre-emptively in the code above.
485 * however, if this really happens, we probably just want to cut down the 471 * however, if this really happens, we probably just want to cut down the
486 * size to less than 1000, since that is what we claim the protocol would 472 * size to less than 1000, since that is what we claim the protocol would
487 * support. 473 * support.
488 */ 474 */
489 if (sl.len >= MAXSOCKBUF) 475 if (sl.length () >= MAXSOCKBUF)
490 { 476 {
491 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); 477 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF);
492 abort (); 478 abort ();
493 } 479 }
494 480
495 Send_With_Handling (ns, &sl); 481 ns->send_packet (sl);
496 sl.free ();
497} 482}
498 483

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines