1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * 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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /** |
24 | /** |
25 | * \file |
25 | * \file |
26 | * Client/server logic. |
26 | * Client/server logic. |
… | |
… | |
193 | query_flags (object *op) |
193 | query_flags (object *op) |
194 | { |
194 | { |
195 | unsigned int flags = 0; |
195 | unsigned int flags = 0; |
196 | |
196 | |
197 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
197 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
198 | { |
|
|
199 | switch (op->type) |
198 | switch (op->type) |
200 | { |
199 | { |
201 | case BOW: |
200 | case BOW: |
202 | case WAND: |
201 | case WAND: |
203 | case ROD: |
202 | case ROD: |
204 | case HORN: |
203 | case HORN: |
205 | flags = a_readied; |
204 | flags = a_readied; |
206 | break; |
205 | break; |
207 | case WEAPON: |
206 | case WEAPON: |
208 | flags = a_wielded; |
207 | flags = a_wielded; |
209 | break; |
208 | break; |
210 | case SKILL: |
209 | case SKILL: |
211 | case ARMOUR: |
210 | case ARMOUR: |
212 | case HELMET: |
211 | case HELMET: |
213 | case SHIELD: |
212 | case SHIELD: |
214 | case RING: |
213 | case RING: |
215 | case BOOTS: |
214 | case BOOTS: |
216 | case GLOVES: |
215 | case GLOVES: |
217 | case AMULET: |
216 | case AMULET: |
218 | case GIRDLE: |
217 | case GIRDLE: |
219 | case BRACERS: |
218 | case BRACERS: |
220 | case CLOAK: |
219 | case CLOAK: |
221 | flags = a_worn; |
220 | flags = a_worn; |
222 | break; |
221 | break; |
223 | case CONTAINER: |
222 | case CONTAINER: |
224 | flags = a_active; |
223 | flags = a_active; |
225 | break; |
224 | break; |
226 | default: |
225 | default: |
227 | flags = a_applied; |
226 | flags = a_applied; |
228 | break; |
227 | break; |
229 | } |
228 | } |
230 | } |
|
|
231 | |
229 | |
232 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
230 | if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) |
233 | flags |= F_OPEN; |
231 | flags |= F_OPEN; |
234 | |
232 | |
235 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
233 | if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) |
… | |
… | |
271 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
269 | if (QUERY_FLAG (head, FLAG_ANIMATE) && !ns.anims_sent[head->animation_id]) |
272 | ns.send_animation (head->animation_id); |
270 | ns.send_animation (head->animation_id); |
273 | |
271 | |
274 | sl << uint32 (head->count) |
272 | sl << uint32 (head->count) |
275 | << uint32 (flags) |
273 | << uint32 (flags) |
276 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) |
274 | << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : head->client_weight ()) |
277 | << uint32 (head->face); |
275 | << uint32 (head->face); |
278 | |
276 | |
279 | if (!head->custom_name) |
277 | if (!head->custom_name) |
280 | { |
278 | { |
281 | strncpy (item_n, query_base_name (head, 0), 127); |
279 | strncpy (item_n, query_base_name (head, 0), 127); |
… | |
… | |
341 | if (!pl->ns->update_look) |
339 | if (!pl->ns->update_look) |
342 | { |
340 | { |
343 | LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name); |
341 | LOG (llevDebug, "esrv_draw_look called when update_look was not set (player %s)\n", &ob->name); |
344 | return; |
342 | return; |
345 | } |
343 | } |
346 | else |
344 | |
347 | pl->ns->update_look = 0; |
345 | pl->ns->update_look = 0; |
348 | |
346 | |
349 | if (QUERY_FLAG (ob, FLAG_REMOVED) |
347 | if (QUERY_FLAG (ob, FLAG_REMOVED) |
350 | || !ob->map |
348 | || !ob->map |
351 | || ob->map->in_memory != MAP_IN_MEMORY |
349 | || ob->map->in_memory != MAP_ACTIVE |
352 | || out_of_map (ob->map, ob->x, ob->y)) |
350 | || out_of_map (ob->map, ob->x, ob->y)) |
353 | return; |
351 | return; |
354 | |
352 | |
355 | pl->ns->send_packet ("delinv 0"); |
353 | pl->ns->send_packet ("delinv 0"); |
356 | |
354 | |
… | |
… | |
381 | } |
379 | } |
382 | |
380 | |
383 | object *tmp = ob->ms ().top; |
381 | object *tmp = ob->ms ().top; |
384 | for (object *last = 0; tmp != last; tmp = tmp->below) |
382 | for (object *last = 0; tmp != last; tmp = tmp->below) |
385 | { |
383 | { |
386 | object *head; |
|
|
387 | |
|
|
388 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last) |
384 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last) |
389 | { |
385 | { |
390 | last = tmp->below; /* assumes double floor mode */ |
386 | last = tmp->below; /* assumes double floor mode */ |
391 | if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) |
387 | if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) |
392 | last = last->below; |
388 | last = last->below; |
… | |
… | |
417 | sl << uint16 (0); |
413 | sl << uint16 (0); |
418 | |
414 | |
419 | break; |
415 | break; |
420 | } |
416 | } |
421 | |
417 | |
422 | if (tmp->head) |
|
|
423 | head = tmp->head; |
|
|
424 | else |
|
|
425 | head = tmp; |
|
|
426 | |
|
|
427 | add_object_to_socklist (*pl->ns, sl, head); |
418 | add_object_to_socklist (*pl->ns, sl, tmp->head_ ()); |
428 | got_one++; |
419 | got_one++; |
429 | |
420 | |
430 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
421 | if (sl.length () > MAXSOCKBUF - MAXITEMLEN) |
431 | { |
422 | { |
432 | pl->ns->send_packet (sl); |
423 | pl->ns->send_packet (sl); |
… | |
… | |
506 | */ |
497 | */ |
507 | void |
498 | void |
508 | esrv_update_item (int flags, object *pl, object *op) |
499 | esrv_update_item (int flags, object *pl, object *op) |
509 | { |
500 | { |
510 | /* If we have a request to send the player item, skip a few checks. */ |
501 | /* If we have a request to send the player item, skip a few checks. */ |
511 | if (op != pl) |
|
|
512 | { |
|
|
513 | if (!op->client_visible ()) |
502 | if (op != pl && !op->client_visible ()) |
514 | return; |
503 | return; |
515 | /* we remove the check for op->env, because in theory, the object |
|
|
516 | * is hopefully in the same place, so the client should preserve |
|
|
517 | * order. |
|
|
518 | */ |
|
|
519 | } |
|
|
520 | |
504 | |
521 | client *ns = pl->contr->ns; |
505 | client *ns = pl->contr->ns; |
522 | if (!ns) |
506 | if (!ns) |
523 | return; |
507 | return; |
524 | |
508 | |
… | |
… | |
533 | |
517 | |
534 | packet sl ("upditem"); |
518 | packet sl ("upditem"); |
535 | |
519 | |
536 | sl << uint8 (flags); |
520 | sl << uint8 (flags); |
537 | |
521 | |
538 | if (op->head) |
|
|
539 | op = op->head; |
522 | op = op->head_ (); |
540 | |
523 | |
541 | sl << uint32 (op->count); |
524 | sl << uint32 (op->count); |
542 | |
525 | |
543 | if (flags & UPD_LOCATION) |
526 | if (flags & UPD_LOCATION) |
544 | sl << uint32 (op->env ? op->env->count : 0); |
527 | sl << uint32 (op->env ? op->env->count : 0); |
… | |
… | |
546 | if (flags & UPD_FLAGS) |
529 | if (flags & UPD_FLAGS) |
547 | sl << uint32 (query_flags (op)); |
530 | sl << uint32 (query_flags (op)); |
548 | |
531 | |
549 | if (flags & UPD_WEIGHT) |
532 | if (flags & UPD_WEIGHT) |
550 | { |
533 | { |
551 | sint32 weight = WEIGHT (op); |
534 | sint32 weight = op->flag [FLAG_NO_PICK] ? -1 : op->client_weight (); |
552 | |
535 | |
553 | sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight); |
|
|
554 | |
|
|
555 | if (pl == op) |
536 | if (op) |
556 | ns->last_weight = weight; |
537 | ns->last_weight = weight; |
|
|
538 | |
|
|
539 | sl << uint32 (weight); |
557 | } |
540 | } |
558 | |
541 | |
559 | if (flags & UPD_FACE) |
542 | if (flags & UPD_FACE) |
560 | { |
543 | { |
561 | ns->send_face (op->face, -50); |
544 | ns->send_face (op->face, -50); |
… | |
… | |
632 | esrv_send_item (object *pl, object *op) |
615 | esrv_send_item (object *pl, object *op) |
633 | { |
616 | { |
634 | if (!pl->contr->ns) |
617 | if (!pl->contr->ns) |
635 | return; |
618 | return; |
636 | |
619 | |
637 | /* If this is not the player object, do some more checks */ |
|
|
638 | if (op != pl) |
|
|
639 | { |
|
|
640 | /* We only send 'visibile' objects to the client */ |
620 | /* We only send 'visible' objects to the client, and sometimes the player */ |
641 | if (!op->client_visible ()) |
621 | if (!op->client_visible () && op->type != PLAYER) |
642 | return; |
622 | return; |
643 | |
|
|
644 | /* if the item is on the ground, mark that the look needs to |
|
|
645 | * be updated. |
|
|
646 | */ |
|
|
647 | if (!op->env) |
|
|
648 | { |
|
|
649 | pl->contr->ns->floorbox_update (); |
|
|
650 | return; |
|
|
651 | } |
|
|
652 | } |
|
|
653 | |
623 | |
654 | packet sl; |
624 | packet sl; |
655 | |
625 | |
656 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
626 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
657 | |
627 | |
658 | if (op->head) |
|
|
659 | op = op->head; |
628 | op = op->head_ (); |
660 | |
629 | |
661 | sl << uint32 (op->env ? op->env->count : 0); |
630 | sl << uint32 (op->env ? op->env->count : 0); |
662 | |
631 | |
663 | add_object_to_socklist (*pl->contr->ns, sl, op); |
632 | add_object_to_socklist (*pl->contr->ns, sl, op); |
664 | |
633 | |
665 | pl->contr->ns->send_packet (sl); |
634 | pl->contr->ns->send_packet (sl); |
666 | SET_FLAG (op, FLAG_CLIENT_SENT); |
635 | SET_FLAG (op, FLAG_CLIENT_SENT); |
667 | } |
636 | } |
668 | |
637 | |
669 | /** |
638 | /** |
670 | * Tells the client to delete an item. Uses the item |
639 | * Tells the client to delete an item. |
671 | * command with a -1 location. |
|
|
672 | */ |
640 | */ |
673 | void |
641 | void |
674 | esrv_del_item (player *pl, int tag) |
642 | esrv_del_item (player *pl, int tag) |
675 | { |
643 | { |
676 | if (!pl->ns) |
644 | if (!pl->ns) |
… | |
… | |
800 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
768 | tag_t tag = net_uint32 ((uint8 *)data + 1); |
801 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
769 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
802 | |
770 | |
803 | if (!op) |
771 | if (!op) |
804 | { |
772 | { |
805 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); |
773 | pl->failmsg ("Could not find object to lock/unlock"); |
806 | return; |
774 | return; |
807 | } |
775 | } |
808 | |
776 | |
809 | if (!flag) |
777 | if (!flag) |
810 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
778 | CLEAR_FLAG (op, FLAG_INV_LOCKED); |
… | |
… | |
821 | tag_t tag = net_uint32 ((uint8 *)data); |
789 | tag_t tag = net_uint32 ((uint8 *)data); |
822 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
790 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
823 | |
791 | |
824 | if (!op) |
792 | if (!op) |
825 | { |
793 | { |
826 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); |
794 | pl->failmsg ("Could not find object to mark"); |
827 | return; |
795 | return; |
828 | } |
796 | } |
829 | |
797 | |
830 | pl->mark = op; |
798 | pl->mark = op; |
831 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "Marked item %s", query_name (op)); |
799 | pl->ob->statusmsg (format ("Marked item %s", query_name (op))); |
832 | } |
800 | } |
833 | |
801 | |
834 | /** |
802 | /** |
835 | * look_at prints items on the specified square. |
803 | * look_at prints items on the specified square. |
836 | * |
804 | * |
… | |
… | |
838 | * Tero.Haatanen@lut.fi ] |
806 | * Tero.Haatanen@lut.fi ] |
839 | */ |
807 | */ |
840 | static void |
808 | static void |
841 | look_at (player *pl, int dx, int dy) |
809 | look_at (player *pl, int dx, int dy) |
842 | { |
810 | { |
|
|
811 | dynbuf_text buf; |
843 | object *ob = pl->ob; |
812 | object *ob = pl->ob; |
844 | |
813 | |
845 | maptile *m = pl->observe->map; |
814 | if (!pl->observe->map) |
846 | sint16 x = pl->observe->x + dx; |
|
|
847 | sint16 y = pl->observe->y + dy; |
|
|
848 | |
|
|
849 | if (!m) |
|
|
850 | return; |
|
|
851 | |
|
|
852 | if (!xy_normalise (m, x, y)) |
|
|
853 | { |
|
|
854 | new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing there."); |
|
|
855 | return; |
815 | return; |
856 | } |
|
|
857 | |
816 | |
858 | int flag = 0; |
817 | mapxy pos (pl->observe); |
|
|
818 | pos.move (dx, dy); |
859 | |
819 | |
|
|
820 | if (pos.normalise ()) |
860 | for (object *tmp = m->at (x, y).top; tmp; tmp = tmp->below) |
821 | for (object *tmp = pos->top; tmp; tmp = tmp->below) |
861 | { |
822 | { |
862 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
823 | if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) |
863 | continue; |
824 | continue; |
864 | |
825 | |
865 | if (!flag) |
|
|
866 | { |
|
|
867 | if (dx || dy) |
|
|
868 | new_draw_info (NDI_UNIQUE, 0, ob, "There you see:"); |
|
|
869 | else |
|
|
870 | new_draw_info (NDI_UNIQUE, 0, ob, "You see:"); |
|
|
871 | |
|
|
872 | flag = 1; |
|
|
873 | } |
|
|
874 | |
|
|
875 | if (QUERY_FLAG (ob, FLAG_WIZ)) |
826 | if (QUERY_FLAG (ob, FLAG_WIZ)) |
876 | new_draw_info_format (NDI_UNIQUE, 0, ob, "- %s (%d).", query_name (tmp), tmp->count); |
827 | buf.printf ("- %s (%d).\n", query_name (tmp), tmp->count); |
877 | else |
828 | else |
878 | new_draw_info_format (NDI_UNIQUE, 0, ob, "- %s.", query_name (tmp)); |
829 | buf.printf ("- %s.\n", query_name (tmp)); |
879 | |
830 | |
880 | if (((tmp->inv != NULL || (tmp->head && tmp->head->inv)) && |
831 | object *head = tmp->head_ (); |
881 | (tmp->type != CONTAINER && tmp->type != FLESH)) || QUERY_FLAG (ob, FLAG_WIZ)) |
|
|
882 | inventory (ob, tmp->head == NULL ? tmp : tmp->head); |
|
|
883 | |
832 | |
|
|
833 | if (head->inv) |
|
|
834 | if ((head->type != CONTAINER && head->type != FLESH) |
|
|
835 | || QUERY_FLAG (ob, FLAG_WIZ)) |
|
|
836 | buf << head->query_inventory (ob, " "); |
|
|
837 | |
884 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ob, FLAG_WIZ)) /* don't continue under the floor */ |
838 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !QUERY_FLAG (ob, FLAG_WIZ)) /* don't continue under the floor */ |
885 | break; |
839 | break; |
886 | } |
840 | } |
887 | |
841 | |
888 | if (!flag) |
842 | if (buf.empty ()) |
889 | { |
843 | pl->failmsg ("You see nothing there."); |
890 | if (dx || dy) |
|
|
891 | new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing there."); |
|
|
892 | else |
844 | else |
893 | new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing."); |
845 | pl->infobox (MSG_CHANNEL ("lookat"), buf); |
894 | } |
|
|
895 | } |
846 | } |
896 | |
847 | |
897 | /** Client wants to look at some object. Lets do so. */ |
848 | /** Client wants to look at some object. Lets do so. */ |
898 | void |
849 | void |
899 | LookAt (char *buf, int len, player *pl) |
850 | LookAt (char *buf, int len, player *pl) |
… | |
… | |
940 | /* If it is an active container, then we should drop all objects |
891 | /* If it is an active container, then we should drop all objects |
941 | * in the container and not the container itself. |
892 | * in the container and not the container itself. |
942 | */ |
893 | */ |
943 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
894 | if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) |
944 | { |
895 | { |
945 | object *current, *next; |
896 | int cnt = MAX_ITEM_PER_DROP; |
946 | |
897 | |
947 | for (current = op->inv; current != NULL; current = next) |
898 | for (object *current = op->inv; current; ) |
948 | { |
899 | { |
949 | next = current->below; |
900 | object *next = current->below; |
|
|
901 | |
950 | drop_object (pl, current, 0); |
902 | drop_object (pl, current, 0); |
|
|
903 | |
|
|
904 | if (--cnt <= 0) break; |
|
|
905 | |
|
|
906 | current = next; |
951 | } |
907 | } |
952 | |
908 | |
953 | esrv_update_item (UPD_WEIGHT, pl, op); |
909 | if (cnt <= 0) |
|
|
910 | op->failmsg ("Only dropped some items, can't drop that many items at once."); |
954 | } |
911 | } |
955 | else |
912 | else |
956 | drop_object (pl, op, nrof); |
913 | drop_object (pl, op, nrof); |
957 | |
914 | |
958 | return; |
915 | return; |
… | |
… | |
978 | /* put_object_in_sack presumes that necessary sanity checking |
935 | /* put_object_in_sack presumes that necessary sanity checking |
979 | * has already been done (eg, it can be picked up and fits in |
936 | * has already been done (eg, it can be picked up and fits in |
980 | * in a sack, so check for those things. We should also check |
937 | * in a sack, so check for those things. We should also check |
981 | * an make sure env is in fact a container for that matter. |
938 | * an make sure env is in fact a container for that matter. |
982 | */ |
939 | */ |
983 | if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) |
940 | if (env->type == CONTAINER |
|
|
941 | && can_pick (pl, op) |
|
|
942 | && sack_can_hold (pl, env, op, nrof)) |
984 | put_object_in_sack (pl, env, op, nrof); |
943 | put_object_in_sack (pl, env, op, nrof); |
985 | } |
944 | } |
986 | |
945 | |