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.49 by root, Fri Jun 8 09:20:20 2007 UTC vs.
Revision 1.63 by root, Thu Apr 24 00:30:52 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 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 it 8 * Deliantra is free software: you can redistribute it and/or modify
9 * under the terms of the GNU General Public License as published by the Free 9 * it under the terms of the GNU General Public License as published by
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * the Free Software Foundation, either version 3 of the License, or
11 * 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, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * 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 along 18 * You should have received a copy of the GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * 20 *
22 * 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>
23 */ 22 */
24 23
25/** 24/**
26 * \file 25 * \file
27 * Client/server logic. 26 * Client/server logic.
194query_flags (object *op) 193query_flags (object *op)
195{ 194{
196 unsigned int flags = 0; 195 unsigned int flags = 0;
197 196
198 if (QUERY_FLAG (op, FLAG_APPLIED)) 197 if (QUERY_FLAG (op, FLAG_APPLIED))
199 {
200 switch (op->type) 198 switch (op->type)
201 { 199 {
202 case BOW: 200 case BOW:
203 case WAND: 201 case WAND:
204 case ROD: 202 case ROD:
205 case HORN: 203 case HORN:
206 flags = a_readied; 204 flags = a_readied;
207 break; 205 break;
208 case WEAPON: 206 case WEAPON:
209 flags = a_wielded; 207 flags = a_wielded;
210 break; 208 break;
211 case SKILL: 209 case SKILL:
212 case ARMOUR: 210 case ARMOUR:
213 case HELMET: 211 case HELMET:
214 case SHIELD: 212 case SHIELD:
215 case RING: 213 case RING:
216 case BOOTS: 214 case BOOTS:
217 case GLOVES: 215 case GLOVES:
218 case AMULET: 216 case AMULET:
219 case GIRDLE: 217 case GIRDLE:
220 case BRACERS: 218 case BRACERS:
221 case CLOAK: 219 case CLOAK:
222 flags = a_worn; 220 flags = a_worn;
223 break; 221 break;
224 case CONTAINER: 222 case CONTAINER:
225 flags = a_active; 223 flags = a_active;
226 break; 224 break;
227 default: 225 default:
228 flags = a_applied; 226 flags = a_applied;
229 break; 227 break;
230 } 228 }
231 }
232 229
233 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))))
234 flags |= F_OPEN; 231 flags |= F_OPEN;
235 232
236 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) 233 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
264 261
265 flags = query_flags (head); 262 flags = query_flags (head);
266 if (QUERY_FLAG (head, FLAG_NO_PICK)) 263 if (QUERY_FLAG (head, FLAG_NO_PICK))
267 flags |= F_NOPICK; 264 flags |= F_NOPICK;
268 265
269 ns.send_face (head->face); 266 ns.send_face (head->face, -50);
270 ns.flush_fx (); 267 ns.flush_fx ();
271 268
272 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])
273 ns.send_animation (head->animation_id); 270 ns.send_animation (head->animation_id);
274 271
275 sl << uint32 (head->count) 272 sl << uint32 (head->count)
276 << uint32 (flags) 273 << uint32 (flags)
277 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : WEIGHT (head)) 274 << uint32 (QUERY_FLAG (head, FLAG_NO_PICK) ? -1 : head->client_weight ())
278 << uint32 (head->face); 275 << uint32 (head->face);
279 276
280 if (!head->custom_name) 277 if (!head->custom_name)
281 { 278 {
282 strncpy (item_n, query_base_name (head, 0), 127); 279 strncpy (item_n, query_base_name (head, 0), 127);
342 if (!pl->ns->update_look) 339 if (!pl->ns->update_look)
343 { 340 {
344 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);
345 return; 342 return;
346 } 343 }
347 else 344
348 pl->ns->update_look = 0; 345 pl->ns->update_look = 0;
349 346
350 if (QUERY_FLAG (ob, FLAG_REMOVED) 347 if (QUERY_FLAG (ob, FLAG_REMOVED)
351 || !ob->map 348 || !ob->map
352 || ob->map->in_memory != MAP_IN_MEMORY 349 || ob->map->in_memory != MAP_ACTIVE
353 || out_of_map (ob->map, ob->x, ob->y)) 350 || out_of_map (ob->map, ob->x, ob->y))
354 return; 351 return;
355 352
356 pl->ns->send_packet ("delinv 0"); 353 pl->ns->send_packet ("delinv 0");
357 354
358 packet sl; 355 packet sl;
359 sl.printf ("item%d ", pl->ns->itemcmd); 356 sl.printf ("item%d ", pl->ns->itemcmd);
360 357
361 sl << uint32 (0); 358 sl << uint32 (0);
362 359
363 pl->ns->send_face (empty_face); 360 pl->ns->send_face (empty_face, -50);
364 pl->ns->flush_fx (); 361 pl->ns->flush_fx ();
365 362
366 if (pl->ns->look_position) 363 if (pl->ns->look_position)
367 { 364 {
368 char buf[80]; 365 char buf[80];
382 } 379 }
383 380
384 object *tmp = ob->ms ().top; 381 object *tmp = ob->ms ().top;
385 for (object *last = 0; tmp != last; tmp = tmp->below) 382 for (object *last = 0; tmp != last; tmp = tmp->below)
386 { 383 {
387 object *head;
388
389 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last) 384 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) && !last)
390 { 385 {
391 last = tmp->below; /* assumes double floor mode */ 386 last = tmp->below; /* assumes double floor mode */
392 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR)) 387 if (last && QUERY_FLAG (last, FLAG_IS_FLOOR))
393 last = last->below; 388 last = last->below;
418 sl << uint16 (0); 413 sl << uint16 (0);
419 414
420 break; 415 break;
421 } 416 }
422 417
423 if (tmp->head)
424 head = tmp->head;
425 else
426 head = tmp;
427
428 add_object_to_socklist (*pl->ns, sl, head); 418 add_object_to_socklist (*pl->ns, sl, tmp->head_ ());
429 got_one++; 419 got_one++;
430 420
431 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) 421 if (sl.length () > MAXSOCKBUF - MAXITEMLEN)
432 { 422 {
433 pl->ns->send_packet (sl); 423 pl->ns->send_packet (sl);
434 424
435 sl.reset (); 425 sl.reset ();
436 sl.printf ("item%d ", pl->ns->itemcmd); 426 sl.printf ("item%d ", pl->ns->itemcmd);
480 470
481 /* IT is possible for players to accumulate a huge amount of 471 /* IT is possible for players to accumulate a huge amount of
482 * items (especially with some of the bags out there) to 472 * items (especially with some of the bags out there) to
483 * overflow the buffer. IF so, send multiple item commands. 473 * overflow the buffer. IF so, send multiple item commands.
484 */ 474 */
485 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) 475 if (sl.length () > MAXSOCKBUF - MAXITEMLEN)
486 { 476 {
487 pl->contr->ns->send_packet (sl); 477 pl->contr->ns->send_packet (sl);
488 478
489 sl.reset (); 479 sl.reset ();
490 sl.printf ("item%d ", pl->contr->ns->itemcmd); 480 sl.printf ("item%d ", pl->contr->ns->itemcmd);
507 */ 497 */
508void 498void
509esrv_update_item (int flags, object *pl, object *op) 499esrv_update_item (int flags, object *pl, object *op)
510{ 500{
511 /* 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. */
512 if (op != pl)
513 {
514 if (!op->client_visible ()) 502 if (op != pl && !op->client_visible ())
515 return; 503 return;
516 /* we remove the check for op->env, because in theory, the object
517 * is hopefully in the same place, so the client should preserve
518 * order.
519 */
520 }
521 504
522 client *ns = pl->contr->ns; 505 client *ns = pl->contr->ns;
523 if (!ns) 506 if (!ns)
524 return; 507 return;
525 508
534 517
535 packet sl ("upditem"); 518 packet sl ("upditem");
536 519
537 sl << uint8 (flags); 520 sl << uint8 (flags);
538 521
539 if (op->head)
540 op = op->head; 522 op = op->head_ ();
541 523
542 sl << uint32 (op->count); 524 sl << uint32 (op->count);
543 525
544 if (flags & UPD_LOCATION) 526 if (flags & UPD_LOCATION)
545 sl << uint32 (op->env ? op->env->count : 0); 527 sl << uint32 (op->env ? op->env->count : 0);
547 if (flags & UPD_FLAGS) 529 if (flags & UPD_FLAGS)
548 sl << uint32 (query_flags (op)); 530 sl << uint32 (query_flags (op));
549 531
550 if (flags & UPD_WEIGHT) 532 if (flags & UPD_WEIGHT)
551 { 533 {
552 sint32 weight = WEIGHT (op); 534 sint32 weight = op->flag [FLAG_NO_PICK] ? -1 : op->client_weight ();
553 535
554 sl << uint32 (QUERY_FLAG (op, FLAG_NO_PICK) ? -1 : weight);
555
556 if (pl == op) 536 if (op)
557 ns->last_weight = weight; 537 ns->last_weight = weight;
538
539 sl << uint32 (weight);
558 } 540 }
559 541
560 if (flags & UPD_FACE) 542 if (flags & UPD_FACE)
561 { 543 {
562 ns->send_face (op->face); 544 ns->send_face (op->face, -50);
563 ns->flush_fx (); 545 ns->flush_fx ();
564 sl << uint32 (op->face); 546 sl << uint32 (op->face);
565 } 547 }
566 548
567 if (flags & UPD_NAME) 549 if (flags & UPD_NAME)
633esrv_send_item (object *pl, object *op) 615esrv_send_item (object *pl, object *op)
634{ 616{
635 if (!pl->contr->ns) 617 if (!pl->contr->ns)
636 return; 618 return;
637 619
638 /* If this is not the player object, do some more checks */
639 if (op != pl)
640 {
641 /* We only send 'visibile' objects to the client */ 620 /* We only send 'visible' objects to the client, and sometimes the player */
642 if (!op->client_visible ()) 621 if (!op->client_visible () && op->type != PLAYER)
643 return; 622 return;
644
645 /* if the item is on the ground, mark that the look needs to
646 * be updated.
647 */
648 if (!op->env)
649 {
650 pl->contr->ns->floorbox_update ();
651 return;
652 }
653 }
654 623
655 packet sl; 624 packet sl;
656 625
657 sl.printf ("item%d ", pl->contr->ns->itemcmd); 626 sl.printf ("item%d ", pl->contr->ns->itemcmd);
658 627
659 if (op->head)
660 op = op->head; 628 op = op->head_ ();
661 629
662 sl << uint32 (op->env ? op->env->count : 0); 630 sl << uint32 (op->env ? op->env->count : 0);
663 631
664 add_object_to_socklist (*pl->contr->ns, sl, op); 632 add_object_to_socklist (*pl->contr->ns, sl, op);
665 633
666 pl->contr->ns->send_packet (sl); 634 pl->contr->ns->send_packet (sl);
667 SET_FLAG (op, FLAG_CLIENT_SENT); 635 SET_FLAG (op, FLAG_CLIENT_SENT);
668} 636}
669 637
670/** 638/**
671 * Tells the client to delete an item. Uses the item 639 * Tells the client to delete an item.
672 * command with a -1 location.
673 */ 640 */
674void 641void
675esrv_del_item (player *pl, int tag) 642esrv_del_item (player *pl, int tag)
676{ 643{
677 if (!pl->ns) 644 if (!pl->ns)
801 tag_t tag = net_uint32 ((uint8 *)data + 1); 768 tag_t tag = net_uint32 ((uint8 *)data + 1);
802 object *op = esrv_get_ob_from_count (pl->ob, tag); 769 object *op = esrv_get_ob_from_count (pl->ob, tag);
803 770
804 if (!op) 771 if (!op)
805 { 772 {
806 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");
807 return; 774 return;
808 } 775 }
809 776
810 if (!flag) 777 if (!flag)
811 CLEAR_FLAG (op, FLAG_INV_LOCKED); 778 CLEAR_FLAG (op, FLAG_INV_LOCKED);
822 tag_t tag = net_uint32 ((uint8 *)data); 789 tag_t tag = net_uint32 ((uint8 *)data);
823 object *op = esrv_get_ob_from_count (pl->ob, tag); 790 object *op = esrv_get_ob_from_count (pl->ob, tag);
824 791
825 if (!op) 792 if (!op)
826 { 793 {
827 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 794 pl->failmsg ("Could not find object to mark");
828 return; 795 return;
829 } 796 }
830 797
831 pl->mark = op; 798 pl->mark = op;
832 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)));
833} 800}
834 801
835/** 802/**
836 * look_at prints items on the specified square. 803 * look_at prints items on the specified square.
837 * 804 *
839 * Tero.Haatanen@lut.fi ] 806 * Tero.Haatanen@lut.fi ]
840 */ 807 */
841static void 808static void
842look_at (player *pl, int dx, int dy) 809look_at (player *pl, int dx, int dy)
843{ 810{
811 dynbuf_text buf;
844 object *ob = pl->ob; 812 object *ob = pl->ob;
845 813
846 maptile *m = pl->observe->map; 814 if (!pl->observe->map)
847 sint16 x = pl->observe->x + dx;
848 sint16 y = pl->observe->y + dy;
849
850 if (!m)
851 return;
852
853 if (!xy_normalise (m, x, y))
854 {
855 new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing there.");
856 return; 815 return;
857 }
858 816
859 int flag = 0; 817 mapxy pos (pl->observe);
818 pos.move (dx, dy);
860 819
820 if (pos.normalise ())
861 for (object *tmp = m->at (x, y).top; tmp; tmp = tmp->below) 821 for (object *tmp = pos->top; tmp; tmp = tmp->below)
862 { 822 {
863 if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ)) 823 if (tmp->invisible && !QUERY_FLAG (ob, FLAG_WIZ))
864 continue; 824 continue;
865 825
866 if (!flag)
867 {
868 if (dx || dy)
869 new_draw_info (NDI_UNIQUE, 0, ob, "There you see:");
870 else
871 new_draw_info (NDI_UNIQUE, 0, ob, "You see:");
872
873 flag = 1;
874 }
875
876 if (QUERY_FLAG (ob, FLAG_WIZ)) 826 if (QUERY_FLAG (ob, FLAG_WIZ))
877 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);
878 else 828 else
879 new_draw_info_format (NDI_UNIQUE, 0, ob, "- %s.", query_name (tmp)); 829 buf.printf ("- %s.\n", query_name (tmp));
880 830
881 if (((tmp->inv != NULL || (tmp->head && tmp->head->inv)) && 831 object *head = tmp->head_ ();
882 (tmp->type != CONTAINER && tmp->type != FLESH)) || QUERY_FLAG (ob, FLAG_WIZ))
883 inventory (ob, tmp->head == NULL ? tmp : tmp->head);
884 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
885 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 */
886 break; 839 break;
887 } 840 }
888 841
889 if (!flag) 842 if (buf.empty ())
890 { 843 pl->failmsg ("You see nothing there.");
891 if (dx || dy)
892 new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing there.");
893 else 844 else
894 new_draw_info (NDI_UNIQUE, 0, ob, "You see nothing."); 845 pl->infobox (MSG_CHANNEL ("lookat"), buf);
895 }
896} 846}
897 847
898/** Client wants to look at some object. Lets do so. */ 848/** Client wants to look at some object. Lets do so. */
899void 849void
900LookAt (char *buf, int len, player *pl) 850LookAt (char *buf, int len, player *pl)
941 /* 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
942 * in the container and not the container itself. 892 * in the container and not the container itself.
943 */ 893 */
944 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED)) 894 if (op->inv && QUERY_FLAG (op, FLAG_APPLIED))
945 { 895 {
946 object *current, *next; 896 int cnt = MAX_ITEM_PER_DROP;
947 897
948 for (current = op->inv; current != NULL; current = next) 898 for (object *current = op->inv; current; )
949 { 899 {
950 next = current->below; 900 object *next = current->below;
901
951 drop_object (pl, current, 0); 902 drop_object (pl, current, 0);
903
904 if (--cnt <= 0) break;
905
906 current = next;
952 } 907 }
953 908
954 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.");
955 } 911 }
956 else 912 else
957 drop_object (pl, op, nrof); 913 drop_object (pl, op, nrof);
958 914
959 return; 915 return;
979 /* put_object_in_sack presumes that necessary sanity checking 935 /* put_object_in_sack presumes that necessary sanity checking
980 * 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
981 * 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
982 * 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.
983 */ 939 */
984 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))
985 put_object_in_sack (pl, env, op, nrof); 943 put_object_in_sack (pl, env, op, nrof);
986} 944}
987 945

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines