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.21 by root, Fri Dec 15 00:34:17 2006 UTC vs.
Revision 1.27 by root, Wed Dec 20 01:19:11 2006 UTC

30 * This containes item logic for client/server. It doesn't contain 30 * This containes item logic for client/server. It doesn't contain
31 * the actual commands that send the data, but does contain 31 * the actual commands that send the data, but does contain
32 * the logic for what items should be sent. 32 * the logic for what items should be sent.
33 */ 33 */
34 34
35
36#include <global.h> 35#include <global.h>
37#include <object.h> /* LOOK_OBJ */ 36#include <object.h> /* LOOK_OBJ */
38#include <newclient.h>
39#include <newserver.h>
40#include <sproto.h> 37#include <sproto.h>
41 38
42/** This is the maximum number of bytes we expect any one item to take up */ 39/** This is the maximum number of bytes we expect any one item to take up */
43#define MAXITEMLEN 300 40#define MAXITEMLEN 300
44 41
48 * 45 *
49 ******************************************************************************/ 46 ******************************************************************************/
50 47
51/** 48/**
52 * This is a similar to query_name, but returns flags 49 * This is a similar to query_name, but returns flags
53 * to be sended to client. 50 * to be sent to client.
54 */ 51 */
55unsigned int 52unsigned int
56query_flags (object *op) 53query_flags (object *op)
57{ 54{
58 unsigned int flags = 0; 55 unsigned int flags = 0;
59 56
60 if (QUERY_FLAG (op, FLAG_APPLIED)) 57 if (QUERY_FLAG (op, FLAG_APPLIED))
61 { 58 {
62 switch (op->type) 59 switch (op->type)
63 { 60 {
64 case BOW: 61 case BOW:
65 case WAND: 62 case WAND:
66 case ROD: 63 case ROD:
67 case HORN: 64 case HORN:
68 flags = a_readied; 65 flags = a_readied;
69 break; 66 break;
70 case WEAPON: 67 case WEAPON:
71 flags = a_wielded; 68 flags = a_wielded;
72 break; 69 break;
73 case SKILL: 70 case SKILL:
74 case ARMOUR: 71 case ARMOUR:
75 case HELMET: 72 case HELMET:
76 case SHIELD: 73 case SHIELD:
77 case RING: 74 case RING:
78 case BOOTS: 75 case BOOTS:
79 case GLOVES: 76 case GLOVES:
80 case AMULET: 77 case AMULET:
81 case GIRDLE: 78 case GIRDLE:
82 case BRACERS: 79 case BRACERS:
83 case CLOAK: 80 case CLOAK:
84 flags = a_worn; 81 flags = a_worn;
85 break; 82 break;
86 case CONTAINER: 83 case CONTAINER:
87 flags = a_active; 84 flags = a_active;
88 break; 85 break;
89 default: 86 default:
90 flags = a_applied; 87 flags = a_applied;
91 break; 88 break;
92 } 89 }
93 } 90 }
91
94 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) 92 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED))))
95 flags |= F_OPEN; 93 flags |= F_OPEN;
96 94
97 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) 95 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
98 { 96 {
99 if (QUERY_FLAG (op, FLAG_DAMNED)) 97 if (QUERY_FLAG (op, FLAG_DAMNED))
100 flags |= F_DAMNED; 98 flags |= F_DAMNED;
101 else if (QUERY_FLAG (op, FLAG_CURSED)) 99 else if (QUERY_FLAG (op, FLAG_CURSED))
102 flags |= F_CURSED; 100 flags |= F_CURSED;
103 } 101 }
102
104 if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) 103 if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED))
105 flags |= F_MAGIC; 104 flags |= F_MAGIC;
106 if (QUERY_FLAG (op, FLAG_UNPAID)) 105 if (QUERY_FLAG (op, FLAG_UNPAID))
107 flags |= F_UNPAID; 106 flags |= F_UNPAID;
108 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 107 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
114/* Used in the send_look to put object head into packet 113/* Used in the send_look to put object head into packet
115 * sl for socket ns. Need socket to know if we need to send 114 * sl for socket ns. Need socket to know if we need to send
116 * animation of face to the client. 115 * animation of face to the client.
117 */ 116 */
118static void 117static void
119add_object_to_socklist (client_socket &ns, packet &sl, object *head) 118add_object_to_socklist (client &ns, packet &sl, object *head)
120{ 119{
121 int flags, len, anim_speed; 120 int flags, len, anim_speed;
122 char item_n[MAX_BUF]; 121 char item_n[MAX_BUF];
123 const char *item_p; 122 const char *item_p;
124 123
187 SET_FLAG (head, FLAG_CLIENT_SENT); 186 SET_FLAG (head, FLAG_CLIENT_SENT);
188} 187}
189 188
190 189
191/** 190/**
192 * Send the look window. Don't need to do animations here 191 * Send the look window. Don't need to do animations here
193 * This sends all the faces to the client, not just updates. This is 192 * This sends all the faces to the client, not just updates. This is
194 * because object ordering would otherwise be inconsistent 193 * because object ordering would otherwise be inconsistent.
195 */ 194 */
196
197void 195void
198esrv_draw_look (object *pl) 196esrv_draw_look (object *pl)
199{ 197{
200 object *tmp, *last; 198 object *tmp, *last;
201 int got_one = 0, start_look = 0, end_look = 0; 199 int got_one = 0, start_look = 0, end_look = 0;
216 return; 214 return;
217 215
218 for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) 216 for (tmp = get_map_ob (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above)
219 ; 217 ;
220 218
219 pl->contr->socket->send_packet ("delinv 0");
220
221 packet sl; 221 packet sl;
222
223 pl->contr->socket->send_packet ("delinv 0");
224
225 sl.printf ("item%d ", pl->contr->socket->itemcmd); 222 sl.printf ("item%d ", pl->contr->socket->itemcmd);
226 223
227 sl << uint32 (0); 224 sl << uint32 (0);
228 225
229 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) 226 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE))
230 esrv_send_face (pl->contr->socket, empty_face->number, 0); 227 esrv_send_face (pl->contr->socket, empty_face->number, 0);
231 228
232 if (pl->contr->socket->look_position) 229 if (pl->contr->socket->look_position)
233 { 230 {
234 char buf[80]; 231 char buf[80];
235 snprintf (buf, 80, "Apply this to see %d previous items", NUM_LOOK_OBJECTS); 232 snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE);
236 233
237 sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) 234 sl << uint32 (0x80000000 | (pl->contr->socket->look_position - FLOORBOX_PAGESIZE))
238 << uint32 (0) 235 << uint32 (0)
239 << sint32 (-1) 236 << sint32 (-1)
240 << uint32 (empty_face->number) 237 << uint32 (empty_face->number)
241 << data8 (buf) 238 << data8 (buf)
242 << uint16 (0) 239 << uint16 (0)
263 if (++start_look < pl->contr->socket->look_position) 260 if (++start_look < pl->contr->socket->look_position)
264 continue; 261 continue;
265 262
266 end_look++; 263 end_look++;
267 264
268 if (end_look > NUM_LOOK_OBJECTS) 265 if (end_look > FLOORBOX_PAGESIZE)
269 { 266 {
270 /* What we basically do is make a 'fake' object - when the user applies it, 267 /* What we basically do is make a 'fake' object - when the user applies it,
271 * we notice the special tag the object has, and act accordingly. 268 * we notice the special tag the object has, and act accordingly.
272 */ 269 */
273 sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) 270 sl << uint32 (0x80000000 | (pl->contr->socket->look_position + FLOORBOX_PAGESIZE))
274 << uint32 (0) 271 << uint32 (0)
275 << uint32 ((uint32) - 1) 272 << uint32 ((uint32) - 1)
276 << uint32 (empty_face->number) 273 << uint32 (empty_face->number)
277 << data8 ("Apply this to see next group of items") 274 << data8 ("Apply this to see next group of items")
278 << uint16 (0) 275 << uint16 (0)
300 sl.reset (); 297 sl.reset ();
301 sl.printf ("item%d ", pl->contr->socket->itemcmd); 298 sl.printf ("item%d ", pl->contr->socket->itemcmd);
302 sl << uint32 (0); 299 sl << uint32 (0);
303 got_one = 0; 300 got_one = 0;
304 } 301 }
305 } /* If LOOK_OBJ() */ 302 }
306 } 303 }
307 304
308 if (got_one) 305 if (got_one)
309 pl->contr->socket->send_packet (sl); 306 pl->contr->socket->send_packet (sl);
310 307
317esrv_send_inventory (object *pl, object *op) 314esrv_send_inventory (object *pl, object *op)
318{ 315{
319 object *tmp; 316 object *tmp;
320 int got_one = 0; 317 int got_one = 0;
321 318
319
320 pl->contr->socket->send_packet_printf ("delinv %d", op->count);
321
322 packet sl; 322 packet sl;
323
324 sl.printf ("delinv %d", op->count);
325 pl->contr->socket->send_packet (sl);
326
327 sl.reset ();
328 sl.printf ("item%d ", pl->contr->socket->itemcmd); 323 sl.printf ("item%d ", pl->contr->socket->itemcmd);
329 324
330 sl << uint32 (op->count); 325 sl << uint32 (op->count);
331 326
332 for (tmp = op->inv; tmp; tmp = tmp->below) 327 for (tmp = op->inv; tmp; tmp = tmp->below)
360 } /* If LOOK_OBJ() */ 355 } /* If LOOK_OBJ() */
361 } 356 }
362 357
363 if (got_one) 358 if (got_one)
364 pl->contr->socket->send_packet (sl); 359 pl->contr->socket->send_packet (sl);
365
366} 360}
367 361
368/** 362/**
369 * Updates object *op for player *pl. 363 * Updates object *op for player *pl.
370 * 364 *
394 * and track back the call. 388 * and track back the call.
395 */ 389 */
396 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count); 390 LOG (llevDebug, "We have not sent item %s (%d)\n", &op->name, op->count);
397 } 391 }
398 392
399 packet sl; 393 packet sl ("upditem");
400 394
401 sl << "upditem "
402 << uint8 (flags); 395 sl << uint8 (flags);
403 396
404 if (op->head) 397 if (op->head)
405 op = op->head; 398 op = op->head;
406 399
407 sl << uint32 (op->count); 400 sl << uint32 (op->count);
507 /* if the item is on the ground, mark that the look needs to 500 /* if the item is on the ground, mark that the look needs to
508 * be updated. 501 * be updated.
509 */ 502 */
510 if (!op->env) 503 if (!op->env)
511 { 504 {
512 pl->contr->socket->update_look = 1; 505 pl->contr->socket->floorbox_update ();
513 return; 506 return;
514 } 507 }
515 } 508 }
516 509
517 packet sl; 510 packet sl;
525 518
526 add_object_to_socklist (*pl->contr->socket, sl, op); 519 add_object_to_socklist (*pl->contr->socket, sl, op);
527 520
528 pl->contr->socket->send_packet (sl); 521 pl->contr->socket->send_packet (sl);
529 SET_FLAG (op, FLAG_CLIENT_SENT); 522 SET_FLAG (op, FLAG_CLIENT_SENT);
530
531} 523}
532 524
533/** 525/**
534 * Tells the client to delete an item. Uses the item 526 * Tells the client to delete an item. Uses the item
535 * command with a -1 location. 527 * command with a -1 location.
536 */ 528 */
537 529
538void 530void
539esrv_del_item (player *pl, int tag) 531esrv_del_item (player *pl, int tag)
540{ 532{
541 packet sl; 533 packet sl ("delitem");
542 534
543 sl << "delitem "
544 << uint32 (tag); 535 sl << uint32 (tag);
545 536
546 pl->socket->send_packet (sl); 537 pl->socket->send_packet (sl);
547} 538}
548 539
549 540
573 for (tmp = op->inv; tmp; tmp = tmp->below) 564 for (tmp = op->inv; tmp; tmp = tmp->below)
574 if (tmp->count == count) 565 if (tmp->count == count)
575 return tmp; 566 return tmp;
576 567
577 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) 568 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above)
578 if (op->head != NULL && op->head->count == count) 569 if (op->head && op->head->count == count)
579 return op; 570 return op;
580 else if (op->count == count) 571 else if (op->count == count)
581 return op; 572 return op;
582 else if (op->type == CONTAINER && pl->container == op) 573 else if (op->type == CONTAINER && pl->container == op)
583 for (tmp = op->inv; tmp; tmp = tmp->below) 574 for (tmp = op->inv; tmp; tmp = tmp->below)
584 if (tmp->count == count) 575 if (tmp->count == count)
585 return tmp; 576 return tmp;
586 577
587 return NULL; 578 return 0;
588} 579}
589 580
590 581
591/** Client wants to examine some object. So lets do so. */ 582/** Client wants to examine some object. So lets do so. */
592void 583void
607 } 598 }
608 599
609 examine (pl->ob, op); 600 examine (pl->ob, op);
610} 601}
611 602
612/** Client wants to apply some object. Lets do so. */ 603/** Client wants to apply some object. Lets do so. */
613void 604void
614ApplyCmd (char *buf, int len, player *pl) 605ApplyCmd (char *buf, int len, player *pl)
615{ 606{
616 tag_t tag = atoi (buf); 607 tag_t tag = atoi (buf);
617 608
623 614
624 /* If the high bit is set, player applied a pseudo object. */ 615 /* If the high bit is set, player applied a pseudo object. */
625 if (tag & 0x80000000) 616 if (tag & 0x80000000)
626 { 617 {
627 pl->socket->look_position = tag & 0x7fffffff; 618 pl->socket->look_position = tag & 0x7fffffff;
628 pl->socket->update_look = 1; 619 pl->socket->floorbox_update ();
629 return; 620 return;
630 } 621 }
631 622
632 object *op = esrv_get_ob_from_count (pl->ob, tag); 623 object *op = esrv_get_ob_from_count (pl->ob, tag);
633 624
638 } 629 }
639 630
640 player_apply (pl->ob, op, 0, 0); 631 player_apply (pl->ob, op, 0, 0);
641} 632}
642 633
643/** Client wants to apply some object. Lets do so. */ 634/** Client wants to lock some object. Lets do so. */
644void 635void
645LockItem (uint8 *data, int len, player *pl) 636LockItem (char *data, int len, player *pl)
646{ 637{
647 int flag = data[0]; 638 int flag = data[0];
648 tag_t tag = net_uint32 (data + 1); 639 tag_t tag = net_uint32 ((uint8 *)data + 1);
649 object *op = esrv_get_ob_from_count (pl->ob, tag); 640 object *op = esrv_get_ob_from_count (pl->ob, tag);
650 641
651 if (!op) 642 if (!op)
652 { 643 {
653 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); 644 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock");
660 SET_FLAG (op, FLAG_INV_LOCKED); 651 SET_FLAG (op, FLAG_INV_LOCKED);
661 652
662 esrv_update_item (UPD_FLAGS, pl->ob, op); 653 esrv_update_item (UPD_FLAGS, pl->ob, op);
663} 654}
664 655
665/** Client wants to apply some object. Lets do so. */ 656/** Client wants to mark some object. Lets do so. */
666void 657void
667MarkItem (uint8 * data, int len, player *pl) 658MarkItem (char *data, int len, player *pl)
668{ 659{
669 tag_t tag = net_uint32 (data); 660 tag_t tag = net_uint32 ((uint8 *)data);
670 object *op = esrv_get_ob_from_count (pl->ob, tag); 661 object *op = esrv_get_ob_from_count (pl->ob, tag);
671 662
672 if (!op) 663 if (!op)
673 { 664 {
674 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 665 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark");
801 } 792 }
802 793
803 esrv_update_item (UPD_WEIGHT, pl, op); 794 esrv_update_item (UPD_WEIGHT, pl, op);
804 } 795 }
805 else 796 else
806 {
807 drop_object (pl, op, nrof); 797 drop_object (pl, op, nrof);
808 } 798
809 return; 799 return;
810 } 800 }
811 else if (to == pl->count) 801 else if (to == pl->count)
812 { /* pick it up to the inventory */ 802 { /* pick it up to the inventory */
813 /* return if player has already picked it up */ 803 /* return if player has already picked it up */
830 * has already been done (eg, it can be picked up and fits in 820 * has already been done (eg, it can be picked up and fits in
831 * in a sack, so check for those things. We should also check 821 * in a sack, so check for those things. We should also check
832 * an make sure env is in fact a container for that matter. 822 * an make sure env is in fact a container for that matter.
833 */ 823 */
834 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) 824 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof))
835 {
836 put_object_in_sack (pl, env, op, nrof); 825 put_object_in_sack (pl, env, op, nrof);
837 }
838} 826}
839 827

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines