… | |
… | |
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 <sproto.h> |
37 | #include <sproto.h> |
39 | |
38 | |
40 | /** 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 */ |
… | |
… | |
46 | * |
45 | * |
47 | ******************************************************************************/ |
46 | ******************************************************************************/ |
48 | |
47 | |
49 | /** |
48 | /** |
50 | * This is a similar to query_name, but returns flags |
49 | * This is a similar to query_name, but returns flags |
51 | * to be sended to client. |
50 | * to be sent to client. |
52 | */ |
51 | */ |
53 | unsigned int |
52 | unsigned int |
54 | query_flags (object *op) |
53 | query_flags (object *op) |
55 | { |
54 | { |
56 | unsigned int flags = 0; |
55 | unsigned int flags = 0; |
57 | |
56 | |
58 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
57 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
59 | { |
58 | { |
60 | switch (op->type) |
59 | switch (op->type) |
61 | { |
60 | { |
62 | case BOW: |
61 | case BOW: |
63 | case WAND: |
62 | case WAND: |
64 | case ROD: |
63 | case ROD: |
65 | case HORN: |
64 | case HORN: |
66 | flags = a_readied; |
65 | flags = a_readied; |
67 | break; |
66 | break; |
68 | case WEAPON: |
67 | case WEAPON: |
69 | flags = a_wielded; |
68 | flags = a_wielded; |
70 | break; |
69 | break; |
71 | case SKILL: |
70 | case SKILL: |
72 | case ARMOUR: |
71 | case ARMOUR: |
73 | case HELMET: |
72 | case HELMET: |
74 | case SHIELD: |
73 | case SHIELD: |
75 | case RING: |
74 | case RING: |
76 | case BOOTS: |
75 | case BOOTS: |
77 | case GLOVES: |
76 | case GLOVES: |
78 | case AMULET: |
77 | case AMULET: |
79 | case GIRDLE: |
78 | case GIRDLE: |
80 | case BRACERS: |
79 | case BRACERS: |
81 | case CLOAK: |
80 | case CLOAK: |
82 | flags = a_worn; |
81 | flags = a_worn; |
83 | break; |
82 | break; |
84 | case CONTAINER: |
83 | case CONTAINER: |
85 | flags = a_active; |
84 | flags = a_active; |
86 | break; |
85 | break; |
87 | default: |
86 | default: |
88 | flags = a_applied; |
87 | flags = a_applied; |
89 | break; |
88 | break; |
90 | } |
89 | } |
91 | } |
90 | } |
|
|
91 | |
92 | 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)))) |
93 | flags |= F_OPEN; |
93 | flags |= F_OPEN; |
94 | |
94 | |
95 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
95 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
96 | { |
96 | { |
97 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
97 | if (QUERY_FLAG (op, FLAG_DAMNED)) |
98 | flags |= F_DAMNED; |
98 | flags |= F_DAMNED; |
99 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
99 | else if (QUERY_FLAG (op, FLAG_CURSED)) |
100 | flags |= F_CURSED; |
100 | flags |= F_CURSED; |
101 | } |
101 | } |
|
|
102 | |
102 | 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)) |
103 | flags |= F_MAGIC; |
104 | flags |= F_MAGIC; |
104 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
105 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
105 | flags |= F_UNPAID; |
106 | flags |= F_UNPAID; |
106 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
107 | if (QUERY_FLAG (op, FLAG_INV_LOCKED)) |
… | |
… | |
185 | SET_FLAG (head, FLAG_CLIENT_SENT); |
186 | SET_FLAG (head, FLAG_CLIENT_SENT); |
186 | } |
187 | } |
187 | |
188 | |
188 | |
189 | |
189 | /** |
190 | /** |
190 | * Send the look window. Don't need to do animations here |
191 | * Send the look window. Don't need to do animations here |
191 | * 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 |
192 | * because object ordering would otherwise be inconsistent |
193 | * because object ordering would otherwise be inconsistent. |
193 | */ |
194 | */ |
194 | |
|
|
195 | void |
195 | void |
196 | esrv_draw_look (object *pl) |
196 | esrv_draw_look (object *pl) |
197 | { |
197 | { |
198 | object *tmp, *last; |
198 | object *tmp, *last; |
199 | int got_one = 0, start_look = 0, end_look = 0; |
199 | int got_one = 0, start_look = 0, end_look = 0; |
… | |
… | |
214 | return; |
214 | return; |
215 | |
215 | |
216 | 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) |
217 | ; |
217 | ; |
218 | |
218 | |
|
|
219 | pl->contr->socket->send_packet ("delinv 0"); |
|
|
220 | |
219 | packet sl; |
221 | packet sl; |
220 | |
|
|
221 | pl->contr->socket->send_packet ("delinv 0"); |
|
|
222 | |
|
|
223 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
222 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
224 | |
223 | |
225 | sl << uint32 (0); |
224 | sl << uint32 (0); |
226 | |
225 | |
227 | 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)) |
228 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
227 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
229 | |
228 | |
230 | if (pl->contr->socket->look_position) |
229 | if (pl->contr->socket->look_position) |
231 | { |
230 | { |
232 | char buf[80]; |
231 | char buf[80]; |
233 | 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); |
234 | |
233 | |
235 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS)) |
234 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - FLOORBOX_PAGESIZE)) |
236 | << uint32 (0) |
235 | << uint32 (0) |
237 | << sint32 (-1) |
236 | << sint32 (-1) |
238 | << uint32 (empty_face->number) |
237 | << uint32 (empty_face->number) |
239 | << data8 (buf) |
238 | << data8 (buf) |
240 | << uint16 (0) |
239 | << uint16 (0) |
… | |
… | |
261 | if (++start_look < pl->contr->socket->look_position) |
260 | if (++start_look < pl->contr->socket->look_position) |
262 | continue; |
261 | continue; |
263 | |
262 | |
264 | end_look++; |
263 | end_look++; |
265 | |
264 | |
266 | if (end_look > NUM_LOOK_OBJECTS) |
265 | if (end_look > FLOORBOX_PAGESIZE) |
267 | { |
266 | { |
268 | /* 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, |
269 | * we notice the special tag the object has, and act accordingly. |
268 | * we notice the special tag the object has, and act accordingly. |
270 | */ |
269 | */ |
271 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS)) |
270 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + FLOORBOX_PAGESIZE)) |
272 | << uint32 (0) |
271 | << uint32 (0) |
273 | << uint32 ((uint32) - 1) |
272 | << uint32 ((uint32) - 1) |
274 | << uint32 (empty_face->number) |
273 | << uint32 (empty_face->number) |
275 | << data8 ("Apply this to see next group of items") |
274 | << data8 ("Apply this to see next group of items") |
276 | << uint16 (0) |
275 | << uint16 (0) |
… | |
… | |
298 | sl.reset (); |
297 | sl.reset (); |
299 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
298 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
300 | sl << uint32 (0); |
299 | sl << uint32 (0); |
301 | got_one = 0; |
300 | got_one = 0; |
302 | } |
301 | } |
303 | } /* If LOOK_OBJ() */ |
302 | } |
304 | } |
303 | } |
305 | |
304 | |
306 | if (got_one) |
305 | if (got_one) |
307 | pl->contr->socket->send_packet (sl); |
306 | pl->contr->socket->send_packet (sl); |
308 | |
307 | |
… | |
… | |
315 | esrv_send_inventory (object *pl, object *op) |
314 | esrv_send_inventory (object *pl, object *op) |
316 | { |
315 | { |
317 | object *tmp; |
316 | object *tmp; |
318 | int got_one = 0; |
317 | int got_one = 0; |
319 | |
318 | |
|
|
319 | |
|
|
320 | pl->contr->socket->send_packet_printf ("delinv %d", op->count); |
|
|
321 | |
320 | packet sl; |
322 | packet sl; |
321 | |
|
|
322 | sl.printf ("delinv %d", op->count); |
|
|
323 | pl->contr->socket->send_packet (sl); |
|
|
324 | |
|
|
325 | sl.reset (); |
|
|
326 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
323 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
327 | |
324 | |
328 | sl << uint32 (op->count); |
325 | sl << uint32 (op->count); |
329 | |
326 | |
330 | for (tmp = op->inv; tmp; tmp = tmp->below) |
327 | for (tmp = op->inv; tmp; tmp = tmp->below) |
… | |
… | |
358 | } /* If LOOK_OBJ() */ |
355 | } /* If LOOK_OBJ() */ |
359 | } |
356 | } |
360 | |
357 | |
361 | if (got_one) |
358 | if (got_one) |
362 | pl->contr->socket->send_packet (sl); |
359 | pl->contr->socket->send_packet (sl); |
363 | |
|
|
364 | } |
360 | } |
365 | |
361 | |
366 | /** |
362 | /** |
367 | * Updates object *op for player *pl. |
363 | * Updates object *op for player *pl. |
368 | * |
364 | * |
… | |
… | |
392 | * and track back the call. |
388 | * and track back the call. |
393 | */ |
389 | */ |
394 | 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); |
395 | } |
391 | } |
396 | |
392 | |
397 | packet sl; |
393 | packet sl ("upditem"); |
398 | |
394 | |
399 | sl << "upditem " |
|
|
400 | << uint8 (flags); |
395 | sl << uint8 (flags); |
401 | |
396 | |
402 | if (op->head) |
397 | if (op->head) |
403 | op = op->head; |
398 | op = op->head; |
404 | |
399 | |
405 | sl << uint32 (op->count); |
400 | sl << uint32 (op->count); |
… | |
… | |
505 | /* 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 |
506 | * be updated. |
501 | * be updated. |
507 | */ |
502 | */ |
508 | if (!op->env) |
503 | if (!op->env) |
509 | { |
504 | { |
510 | pl->contr->socket->update_look = 1; |
505 | pl->contr->socket->floorbox_update (); |
511 | return; |
506 | return; |
512 | } |
507 | } |
513 | } |
508 | } |
514 | |
509 | |
515 | packet sl; |
510 | packet sl; |
… | |
… | |
523 | |
518 | |
524 | add_object_to_socklist (*pl->contr->socket, sl, op); |
519 | add_object_to_socklist (*pl->contr->socket, sl, op); |
525 | |
520 | |
526 | pl->contr->socket->send_packet (sl); |
521 | pl->contr->socket->send_packet (sl); |
527 | SET_FLAG (op, FLAG_CLIENT_SENT); |
522 | SET_FLAG (op, FLAG_CLIENT_SENT); |
528 | |
|
|
529 | } |
523 | } |
530 | |
524 | |
531 | /** |
525 | /** |
532 | * Tells the client to delete an item. Uses the item |
526 | * Tells the client to delete an item. Uses the item |
533 | * command with a -1 location. |
527 | * command with a -1 location. |
534 | */ |
528 | */ |
535 | |
529 | |
536 | void |
530 | void |
537 | esrv_del_item (player *pl, int tag) |
531 | esrv_del_item (player *pl, int tag) |
538 | { |
532 | { |
539 | packet sl; |
533 | packet sl ("delitem"); |
540 | |
534 | |
541 | sl << "delitem " |
|
|
542 | << uint32 (tag); |
535 | sl << uint32 (tag); |
543 | |
536 | |
544 | pl->socket->send_packet (sl); |
537 | pl->socket->send_packet (sl); |
545 | } |
538 | } |
546 | |
539 | |
547 | |
540 | |
… | |
… | |
571 | for (tmp = op->inv; tmp; tmp = tmp->below) |
564 | for (tmp = op->inv; tmp; tmp = tmp->below) |
572 | if (tmp->count == count) |
565 | if (tmp->count == count) |
573 | return tmp; |
566 | return tmp; |
574 | |
567 | |
575 | 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) |
576 | if (op->head != NULL && op->head->count == count) |
569 | if (op->head && op->head->count == count) |
577 | return op; |
570 | return op; |
578 | else if (op->count == count) |
571 | else if (op->count == count) |
579 | return op; |
572 | return op; |
580 | else if (op->type == CONTAINER && pl->container == op) |
573 | else if (op->type == CONTAINER && pl->container == op) |
581 | for (tmp = op->inv; tmp; tmp = tmp->below) |
574 | for (tmp = op->inv; tmp; tmp = tmp->below) |
582 | if (tmp->count == count) |
575 | if (tmp->count == count) |
583 | return tmp; |
576 | return tmp; |
584 | |
577 | |
585 | return NULL; |
578 | return 0; |
586 | } |
579 | } |
587 | |
580 | |
588 | |
581 | |
589 | /** Client wants to examine some object. So lets do so. */ |
582 | /** Client wants to examine some object. So lets do so. */ |
590 | void |
583 | void |
… | |
… | |
605 | } |
598 | } |
606 | |
599 | |
607 | examine (pl->ob, op); |
600 | examine (pl->ob, op); |
608 | } |
601 | } |
609 | |
602 | |
610 | /** Client wants to apply some object. Lets do so. */ |
603 | /** Client wants to apply some object. Lets do so. */ |
611 | void |
604 | void |
612 | ApplyCmd (char *buf, int len, player *pl) |
605 | ApplyCmd (char *buf, int len, player *pl) |
613 | { |
606 | { |
614 | tag_t tag = atoi (buf); |
607 | tag_t tag = atoi (buf); |
615 | |
608 | |
… | |
… | |
621 | |
614 | |
622 | /* If the high bit is set, player applied a pseudo object. */ |
615 | /* If the high bit is set, player applied a pseudo object. */ |
623 | if (tag & 0x80000000) |
616 | if (tag & 0x80000000) |
624 | { |
617 | { |
625 | pl->socket->look_position = tag & 0x7fffffff; |
618 | pl->socket->look_position = tag & 0x7fffffff; |
626 | pl->socket->update_look = 1; |
619 | pl->socket->floorbox_update (); |
627 | return; |
620 | return; |
628 | } |
621 | } |
629 | |
622 | |
630 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
623 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
631 | |
624 | |
… | |
… | |
636 | } |
629 | } |
637 | |
630 | |
638 | player_apply (pl->ob, op, 0, 0); |
631 | player_apply (pl->ob, op, 0, 0); |
639 | } |
632 | } |
640 | |
633 | |
641 | /** Client wants to apply some object. Lets do so. */ |
634 | /** Client wants to lock some object. Lets do so. */ |
642 | void |
635 | void |
643 | LockItem (char *data, int len, player *pl) |
636 | LockItem (char *data, int len, player *pl) |
644 | { |
637 | { |
645 | int flag = data[0]; |
638 | int flag = data[0]; |
646 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
639 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
… | |
… | |
658 | SET_FLAG (op, FLAG_INV_LOCKED); |
651 | SET_FLAG (op, FLAG_INV_LOCKED); |
659 | |
652 | |
660 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
653 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
661 | } |
654 | } |
662 | |
655 | |
663 | /** Client wants to apply some object. Lets do so. */ |
656 | /** Client wants to mark some object. Lets do so. */ |
664 | void |
657 | void |
665 | MarkItem (char *data, int len, player *pl) |
658 | MarkItem (char *data, int len, player *pl) |
666 | { |
659 | { |
667 | tag_t tag = net_uint32 ((uint8 *)data); |
660 | tag_t tag = net_uint32 ((uint8 *)data); |
668 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
661 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
… | |
… | |
799 | } |
792 | } |
800 | |
793 | |
801 | esrv_update_item (UPD_WEIGHT, pl, op); |
794 | esrv_update_item (UPD_WEIGHT, pl, op); |
802 | } |
795 | } |
803 | else |
796 | else |
804 | { |
|
|
805 | drop_object (pl, op, nrof); |
797 | drop_object (pl, op, nrof); |
806 | } |
798 | |
807 | return; |
799 | return; |
808 | } |
800 | } |
809 | else if (to == pl->count) |
801 | else if (to == pl->count) |
810 | { /* pick it up to the inventory */ |
802 | { /* pick it up to the inventory */ |
811 | /* return if player has already picked it up */ |
803 | /* return if player has already picked it up */ |
… | |
… | |
828 | * 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 |
829 | * 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 |
830 | * 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. |
831 | */ |
823 | */ |
832 | 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)) |
833 | { |
|
|
834 | put_object_in_sack (pl, env, op, nrof); |
825 | put_object_in_sack (pl, env, op, nrof); |
835 | } |
|
|
836 | } |
826 | } |
837 | |
827 | |