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.7 by root, Thu Dec 14 01:12:35 2006 UTC vs.
Revision 1.14 by root, Sat Dec 16 03:08:26 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 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);
320 314
321 if (mode == CF_FACE_NONE) 315 if (mode == CF_FACE_NONE)
322 ns->facecache = 1; 316 ns->facecache = 1;
323 else if (mode != CF_FACE_PNG) 317 else if (mode != CF_FACE_PNG)
324 {
325 SockList sl (MAXSOCKBUF);
326 sl.printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png"); 318 ns->send_packet_printf ("drawinfo %d %s", NDI_RED, "Warning - send unsupported face mode. Will use Png");
327 ns->send_packet (sl);
328 }
329 319
330 if (mask) 320 if (mask)
331 ns->facecache = 1; 321 ns->facecache = 1;
332} 322}
333 323
336 * This will be called often if the client is 326 * This will be called often if the client is
337 * caching images. 327 * caching images.
338 */ 328 */
339 329
340void 330void
341SendFaceCmd (char *buff, int len, NewSocket * ns) 331SendFaceCmd (char *buff, int len, client * ns)
342{ 332{
343 long tmpnum = atoi (buff); 333 long tmpnum = atoi (buff);
344 short facenum = tmpnum & 0xffff; 334 short facenum = tmpnum & 0xffff;
345 335
346 if (facenum != 0) 336 if (facenum != 0)
355 * face (and askface is the only place that should be setting it). Otherwise, 345 * face (and askface is the only place that should be setting it). Otherwise,
356 * we look at the facecache, and if set, send the image name. 346 * we look at the facecache, and if set, send the image name.
357 */ 347 */
358 348
359void 349void
360esrv_send_face (NewSocket *ns, short face_num, int nocache) 350esrv_send_face (client *ns, short face_num, int nocache)
361{ 351{
362 char fallback; 352 char fallback;
363 353
364 if (face_num <= 0 || face_num >= nrofpixmaps) 354 if (face_num <= 0 || face_num >= nrofpixmaps)
365 { 355 {
366 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num); 356 LOG (llevError, "esrv_send_face (%d) out of bounds??\n", face_num);
367 return; 357 return;
368 } 358 }
369 359
370 SockList sl (MAXSOCKBUF); 360 packet sl;
371 fallback = get_face_fallback (ns->faceset, face_num); 361 fallback = get_face_fallback (ns->faceset, face_num);
372 362
373 if (facesets[fallback].faces[face_num].data == NULL) 363 if (facesets[fallback].faces[face_num].data == NULL)
374 { 364 {
375 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num); 365 LOG (llevError, "esrv_send_face: faces[%d].data == NULL\n", face_num);
385 sl << uint8 (fallback); 375 sl << uint8 (fallback);
386 376
387 sl << uint32 (facesets[fallback].faces[face_num].checksum) 377 sl << uint32 (facesets[fallback].faces[face_num].checksum)
388 << new_faces[face_num].name; 378 << new_faces[face_num].name;
389 379
390 Send_With_Handling (ns, &sl); 380 ns->send_packet (sl);
391 } 381 }
392 else 382 else
393 { 383 {
394 sl << (ns->image2 ? "image2 " : "image ") 384 sl << (ns->image2 ? "image2 " : "image ")
395 << uint32 (face_num); 385 << uint32 (face_num);
398 sl << uint8 (fallback); 388 sl << uint8 (fallback);
399 389
400 sl << uint32 (facesets[fallback].faces[face_num].datalen) 390 sl << uint32 (facesets[fallback].faces[face_num].datalen)
401 << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen); 391 << data (facesets[fallback].faces[face_num].data, facesets[fallback].faces[face_num].datalen);
402 392
403 Send_With_Handling (ns, &sl); 393 ns->send_packet (sl);
404 } 394 }
405 395
406 ns->faces_sent[face_num] |= NS_FACESENT_FACE; 396 ns->faces_sent[face_num] |= NS_FACESENT_FACE;
407 sl.free ();
408} 397}
409 398
410/** 399/**
411 * Sends the number of images, checksum of the face file, 400 * Sends the number of images, checksum of the face file,
412 * and the image_info file information. See the doc/Developers/protocol 401 * and the image_info file information. See the doc/Developers/protocol
413 * if you want further detail. 402 * if you want further detail.
414 */ 403 */
415 404
416void 405void
417send_image_info (NewSocket * ns, char *params) 406send_image_info (client * ns, char *params)
418{ 407{
419 SockList sl (MAXSOCKBUF); 408 packet sl;
420 409
421 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum); 410 sl.printf ("replyinfo image_info\n%d\n%d\n", nrofpixmaps - 1, bmaps_checksum);
422 411
423 for (int i = 0; i < MAX_FACE_SETS; i++) 412 for (int i = 0; i < MAX_FACE_SETS; i++)
424 if (facesets[i].prefix) 413 if (facesets[i].prefix)
425 sl.printf ("%d:%s:%s:%d:%s:%s:%s", 414 sl.printf ("%d:%s:%s:%d:%s:%s:%s",
426 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback, 415 i, facesets[i].prefix, facesets[i].fullname, facesets[i].fallback,
427 facesets[i].size, facesets[i].extension, facesets[i].comment); 416 facesets[i].size, facesets[i].extension, facesets[i].comment);
428 417
429 Send_With_Handling (ns, &sl); 418 ns->send_packet (sl);
430 sl.free ();
431} 419}
432 420
433/** 421/**
434 * Sends requested face information. 422 * Sends requested face information.
435 * \param ns socket to send to 423 * \param ns socket to send to
438 * For each image in [start..stop] sends 426 * For each image in [start..stop] sends
439 * - checksum 427 * - checksum
440 * - name 428 * - name
441 */ 429 */
442void 430void
443send_image_sums (NewSocket * ns, char *params) 431send_image_sums (client * ns, char *params)
444{ 432{
445 int start, stop; 433 int start, stop;
446 char *cp, buf[MAX_BUF]; 434 char *cp, buf[MAX_BUF];
447 435
448 SockList sl (MAXSOCKBUF); 436 packet sl;
449 437
450 start = atoi (params); 438 start = atoi (params);
451 for (cp = params; *cp != '\0'; cp++) 439 for (cp = params; *cp != '\0'; cp++)
452 if (*cp == ' ') 440 if (*cp == ' ')
453 break; 441 break;
478 /* It would make more sense to catch this pre-emptively in the code above. 466 /* It would make more sense to catch this pre-emptively in the code above.
479 * however, if this really happens, we probably just want to cut down the 467 * however, if this really happens, we probably just want to cut down the
480 * size to less than 1000, since that is what we claim the protocol would 468 * size to less than 1000, since that is what we claim the protocol would
481 * support. 469 * support.
482 */ 470 */
483 if (sl.len >= MAXSOCKBUF) 471 if (sl.length () >= MAXSOCKBUF)
484 { 472 {
485 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.len, MAXSOCKBUF); 473 LOG (llevError, "send_image_send: buffer overrun, %d > %d\n", sl.length (), MAXSOCKBUF);
486 abort (); 474 abort ();
487 } 475 }
488 476
489 Send_With_Handling (ns, &sl); 477 ns->send_packet (sl);
490 sl.free ();
491} 478}
492 479

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines