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

Comparing deliantra/server/socket/item.C (file contents):
Revision 1.28 by root, Wed Dec 20 09:14:22 2006 UTC vs.
Revision 1.31 by root, Mon Jan 8 18:18:36 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
3 3
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
6 7
7 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
8 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
337{ 338{
338 object *tmp, *last; 339 object *tmp, *last;
339 int got_one = 0, start_look = 0, end_look = 0; 340 int got_one = 0, start_look = 0, end_look = 0;
340 char buf[MAX_BUF]; 341 char buf[MAX_BUF];
341 342
342 if (!pl->contr->socket->update_look) 343 if (!pl->contr->ns->update_look)
343 { 344 {
344 LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); 345 LOG (llevDebug, "esrv_draw_look called when update_look was not set\n");
345 return; 346 return;
346 } 347 }
347 else 348 else
348 pl->contr->socket->update_look = 0; 349 pl->contr->ns->update_look = 0;
349 350
350 if (QUERY_FLAG (pl, FLAG_REMOVED) 351 if (QUERY_FLAG (pl, FLAG_REMOVED)
351 || !pl->map 352 || !pl->map
352 || pl->map->in_memory != MAP_IN_MEMORY 353 || pl->map->in_memory != MAP_IN_MEMORY
353 || out_of_map (pl->map, pl->x, pl->y)) 354 || out_of_map (pl->map, pl->x, pl->y))
354 return; 355 return;
355 356
356 for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) 357 for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above)
357 ; 358 ;
358 359
359 pl->contr->socket->send_packet ("delinv 0"); 360 pl->contr->ns->send_packet ("delinv 0");
360 361
361 packet sl; 362 packet sl;
362 sl.printf ("item%d ", pl->contr->socket->itemcmd); 363 sl.printf ("item%d ", pl->contr->ns->itemcmd);
363 364
364 sl << uint32 (0); 365 sl << uint32 (0);
365 366
366 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) 367 if (!(pl->contr->ns->faces_sent[empty_face->number] & NS_FACESENT_FACE))
367 esrv_send_face (pl->contr->socket, empty_face->number, 0); 368 esrv_send_face (pl->contr->ns, empty_face->number, 0);
368 369
369 if (pl->contr->socket->look_position) 370 if (pl->contr->ns->look_position)
370 { 371 {
371 char buf[80]; 372 char buf[80];
372 snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); 373 snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE);
373 374
374 sl << uint32 (0x80000000 | (pl->contr->socket->look_position - FLOORBOX_PAGESIZE)) 375 sl << uint32 (0x80000000 | (pl->contr->ns->look_position - FLOORBOX_PAGESIZE))
375 << uint32 (0) 376 << uint32 (0)
376 << sint32 (-1) 377 << sint32 (-1)
377 << uint32 (empty_face->number) 378 << uint32 (empty_face->number)
378 << data8 (buf) 379 << data8 (buf)
379 << uint16 (0) 380 << uint16 (0)
380 << uint8 (0) 381 << uint8 (0)
381 << uint32 (0); 382 << uint32 (0);
382 383
383 if (pl->contr->socket->itemcmd == 2) 384 if (pl->contr->ns->itemcmd == 2)
384 sl << uint16 (0); 385 sl << uint16 (0);
385 } 386 }
386 387
387 for (last = NULL; tmp != last; tmp = tmp->below) 388 for (last = NULL; tmp != last; tmp = tmp->below)
388 { 389 {
395 last = last->below; 396 last = last->below;
396 } 397 }
397 398
398 if (LOOK_OBJ (tmp)) 399 if (LOOK_OBJ (tmp))
399 { 400 {
400 if (++start_look < pl->contr->socket->look_position) 401 if (++start_look < pl->contr->ns->look_position)
401 continue; 402 continue;
402 403
403 end_look++; 404 end_look++;
404 405
405 if (end_look > FLOORBOX_PAGESIZE) 406 if (end_look > FLOORBOX_PAGESIZE)
406 { 407 {
407 /* What we basically do is make a 'fake' object - when the user applies it, 408 /* What we basically do is make a 'fake' object - when the user applies it,
408 * we notice the special tag the object has, and act accordingly. 409 * we notice the special tag the object has, and act accordingly.
409 */ 410 */
410 sl << uint32 (0x80000000 | (pl->contr->socket->look_position + FLOORBOX_PAGESIZE)) 411 sl << uint32 (0x80000000 | (pl->contr->ns->look_position + FLOORBOX_PAGESIZE))
411 << uint32 (0) 412 << uint32 (0)
412 << uint32 ((uint32) - 1) 413 << uint32 ((uint32) - 1)
413 << uint32 (empty_face->number) 414 << uint32 (empty_face->number)
414 << data8 ("Apply this to see next group of items") 415 << data8 ("Apply this to see next group of items")
415 << uint16 (0) 416 << uint16 (0)
416 << uint8 (0) 417 << uint8 (0)
417 << uint32 (0); 418 << uint32 (0);
418 419
419 if (pl->contr->socket->itemcmd == 2) 420 if (pl->contr->ns->itemcmd == 2)
420 sl << uint16 (0); 421 sl << uint16 (0);
421 422
422 break; 423 break;
423 } 424 }
424 425
425 if (tmp->head) 426 if (tmp->head)
426 head = tmp->head; 427 head = tmp->head;
427 else 428 else
428 head = tmp; 429 head = tmp;
429 430
430 add_object_to_socklist (*pl->contr->socket, sl, head); 431 add_object_to_socklist (*pl->contr->ns, sl, head);
431 got_one++; 432 got_one++;
432 433
433 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) 434 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN))
434 { 435 {
435 pl->contr->socket->send_packet (sl); 436 pl->contr->ns->send_packet (sl);
436 437
437 sl.reset (); 438 sl.reset ();
438 sl.printf ("item%d ", pl->contr->socket->itemcmd); 439 sl.printf ("item%d ", pl->contr->ns->itemcmd);
439 sl << uint32 (0); 440 sl << uint32 (0);
440 got_one = 0; 441 got_one = 0;
441 } 442 }
442 } 443 }
443 } 444 }
444 445
445 if (got_one) 446 if (got_one)
446 pl->contr->socket->send_packet (sl); 447 pl->contr->ns->send_packet (sl);
447 448
448} 449}
449 450
450/** 451/**
451 * Sends whole inventory. 452 * Sends whole inventory.
455{ 456{
456 object *tmp; 457 object *tmp;
457 int got_one = 0; 458 int got_one = 0;
458 459
459 460
460 pl->contr->socket->send_packet_printf ("delinv %d", op->count); 461 pl->contr->ns->send_packet_printf ("delinv %d", op->count);
461 462
462 packet sl; 463 packet sl;
463 sl.printf ("item%d ", pl->contr->socket->itemcmd); 464 sl.printf ("item%d ", pl->contr->ns->itemcmd);
464 465
465 sl << uint32 (op->count); 466 sl << uint32 (op->count);
466 467
467 for (tmp = op->inv; tmp; tmp = tmp->below) 468 for (tmp = op->inv; tmp; tmp = tmp->below)
468 { 469 {
473 else 474 else
474 head = tmp; 475 head = tmp;
475 476
476 if (LOOK_OBJ (head)) 477 if (LOOK_OBJ (head))
477 { 478 {
478 add_object_to_socklist (*pl->contr->socket, sl, head); 479 add_object_to_socklist (*pl->contr->ns, sl, head);
479 480
480 got_one++; 481 got_one++;
481 482
482 /* IT is possible for players to accumulate a huge amount of 483 /* IT is possible for players to accumulate a huge amount of
483 * items (especially with some of the bags out there) to 484 * items (especially with some of the bags out there) to
484 * overflow the buffer. IF so, send multiple item commands. 485 * overflow the buffer. IF so, send multiple item commands.
485 */ 486 */
486 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) 487 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN))
487 { 488 {
488 pl->contr->socket->send_packet (sl); 489 pl->contr->ns->send_packet (sl);
489 490
490 sl.reset (); 491 sl.reset ();
491 sl.printf ("item%d ", pl->contr->socket->itemcmd); 492 sl.printf ("item%d ", pl->contr->ns->itemcmd);
492 sl << uint32 (op->count); 493 sl << uint32 (op->count);
493 got_one = 0; 494 got_one = 0;
494 } 495 }
495 } /* If LOOK_OBJ() */ 496 } /* If LOOK_OBJ() */
496 } 497 }
497 498
498 if (got_one) 499 if (got_one)
499 pl->contr->socket->send_packet (sl); 500 pl->contr->ns->send_packet (sl);
500} 501}
501 502
502/** 503/**
503 * Updates object *op for player *pl. 504 * Updates object *op for player *pl.
504 * 505 *
519 * is hopefully in the same place, so the client should preserve 520 * is hopefully in the same place, so the client should preserve
520 * order. 521 * order.
521 */ 522 */
522 } 523 }
523 524
525 client *ns = pl->contr->ns;
526 if (!ns)
527 return;
528
524 if (!QUERY_FLAG (op, FLAG_CLIENT_SENT)) 529 if (!QUERY_FLAG (op, FLAG_CLIENT_SENT))
525 { 530 {
526 /* FLAG_CLIENT_SENT is debug only. We are using it to see where 531 /* FLAG_CLIENT_SENT is debug only. We are using it to see where
527 * this is happening - we can set a breakpoint here in the debugger 532 * this is happening - we can set a breakpoint here in the debugger
528 * and track back the call. 533 * and track back the call.
550 sint32 weight = WEIGHT (op); 555 sint32 weight = WEIGHT (op);
551 556
552 sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); 557 sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight);
553 558
554 if (pl == op) 559 if (pl == op)
555 op->contr->last_weight = weight; 560 ns->last_weight = weight;
556 } 561 }
557 562
558 if (flags & UPD_FACE) 563 if (flags & UPD_FACE)
559 { 564 {
560 if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE)) 565 if (!(ns->faces_sent[op->face->number] & NS_FACESENT_FACE))
561 esrv_send_face (pl->contr->socket, op->face->number, 0); 566 esrv_send_face (ns, op->face->number, 0);
562 567
563 sl << uint32 (op->face->number); 568 sl << uint32 (op->face->number);
564 } 569 }
565 570
566 if (flags & UPD_NAME) 571 if (flags & UPD_NAME)
620 } 625 }
621 626
622 if (flags & UPD_NROF) 627 if (flags & UPD_NROF)
623 sl << uint32 (op->nrof); 628 sl << uint32 (op->nrof);
624 629
625 pl->contr->socket->send_packet (sl); 630 pl->contr->ns->send_packet (sl);
626} 631}
627 632
628/** 633/**
629 * Sends item's info to player. 634 * Sends item's info to player.
630 */ 635 */
640 /* if the item is on the ground, mark that the look needs to 645 /* if the item is on the ground, mark that the look needs to
641 * be updated. 646 * be updated.
642 */ 647 */
643 if (!op->env) 648 if (!op->env)
644 { 649 {
645 pl->contr->socket->floorbox_update (); 650 pl->contr->ns->floorbox_update ();
646 return; 651 return;
647 } 652 }
648 } 653 }
649 654
650 packet sl; 655 packet sl;
651 656
652 sl.printf ("item%d ", pl->contr->socket->itemcmd); 657 sl.printf ("item%d ", pl->contr->ns->itemcmd);
653 658
654 if (op->head) 659 if (op->head)
655 op = op->head; 660 op = op->head;
656 661
657 sl << uint32 (op->env ? op->env->count : 0); 662 sl << uint32 (op->env ? op->env->count : 0);
658 663
659 add_object_to_socklist (*pl->contr->socket, sl, op); 664 add_object_to_socklist (*pl->contr->ns, sl, op);
660 665
661 pl->contr->socket->send_packet (sl); 666 pl->contr->ns->send_packet (sl);
662 SET_FLAG (op, FLAG_CLIENT_SENT); 667 SET_FLAG (op, FLAG_CLIENT_SENT);
663} 668}
664 669
665/** 670/**
666 * Tells the client to delete an item. Uses the item 671 * Tells the client to delete an item. Uses the item
672{ 677{
673 packet sl ("delitem"); 678 packet sl ("delitem");
674 679
675 sl << uint32 (tag); 680 sl << uint32 (tag);
676 681
677 pl->socket->send_packet (sl); 682 pl->ns->send_packet (sl);
678} 683}
679 684
680 685
681/******************************************************************************* 686/*******************************************************************************
682 * 687 *
753 return; 758 return;
754 759
755 /* If the high bit is set, player applied a pseudo object. */ 760 /* If the high bit is set, player applied a pseudo object. */
756 if (tag & 0x80000000) 761 if (tag & 0x80000000)
757 { 762 {
758 pl->socket->look_position = tag & 0x7fffffff; 763 pl->ns->look_position = tag & 0x7fffffff;
759 pl->socket->floorbox_update (); 764 pl->ns->floorbox_update ();
760 return; 765 return;
761 } 766 }
762 767
763 object *op = esrv_get_ob_from_count (pl->ob, tag); 768 object *op = esrv_get_ob_from_count (pl->ob, tag);
764 769
889 { 894 {
890 return; 895 return;
891 } 896 }
892 dy = atoi (cp); 897 dy = atoi (cp);
893 898
894 if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2) 899 if (FABS (dx) > pl->ns->mapx / 2 || FABS (dy) > pl->ns->mapy / 2)
895 return; 900 return;
896 901
897 if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]) 902 if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2])
898 return; 903 return;
899 904
900 look_at (pl->ob, dx, dy); 905 look_at (pl->ob, dx, dy);
901} 906}
902 907

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines