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 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 | */ |
53 | unsigned int |
53 | static unsigned int |
54 | query_flags (object *op) |
54 | query_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: |
… | |
… | |
86 | default: |
86 | default: |
87 | flags = a_applied; |
87 | flags = a_applied; |
88 | break; |
88 | break; |
89 | } |
89 | } |
90 | |
90 | |
91 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
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 | |
… | |
… | |
114 | * animation of face to the client. |
114 | * animation of face to the client. |
115 | */ |
115 | */ |
116 | static void |
116 | static void |
117 | add_object_to_socklist (client &ns, packet &sl, object *head) |
117 | add_object_to_socklist (client &ns, packet &sl, object *head) |
118 | { |
118 | { |
119 | char item_n[MAX_BUF]; |
|
|
120 | const char *item_p; |
|
|
121 | |
|
|
122 | int flags = query_flags (head); |
119 | int flags = query_flags (head); |
123 | if (QUERY_FLAG (head, FLAG_NO_PICK)) |
120 | |
|
|
121 | if (head->flag [FLAG_NO_PICK]) |
124 | flags |= F_NOPICK; |
122 | flags |= F_NOPICK; |
125 | |
123 | |
126 | ns.send_face (head->face, -50); |
124 | ns.send_face (head->face, -50); |
127 | ns.flush_fx (); |
|
|
128 | |
125 | |
129 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
126 | if (head->flag [FLAG_ANIMATE] && !ns.anims_sent[head->animation_id]) |
130 | ns.send_animation (head->animation_id); |
127 | ns.send_animation (head->animation_id); |
131 | |
128 | |
132 | sl << uint32 (head->count) |
129 | sl << uint32 (head->count) |
133 | << uint32 (flags) |
130 | << uint32 (flags) |
134 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : head->client_weight ()) |
131 | << uint32 (head->flag [FLAG_NO_PICK] ? -1 : head->client_weight ()) |
135 | << uint32 (head->face); |
132 | << uint32 (head->face); |
136 | |
133 | |
137 | int len; |
|
|
138 | |
|
|
139 | if (!head->custom_name) |
134 | if (!head->custom_name) |
140 | { |
135 | { |
141 | strncpy (item_n, query_base_name (head, 0), 127); |
136 | const char *name; |
142 | item_n[127] = 0; |
137 | uint8 *len = sl.cur++; // patch up length later |
143 | len = strlen (item_n); |
138 | |
144 | item_p = query_base_name (head, 1); |
139 | name = query_base_name (head, 0); sl << data (name, min (127, strlen (name))); |
|
|
140 | sl << uint8 (0); |
|
|
141 | name = query_base_name (head, 1); sl << data (name, min (127, strlen (name))); |
|
|
142 | |
|
|
143 | *len = sl.cur - len - 1; |
145 | } |
144 | } |
146 | else |
145 | else |
147 | { |
146 | { |
148 | strncpy (item_n, head->custom_name, 127); |
147 | int len = min (head->custom_name.length (), 127); |
149 | item_n[127] = 0; |
|
|
150 | len = strlen (item_n); |
|
|
151 | item_p = head->custom_name; |
|
|
152 | } |
|
|
153 | |
148 | |
154 | strncpy (item_n + len + 1, item_p, 127); |
149 | sl << uint8 (len * 2 + 1) |
155 | item_n[254] = 0; |
150 | << data (head->custom_name, len) |
156 | len += strlen (item_n + 1 + len) + 1; |
151 | << uint8 (0) |
|
|
152 | << data (head->custom_name, len); |
|
|
153 | } |
157 | |
154 | |
158 | sl << data8 (item_n, len) |
|
|
159 | << uint16 (head->animation_id); |
155 | sl << uint16 (head->animation_id); |
160 | |
156 | |
161 | int anim_speed = !head->flag [FLAG_ANIMATE] ? 0 |
157 | int anim_speed = !head->flag [FLAG_ANIMATE] ? 0 |
162 | : head->anim_speed ? clamp (head->anim_speed, 1, 255) |
158 | : head->anim_speed ? clamp (head->anim_speed, 1, 255) |
163 | : 1. / clamp (fabs (head->speed), 1./255., 1./1.); |
159 | : 1. / clamp (head->speed, 1./255., 1./1.); |
164 | |
160 | |
165 | sl << uint8 (anim_speed) |
161 | sl << uint8 (anim_speed) |
166 | << uint32 (head->nrof); |
162 | << uint32 (head->nrof); |
167 | |
163 | |
168 | if (ns.itemcmd == 2) |
164 | if (ns.itemcmd == 2) |
… | |
… | |
199 | return; |
195 | return; |
200 | } |
196 | } |
201 | |
197 | |
202 | pl->ns->update_look = 0; |
198 | pl->ns->update_look = 0; |
203 | |
199 | |
204 | if (QUERY_FLAG (ob, FLAG_REMOVED) |
200 | if (ob->flag [FLAG_REMOVED] |
205 | || !ob->map |
201 | || !ob->map |
206 | || ob->map->in_memory != MAP_ACTIVE |
202 | || ob->map->in_memory != MAP_ACTIVE |
207 | || out_of_map (ob->map, ob->x, ob->y)) |
203 | || out_of_map (ob->map, ob->x, ob->y)) |
208 | return; |
204 | return; |
209 | |
205 | |
… | |
… | |
282 | dirty = true; |
278 | dirty = true; |
283 | |
279 | |
284 | // if packet got too large, send it and begin a new one |
280 | // if packet got too large, send it and begin a new one |
285 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
281 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
286 | { |
282 | { |
|
|
283 | pl->ns->flush_fx (); |
287 | pl->ns->send_packet (sl); |
284 | pl->ns->send_packet (sl); |
288 | |
285 | |
289 | sl.reset (); |
286 | sl.reset (); |
290 | sl.printf ("item%d ", pl->ns->itemcmd); |
287 | sl.printf ("item%d ", pl->ns->itemcmd); |
291 | sl << uint32 (0); |
288 | sl << uint32 (0); |
… | |
… | |
310 | |
307 | |
311 | dirty = true; |
308 | dirty = true; |
312 | } |
309 | } |
313 | |
310 | |
314 | if (dirty) |
311 | if (dirty) |
|
|
312 | { |
|
|
313 | pl->ns->flush_fx (); |
315 | pl->ns->send_packet (sl); |
314 | pl->ns->send_packet (sl); |
|
|
315 | } |
316 | } |
316 | } |
317 | |
317 | |
318 | /** |
318 | /** |
319 | * Sends whole inventory. |
319 | * Sends whole inventory. |
320 | */ |
320 | */ |
… | |
… | |
352 | * items (especially with some of the bags out there) to |
352 | * items (especially with some of the bags out there) to |
353 | * overflow the buffer. IF so, send multiple item commands. |
353 | * overflow the buffer. IF so, send multiple item commands. |
354 | */ |
354 | */ |
355 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
355 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
356 | { |
356 | { |
|
|
357 | pl->contr->ns->flush_fx (); |
357 | pl->contr->ns->send_packet (sl); |
358 | pl->contr->ns->send_packet (sl); |
358 | |
359 | |
359 | sl.reset (); |
360 | sl.reset (); |
360 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
361 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
361 | sl << uint32 (op->count); |
362 | sl << uint32 (op->count); |
… | |
… | |
363 | } |
364 | } |
364 | } |
365 | } |
365 | } |
366 | } |
366 | |
367 | |
367 | if (got_one) |
368 | if (got_one) |
|
|
369 | { |
|
|
370 | pl->contr->ns->flush_fx (); |
368 | pl->contr->ns->send_packet (sl); |
371 | pl->contr->ns->send_packet (sl); |
|
|
372 | } |
369 | } |
373 | } |
370 | |
374 | |
371 | /** |
375 | /** |
372 | * Updates object *op for player *pl. |
376 | * Updates object *op for player *pl. |
373 | * |
377 | * |
… | |
… | |
444 | |
448 | |
445 | if (flags & UPD_ANIMSPEED) |
449 | if (flags & UPD_ANIMSPEED) |
446 | { |
450 | { |
447 | int anim_speed = 0; |
451 | int anim_speed = 0; |
448 | |
452 | |
449 | if (QUERY_FLAG (op, FLAG_ANIMATE)) |
453 | if (op->flag [FLAG_ANIMATE]) |
450 | { |
454 | { |
451 | if (op->anim_speed) |
455 | if (op->anim_speed) |
452 | anim_speed = op->anim_speed; |
456 | anim_speed = op->anim_speed; |
453 | else |
457 | else |
454 | { |
458 | { |
455 | if (fabs (op->speed) < 0.001) |
459 | if (op->speed < 0.001) |
456 | anim_speed = 255; |
460 | anim_speed = 255; |
457 | else if (fabs (op->speed) >= 1.0) |
461 | else if (op->speed >= 1.0) |
458 | anim_speed = 1; |
462 | anim_speed = 1; |
459 | else |
463 | else |
460 | anim_speed = (int) (1.0 / fabs (op->speed)); |
464 | anim_speed = 1. / op->speed; |
461 | } |
465 | } |
462 | |
466 | |
463 | if (anim_speed > 255) |
467 | if (anim_speed > 255) |
464 | anim_speed = 255; |
468 | anim_speed = 255; |
465 | } |
469 | } |
… | |
… | |
494 | |
498 | |
495 | sl << uint32 (op->env ? op->env->count : 0); |
499 | sl << uint32 (op->env ? op->env->count : 0); |
496 | |
500 | |
497 | add_object_to_socklist (*pl->contr->ns, sl, op); |
501 | add_object_to_socklist (*pl->contr->ns, sl, op); |
498 | |
502 | |
|
|
503 | pl->contr->ns->flush_fx (); |
499 | pl->contr->ns->send_packet (sl); |
504 | pl->contr->ns->send_packet (sl); |
500 | } |
505 | } |
501 | |
506 | |
502 | /** |
507 | /** |
503 | * Tells the client to delete an item. |
508 | * Tells the client to delete an item. |
… | |
… | |
524 | |
529 | |
525 | /** |
530 | /** |
526 | * Takes a player and object count (tag) and returns the actual object |
531 | * Takes a player and object count (tag) and returns the actual object |
527 | * pointer, or null if it can't be found. |
532 | * pointer, or null if it can't be found. |
528 | */ |
533 | */ |
529 | object * |
534 | static object * |
530 | esrv_get_ob_from_count (object *pl, tag_t count) |
535 | esrv_get_ob_from_count (object *pl, tag_t count) |
531 | { |
536 | { |
532 | if (pl->count == count) |
537 | if (pl->count == count) |
533 | return pl; |
538 | return pl; |
534 | |
539 | |
535 | for (object *op = pl->inv; op; op = op->below) |
540 | for (object *op = pl->inv; op; op = op->below) |
536 | if (op->count == count) |
541 | if (op->count == count) |
537 | return op; |
542 | return op; |
538 | else if (op->type == CONTAINER && pl->container == op) |
543 | else if (op->type == CONTAINER && pl->container_ () == op) |
539 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
544 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
540 | if (tmp->count == count) |
545 | if (tmp->count == count) |
541 | return tmp; |
546 | return tmp; |
542 | |
547 | |
543 | for (object *op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
548 | for (object *op = GET_MAP_OB (pl->map, pl->x, pl->y); op; op = op->above) |
544 | if (op->head && op->head->count == count) |
549 | if (op->head && op->head->count == count) |
545 | return op; |
550 | return op; |
546 | else if (op->count == count) |
551 | else if (op->count == count) |
547 | return op; |
552 | return op; |
548 | else if (op->type == CONTAINER && pl->container == op) |
553 | else if (op->type == CONTAINER && pl->container_ () == op) |
549 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
554 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
550 | if (tmp->count == count) |
555 | if (tmp->count == count) |
551 | return tmp; |
556 | return tmp; |
552 | |
557 | |
553 | #if 0 |
558 | #if 0 |
… | |
… | |
622 | { |
627 | { |
623 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
628 | LOG (llevDebug, "Player '%s' tried to apply the unknown object (%d)\n", &pl->ob->name, tag); |
624 | return; |
629 | return; |
625 | } |
630 | } |
626 | |
631 | |
627 | player_apply (pl->ob, op, 0, 0); |
632 | pl->ob->apply (op, AP_TOGGLE); |
628 | } |
633 | } |
629 | |
634 | |
630 | /** Client wants to lock some object. Lets do so. */ |
635 | /** Client wants to lock some object. Lets do so. */ |
631 | void |
636 | void |
632 | LockItem (char *data, int len, player *pl) |
637 | LockItem (char *data, int len, player *pl) |
… | |
… | |
640 | pl->failmsg ("Could not find object to lock/unlock"); |
645 | pl->failmsg ("Could not find object to lock/unlock"); |
641 | return; |
646 | return; |
642 | } |
647 | } |
643 | |
648 | |
644 | if (!flag) |
649 | if (!flag) |
645 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
650 | op->clr_flag (FLAG_INV_LOCKED); |
646 | else |
651 | else |
647 | SET_FLAG (op, FLAG_INV_LOCKED); |
652 | op->set_flag (FLAG_INV_LOCKED); |
648 | |
653 | |
649 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
654 | esrv_update_item (UPD_FLAGS, pl->ob, op); |
650 | } |
655 | } |
651 | |
656 | |
652 | /** Client wants to mark some object. Lets do so. */ |
657 | /** Client wants to mark some object. Lets do so. */ |
… | |
… | |
692 | { |
697 | { |
693 | mapspace &ms = *pos; |
698 | mapspace &ms = *pos; |
694 | ms.update (); |
699 | ms.update (); |
695 | |
700 | |
696 | buf.printf (" map: %s%+d%+d (%+d%+d)\n" |
701 | buf.printf (" map: %s%+d%+d (%+d%+d)\n" |
697 | " smell %u/%u; flags %x; light %d; block %x; slow %x; on %x; off %x; volume %lld\n\n", |
702 | " smell %u/%u; flags %x; light %d; block %x; slow %x; on %x; off %x; items %d, volume %lld\n\n", |
698 | &pos.m->path, pos.x, pos.y, dx, dy, |
703 | &pos.m->path, pos.x, pos.y, dx, dy, |
699 | (unsigned int)ms.smell, (unsigned int)mapspace::smellcount, ms.flags (), ms.light, |
704 | (unsigned int)ms.smell, (unsigned int)mapspace::smellcount, ms.flags (), ms.light, |
700 | ms.move_block, ms.move_slow, ms.move_on, ms.move_off, (long long)ms.volume () |
705 | ms.move_block, ms.move_slow, ms.move_on, ms.move_off, (int)ms.items (), (long long)ms.volume () |
701 | ); |
706 | ); |
702 | } |
707 | } |
703 | else |
708 | else |
704 | buf << "off-map\n\n"; |
709 | buf << "off-map\n\n"; |
705 | } |
710 | } |
… | |
… | |
713 | else |
718 | else |
714 | { |
719 | { |
715 | if (pos.normalise ()) |
720 | if (pos.normalise ()) |
716 | for (object *tmp = pos->top; tmp; tmp = tmp->below) |
721 | for (object *tmp = pos->top; tmp; tmp = tmp->below) |
717 | { |
722 | { |
718 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
723 | if (tmp->invisible && !ob->flag [FLAG_WIZ]) |
719 | continue; |
724 | continue; |
720 | |
725 | |
721 | if (wiz) |
726 | if (wiz) |
722 | buf.printf (" - %s (%d).\n", query_name (tmp), tmp->count); |
727 | buf.printf (" - %s (%d) %s\n", query_name (tmp), tmp->count, tmp->uuid.c_str ()); |
723 | else |
728 | else |
724 | buf.printf (" - %s.\n", query_name (tmp)); |
729 | buf.printf (" - %s.\n", query_name (tmp)); |
725 | |
730 | |
726 | object *head = tmp->head_ (); |
731 | object *head = tmp->head_ (); |
727 | |
732 | |
728 | if (head->inv) |
733 | if (head->inv) |
729 | if ((head->type != CONTAINER && head->type != FLESH) |
734 | if ((head->type != CONTAINER && head->type != FLESH) |
730 | || QUERY_FLAG (ob, FLAG_WIZ)) |
735 | || ob->flag [FLAG_WIZ]) |
731 | buf << head->query_inventory (ob, " "); |
736 | buf << head->query_inventory (ob, " "); |
732 | |
737 | |
733 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !wiz) /* don't continue under the floor */ |
738 | if (tmp->flag [FLAG_IS_FLOOR] && !wiz) /* don't continue under the floor */ |
734 | break; |
739 | break; |
735 | } |
740 | } |
736 | } |
741 | } |
737 | |
742 | |
738 | if (buf.empty ()) |
743 | if (buf.empty ()) |
… | |
… | |
773 | return; |
778 | return; |
774 | |
779 | |
775 | /* If it is an active container, then we should drop all objects |
780 | /* If it is an active container, then we should drop all objects |
776 | * in the container and not the container itself. |
781 | * in the container and not the container itself. |
777 | */ |
782 | */ |
778 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
783 | if (op->inv && op->flag [FLAG_APPLIED]) |
779 | { |
784 | { |
780 | int cnt = MAX_ITEM_PER_DROP; |
785 | int cnt = MAX_ITEM_PER_ACTION; |
781 | |
786 | |
782 | for (object *current = op->inv; current && cnt--; ) |
787 | for (object *current = op->inv; current && cnt--; ) |
783 | { |
788 | { |
784 | object *next = current->below; |
789 | object *next = current->below; |
785 | drop_object (pl, current, 0); |
790 | drop_object (pl, current, 0); |