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.81 by root, Tue Oct 20 07:18:11 2009 UTC vs.
Revision 1.98 by root, Sat Dec 31 06:18:02 2011 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
48 48
49/** 49/**
50 * This is a similar to query_name, but returns flags 50 * This is a similar to query_name, but returns flags
51 * to be sent to client. 51 * to be sent to client.
52 */ 52 */
53unsigned int 53static unsigned int
54query_flags (object *op) 54query_flags (object *op)
55{ 55{
56 unsigned int flags = 0; 56 unsigned int flags = 0;
57 57
58 if (QUERY_FLAG (op, FLAG_APPLIED)) 58 if (op->flag [FLAG_APPLIED])
59 switch (op->type) 59 switch (op->type)
60 { 60 {
61 case BOW: 61 case BOW:
62 case WAND: 62 case WAND:
63 case ROD: 63 case ROD:
89 } 89 }
90 90
91 if (op->is_open_container ()) 91 if (op->is_open_container ())
92 flags |= F_OPEN; 92 flags |= F_OPEN;
93 93
94 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) 94 if (op->flag [FLAG_KNOWN_CURSED])
95 { 95 {
96 if (QUERY_FLAG (op, FLAG_DAMNED)) 96 if (op->flag [FLAG_DAMNED])
97 flags |= F_DAMNED; 97 flags |= F_DAMNED;
98 else if (QUERY_FLAG (op, FLAG_CURSED)) 98 else if (op->flag [FLAG_CURSED])
99 flags |= F_CURSED; 99 flags |= F_CURSED;
100 } 100 }
101 101
102 if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) 102 if (op->flag [FLAG_KNOWN_MAGICAL] && !op->flag [FLAG_IDENTIFIED])
103 flags |= F_MAGIC; 103 flags |= F_MAGIC;
104 if (QUERY_FLAG (op, FLAG_UNPAID)) 104 if (op->flag [FLAG_UNPAID])
105 flags |= F_UNPAID; 105 flags |= F_UNPAID;
106 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 106 if (op->flag [FLAG_INV_LOCKED])
107 flags |= F_LOCKED; 107 flags |= F_LOCKED;
108 108
109 return flags; 109 return flags;
110} 110}
111 111
116static void 116static void
117add_object_to_socklist (client &ns, packet &sl, object *head) 117add_object_to_socklist (client &ns, packet &sl, object *head)
118{ 118{
119 int flags = query_flags (head); 119 int flags = query_flags (head);
120 120
121 if (QUERY_FLAG (head, FLAG_NO_PICK)) 121 if (head->flag [FLAG_NO_PICK])
122 flags |= F_NOPICK; 122 flags |= F_NOPICK;
123 123
124 ns.send_face (head->face, -50); 124 ns.send_face (head->face, -50);
125 ns.flush_fx ();
126 125
127 if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) 126 if (head->flag [FLAG_ANIMATE] && !ns.anims_sent[head->animation_id])
128 ns.send_animation (head->animation_id); 127 ns.send_animation (head->animation_id);
129 128
130 sl << uint32 (head->count) 129 sl << uint32 (head->count)
131 << uint32 (flags) 130 << uint32 (flags)
132 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : head->client_weight ()) 131 << uint32 (head->flag [FLAG_NO_PICK] ? -1 : head->client_weight ())
133 << uint32 (head->face); 132 << uint32 (head->face);
134 133
135 if (!head->custom_name) 134 if (!head->custom_name)
136 { 135 {
137 const char *name; 136 const char *name;
143 142
144 *len = sl.cur - len - 1; 143 *len = sl.cur - len - 1;
145 } 144 }
146 else 145 else
147 { 146 {
148 int len = min (head->custom_name.length (), 127); 147 int len = min (127, head->custom_name.length ());
149 148
150 sl << uint8 (len * 2 + 1) 149 sl << uint8 (len * 2 + 1)
151 << data (head->custom_name, len) 150 << data (head->custom_name, len)
152 << uint8 (0) 151 << uint8 (0)
153 << data (head->custom_name, len); 152 << data (head->custom_name, len);
155 154
156 sl << uint16 (head->animation_id); 155 sl << uint16 (head->animation_id);
157 156
158 int anim_speed = !head->flag [FLAG_ANIMATE] ? 0 157 int anim_speed = !head->flag [FLAG_ANIMATE] ? 0
159 : head->anim_speed ? clamp (head->anim_speed, 1, 255) 158 : head->anim_speed ? clamp (head->anim_speed, 1, 255)
160 : 1. / clamp (fabs (head->speed), 1./255., 1./1.); 159 : 1. / clamp (head->speed, 1./255., 1./1.);
161 160
162 sl << uint8 (anim_speed) 161 sl << uint8 (anim_speed)
163 << uint32 (head->nrof); 162 << uint32 (head->nrof);
164 163
165 if (ns.itemcmd == 2) 164 if (ns.itemcmd == 2)
194 { 193 {
195 LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name); 194 LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name);
196 return; 195 return;
197 } 196 }
198 197
198 if (pl->ns->need_delinv0)
199 {
200 pl->ns->need_delinv0 = 0;
201 pl->ns->send_packet ("delinv 0");
202 }
203
204 if (pl->run_on)
205 return;
206
199 pl->ns->update_look = 0; 207 pl->ns->update_look = 0;
208 pl->ns->need_delinv0 = 1;
200 209
201 if (QUERY_FLAG (ob, FLAG_REMOVED) 210 if (ob->flag [FLAG_REMOVED]
202 || !ob->map 211 || !ob->map
203 || ob->map->in_memory != MAP_ACTIVE 212 || ob->map->state != MAP_ACTIVE
204 || out_of_map (ob->map, ob->x, ob->y)) 213 || out_of_map (ob->map, ob->x, ob->y))
205 return; 214 return;
206
207 pl->ns->send_packet ("delinv 0");
208 215
209 packet sl; 216 packet sl;
210 sl.printf ("item%d ", pl->ns->itemcmd); 217 sl.printf ("item%d ", pl->ns->itemcmd);
211 218
212 sl << uint32 (0); 219 sl << uint32 (0);
279 dirty = true; 286 dirty = true;
280 287
281 // if packet got too large, send it and begin a new one 288 // if packet got too large, send it and begin a new one
282 if (sl.length () > MAXSOCKBUF - MAXITEMLEN) 289 if (sl.length () > MAXSOCKBUF - MAXITEMLEN)
283 { 290 {
291 pl->ns->flush_fx ();
284 pl->ns->send_packet (sl); 292 pl->ns->send_packet (sl);
285 293
286 sl.reset (); 294 sl.reset ();
287 sl.printf ("item%d ", pl->ns->itemcmd); 295 sl.printf ("item%d ", pl->ns->itemcmd);
288 sl << uint32 (0); 296 sl << uint32 (0);
307 315
308 dirty = true; 316 dirty = true;
309 } 317 }
310 318
311 if (dirty) 319 if (dirty)
320 {
321 pl->ns->flush_fx ();
312 pl->ns->send_packet (sl); 322 pl->ns->send_packet (sl);
323 }
313} 324}
314 325
315/** 326/**
316 * Sends whole inventory. 327 * Sends whole inventory.
317 */ 328 */
349 * items (especially with some of the bags out there) to 360 * items (especially with some of the bags out there) to
350 * overflow the buffer. IF so, send multiple item commands. 361 * overflow the buffer. IF so, send multiple item commands.
351 */ 362 */
352 if (sl.length () > MAXSOCKBUF - MAXITEMLEN) 363 if (sl.length () > MAXSOCKBUF - MAXITEMLEN)
353 { 364 {
365 pl->contr->ns->flush_fx ();
354 pl->contr->ns->send_packet (sl); 366 pl->contr->ns->send_packet (sl);
355 367
356 sl.reset (); 368 sl.reset ();
357 sl.printf ("item%d ", pl->contr->ns->itemcmd); 369 sl.printf ("item%d ", pl->contr->ns->itemcmd);
358 sl << uint32 (op->count); 370 sl << uint32 (op->count);
360 } 372 }
361 } 373 }
362 } 374 }
363 375
364 if (got_one) 376 if (got_one)
377 {
378 pl->contr->ns->flush_fx ();
365 pl->contr->ns->send_packet (sl); 379 pl->contr->ns->send_packet (sl);
380 }
366} 381}
367 382
368/** 383/**
369 * Updates object *op for player *pl. 384 * Updates object *op for player *pl.
370 * 385 *
441 456
442 if (flags & UPD_ANIMSPEED) 457 if (flags & UPD_ANIMSPEED)
443 { 458 {
444 int anim_speed = 0; 459 int anim_speed = 0;
445 460
446 if (QUERY_FLAG (op, FLAG_ANIMATE)) 461 if (op->flag [FLAG_ANIMATE])
447 { 462 {
448 if (op->anim_speed) 463 if (op->anim_speed)
449 anim_speed = op->anim_speed; 464 anim_speed = op->anim_speed;
450 else 465 else
451 { 466 {
452 if (fabs (op->speed) < 0.001) 467 if (op->speed < 0.001)
453 anim_speed = 255; 468 anim_speed = 255;
454 else if (fabs (op->speed) >= 1.0) 469 else if (op->speed >= 1.0)
455 anim_speed = 1; 470 anim_speed = 1;
456 else 471 else
457 anim_speed = (int) (1.0 / fabs (op->speed)); 472 anim_speed = 1. / op->speed;
458 } 473 }
459 474
460 if (anim_speed > 255) 475 if (anim_speed > 255)
461 anim_speed = 255; 476 anim_speed = 255;
462 } 477 }
491 506
492 sl << uint32 (op->env ? op->env->count : 0); 507 sl << uint32 (op->env ? op->env->count : 0);
493 508
494 add_object_to_socklist (*pl->contr->ns, sl, op); 509 add_object_to_socklist (*pl->contr->ns, sl, op);
495 510
511 pl->contr->ns->flush_fx ();
496 pl->contr->ns->send_packet (sl); 512 pl->contr->ns->send_packet (sl);
497} 513}
498 514
499/** 515/**
500 * Tells the client to delete an item. 516 * Tells the client to delete an item.
521 537
522/** 538/**
523 * Takes a player and object count (tag) and returns the actual object 539 * Takes a player and object count (tag) and returns the actual object
524 * pointer, or null if it can't be found. 540 * pointer, or null if it can't be found.
525 */ 541 */
526object * 542static object *
527esrv_get_ob_from_count (object *pl, tag_t count) 543esrv_get_ob_from_count (object *pl, tag_t count)
528{ 544{
529 if (pl->count == count) 545 if (pl->count == count)
530 return pl; 546 return pl;
531 547
611 pl->ns->look_position = tag & 0x7fffffff; 627 pl->ns->look_position = tag & 0x7fffffff;
612 pl->ns->floorbox_update (); 628 pl->ns->floorbox_update ();
613 return; 629 return;
614 } 630 }
615 631
632 // the object might be legally gone already
616 object *op = esrv_get_ob_from_count (pl->ob, tag); 633 if (object *op = esrv_get_ob_from_count (pl->ob, tag))
617 634 pl->ob->apply (op, AP_TOGGLE);
618 if (!op)
619 {
620 LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag);
621 return;
622 }
623
624 player_apply (pl->ob, op, 0, 0);
625} 635}
626 636
627/** Client wants to lock some object. Lets do so. */ 637/** Client wants to lock some object. Lets do so. */
628void 638void
629LockItem (char *data, int len, player *pl) 639LockItem (char *data, int len, player *pl)
637 pl->failmsg ("Could not find object to lock/unlock"); 647 pl->failmsg ("Could not find object to lock/unlock");
638 return; 648 return;
639 } 649 }
640 650
641 if (!flag) 651 if (!flag)
642 CLEAR_FLAG (op, FLAG_INV_LOCKED); 652 op->clr_flag (FLAG_INV_LOCKED);
643 else 653 else
644 SET_FLAG (op, FLAG_INV_LOCKED); 654 op->set_flag (FLAG_INV_LOCKED);
645 655
646 esrv_update_item (UPD_FLAGS, pl->ob, op); 656 esrv_update_item (UPD_FLAGS, pl->ob, op);
647} 657}
648 658
649/** Client wants to mark some object. Lets do so. */ 659/** Client wants to mark some object. Lets do so. */
689 { 699 {
690 mapspace &ms = *pos; 700 mapspace &ms = *pos;
691 ms.update (); 701 ms.update ();
692 702
693 buf.printf (" map: %s%+d%+d (%+d%+d)\n" 703 buf.printf (" map: %s%+d%+d (%+d%+d)\n"
694 " smell %u/%u; flags %x; light %d; block %x; slow %x; on %x; off %x; volume %lld\n\n", 704 " smell %u/%u; flags %x; light %d; block %x; slow %x; on %x; off %x; items %d, volume %lld\n\n",
695 &pos.m->path, pos.x, pos.y, dx, dy, 705 &pos.m->path, pos.x, pos.y, dx, dy,
696 (unsigned int)ms.smell, (unsigned int)mapspace::smellcount, ms.flags (), ms.light, 706 (unsigned int)ms.smell, (unsigned int)mapspace::smellcount, ms.flags (), ms.light,
697 ms.move_block, ms.move_slow, ms.move_on, ms.move_off, (long long)ms.volume () 707 ms.move_block, ms.move_slow, ms.move_on, ms.move_off, (int)ms.items (), (long long)ms.volume ()
698 ); 708 );
699 } 709 }
700 else 710 else
701 buf << "off-map\n\n"; 711 buf << "off-map\n\n";
702 } 712 }
710 else 720 else
711 { 721 {
712 if (pos.normalise ()) 722 if (pos.normalise ())
713 for (object *tmp = pos->top; tmp; tmp = tmp->below) 723 for (object *tmp = pos->top; tmp; tmp = tmp->below)
714 { 724 {
715 if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) 725 if (tmp->invisible && !ob->flag [FLAG_WIZ])
716 continue; 726 continue;
717 727
718 if (wiz) 728 if (wiz)
719 buf.printf (" - %s (%d).\n", query_name (tmp), tmp->count); 729 buf.printf (" - %s (%d) %s\n", query_name (tmp), tmp->count, tmp->uuid.c_str ());
720 else 730 else
721 buf.printf (" - %s.\n", query_name (tmp)); 731 buf.printf (" - %s.\n", query_name (tmp));
722 732
723 object *head = tmp->head_ (); 733 object *head = tmp->head_ ();
724 734
725 if (head->inv) 735 if (head->inv)
726 if ((head->type != CONTAINER && head->type != FLESH) 736 if ((head->type != CONTAINER && head->type != FLESH)
727 || QUERY_FLAG (ob, FLAG_WIZ)) 737 || ob->flag [FLAG_WIZ])
728 buf << head->query_inventory (ob, " "); 738 buf << head->query_inventory (ob, " ");
729 739
730 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !wiz) /* don't continue under the floor */ 740 if (tmp->flag [FLAG_IS_FLOOR] && !wiz) /* don't continue under the floor */
731 break; 741 break;
732 } 742 }
733 } 743 }
734 744
735 if (buf.empty ()) 745 if (buf.empty ())
770 return; 780 return;
771 781
772 /* If it is an active container, then we should drop all objects 782 /* If it is an active container, then we should drop all objects
773 * in the container and not the container itself. 783 * in the container and not the container itself.
774 */ 784 */
775 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 785 if (op->inv && op->flag [FLAG_APPLIED])
776 { 786 {
777 int cnt = MAX_ITEM_PER_DROP; 787 int cnt = MAX_ITEM_PER_ACTION;
778 788
779 for (object *current = op->inv; current && cnt--; ) 789 for (object *current = op->inv; current && cnt--; )
780 { 790 {
781 object *next = current->below; 791 object *next = current->below;
782 drop_object (pl, current, 0); 792 drop_object (pl, current, 0);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines