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.16 by root, Thu Dec 14 01:21:58 2006 UTC vs.
Revision 1.24 by root, Sat Dec 16 22:14:42 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 (NewSocket &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;
202 char buf[MAX_BUF]; 200 char buf[MAX_BUF];
203 201
204 if (!pl->contr->socket.update_look) 202 if (!pl->contr->socket->update_look)
205 { 203 {
206 LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); 204 LOG (llevDebug, "esrv_draw_look called when update_look was not set\n");
207 return; 205 return;
208 } 206 }
209 else 207 else
210 pl->contr->socket.update_look = 0; 208 pl->contr->socket->update_look = 0;
211 209
212 if (QUERY_FLAG (pl, FLAG_REMOVED) 210 if (QUERY_FLAG (pl, FLAG_REMOVED)
213 || !pl->map 211 || !pl->map
214 || pl->map->in_memory != MAP_IN_MEMORY 212 || pl->map->in_memory != MAP_IN_MEMORY
215 || out_of_map (pl->map, pl->x, pl->y)) 213 || out_of_map (pl->map, pl->x, pl->y))
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
221 packet sl; 219 packet sl;
222 220
223 pl->contr->socket.send_packet ("delinv 0"); 221 pl->contr->socket->send_packet ("delinv 0");
224 222
225 sl.printf ("item%d ", pl->contr->socket.itemcmd); 223 sl.printf ("item%d ", pl->contr->socket->itemcmd);
226 224
227 sl << uint32 (0); 225 sl << uint32 (0);
228 226
229 if (!(pl->contr->socket.faces_sent[empty_face->number] & NS_FACESENT_FACE)) 227 if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE))
230 esrv_send_face (&pl->contr->socket, empty_face->number, 0); 228 esrv_send_face (pl->contr->socket, empty_face->number, 0);
231 229
232 if (pl->contr->socket.look_position) 230 if (pl->contr->socket->look_position)
233 { 231 {
232 char buf[80];
233 snprintf (buf, 80, "Apply this to see %d previous items", NUM_LOOK_OBJECTS);
234
234 sl << uint32 (0x80000000 | (pl->contr->socket.look_position - NUM_LOOK_OBJECTS)) 235 sl << uint32 (0x80000000 | (pl->contr->socket->look_position - NUM_LOOK_OBJECTS))
235 << uint32 (0) 236 << uint32 (0)
236 << sint32 (-1) 237 << sint32 (-1)
237 << uint32 (empty_face->number); 238 << uint32 (empty_face->number)
238 239 << data8 (buf)
239 sl.printf ("Click here to see %d previous items", NUM_LOOK_OBJECTS);
240
241 sl << uint16 (0) 240 << uint16 (0)
242 << uint8 (0) 241 << uint8 (0)
243 << uint32 (0); 242 << uint32 (0);
244 243
245 if (pl->contr->socket.itemcmd == 2) 244 if (pl->contr->socket->itemcmd == 2)
246 sl << uint16 (0); 245 sl << uint16 (0);
247 } 246 }
248 247
249 for (last = NULL; tmp != last; tmp = tmp->below) 248 for (last = NULL; tmp != last; tmp = tmp->below)
250 { 249 {
257 last = last->below; 256 last = last->below;
258 } 257 }
259 258
260 if (LOOK_OBJ (tmp)) 259 if (LOOK_OBJ (tmp))
261 { 260 {
262 if (++start_look < pl->contr->socket.look_position) 261 if (++start_look < pl->contr->socket->look_position)
263 continue; 262 continue;
264 263
265 end_look++; 264 end_look++;
266 265
267 if (end_look > NUM_LOOK_OBJECTS) 266 if (end_look > NUM_LOOK_OBJECTS)
268 { 267 {
269 /* What we basically do is make a 'fake' object - when the user applies it, 268 /* What we basically do is make a 'fake' object - when the user applies it,
270 * we notice the special tag the object has, and act accordingly. 269 * we notice the special tag the object has, and act accordingly.
271 */ 270 */
272 sl << uint32 (0x80000000 | (pl->contr->socket.look_position + NUM_LOOK_OBJECTS)) 271 sl << uint32 (0x80000000 | (pl->contr->socket->look_position + NUM_LOOK_OBJECTS))
273 << uint32 (0) 272 << uint32 (0)
274 << uint32 ((uint32) - 1) 273 << uint32 ((uint32) - 1)
275 << uint32 (empty_face->number); 274 << uint32 (empty_face->number)
276 275 << data8 ("Apply this to see next group of items")
277 sl.printf ("Click here to see next group of items");
278
279 sl << uint16 (0) 276 << uint16 (0)
280 << uint8 (0) 277 << uint8 (0)
281 << uint32 (0); 278 << uint32 (0);
282 279
283 if (pl->contr->socket.itemcmd == 2) 280 if (pl->contr->socket->itemcmd == 2)
284 sl << uint16 (0); 281 sl << uint16 (0);
285 282
286 break; 283 break;
287 } 284 }
288 285
289 if (tmp->head) 286 if (tmp->head)
290 head = tmp->head; 287 head = tmp->head;
291 else 288 else
292 head = tmp; 289 head = tmp;
293 290
294 add_object_to_socklist (pl->contr->socket, sl, head); 291 add_object_to_socklist (*pl->contr->socket, sl, head);
295 got_one++; 292 got_one++;
296 293
297 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) 294 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN))
298 { 295 {
299 Send_With_Handling (&pl->contr->socket, &sl); 296 pl->contr->socket->send_packet (sl);
300 297
301 sl.reset (); 298 sl.reset ();
302 sl.printf ("item%d ", pl->contr->socket.itemcmd); 299 sl.printf ("item%d ", pl->contr->socket->itemcmd);
303 sl << uint32 (0); 300 sl << uint32 (0);
304 got_one = 0; 301 got_one = 0;
305 } 302 }
306 } /* If LOOK_OBJ() */ 303 }
307 } 304 }
308 305
309 if (got_one) 306 if (got_one)
310 Send_With_Handling (&pl->contr->socket, &sl); 307 pl->contr->socket->send_packet (sl);
311 308
312} 309}
313 310
314/** 311/**
315 * Sends whole inventory. 312 * Sends whole inventory.
321 int got_one = 0; 318 int got_one = 0;
322 319
323 packet sl; 320 packet sl;
324 321
325 sl.printf ("delinv %d", op->count); 322 sl.printf ("delinv %d", op->count);
326 Send_With_Handling (&pl->contr->socket, &sl); 323 pl->contr->socket->send_packet (sl);
327 324
328 sl.reset (); 325 sl.reset ();
329 sl.printf ("item%d ", pl->contr->socket.itemcmd); 326 sl.printf ("item%d ", pl->contr->socket->itemcmd);
330 327
331 sl << uint32 (op->count); 328 sl << uint32 (op->count);
332 329
333 for (tmp = op->inv; tmp; tmp = tmp->below) 330 for (tmp = op->inv; tmp; tmp = tmp->below)
334 { 331 {
339 else 336 else
340 head = tmp; 337 head = tmp;
341 338
342 if (LOOK_OBJ (head)) 339 if (LOOK_OBJ (head))
343 { 340 {
344 add_object_to_socklist (pl->contr->socket, sl, head); 341 add_object_to_socklist (*pl->contr->socket, sl, head);
345 342
346 got_one++; 343 got_one++;
347 344
348 /* IT is possible for players to accumulate a huge amount of 345 /* IT is possible for players to accumulate a huge amount of
349 * items (especially with some of the bags out there) to 346 * items (especially with some of the bags out there) to
350 * overflow the buffer. IF so, send multiple item commands. 347 * overflow the buffer. IF so, send multiple item commands.
351 */ 348 */
352 if (sl.len >= (MAXSOCKBUF - MAXITEMLEN)) 349 if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN))
353 { 350 {
354 Send_With_Handling (&pl->contr->socket, &sl); 351 pl->contr->socket->send_packet (sl);
352
353 sl.reset ();
355 sprintf ((char *) sl.buf, "item%d ", pl->contr->socket.itemcmd); 354 sl.printf ("item%d ", pl->contr->socket->itemcmd);
356 sl.len = strlen ((char *) sl.buf);
357 sl << uint32 (op->count); 355 sl << uint32 (op->count);
358 got_one = 0; 356 got_one = 0;
359 } 357 }
360 } /* If LOOK_OBJ() */ 358 } /* If LOOK_OBJ() */
361 } 359 }
362 360
363 if (got_one) 361 if (got_one)
364 Send_With_Handling (&pl->contr->socket, &sl); 362 pl->contr->socket->send_packet (sl);
365
366} 363}
367 364
368/** 365/**
369 * Updates object *op for player *pl. 366 * Updates object *op for player *pl.
370 * 367 *
422 op->contr->last_weight = weight; 419 op->contr->last_weight = weight;
423 } 420 }
424 421
425 if (flags & UPD_FACE) 422 if (flags & UPD_FACE)
426 { 423 {
427 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) 424 if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE))
428 esrv_send_face (&pl->contr->socket, op->face->number, 0); 425 esrv_send_face (pl->contr->socket, op->face->number, 0);
429 426
430 sl << uint32 (op->face->number); 427 sl << uint32 (op->face->number);
431 } 428 }
432 429
433 if (flags & UPD_NAME) 430 if (flags & UPD_NAME)
487 } 484 }
488 485
489 if (flags & UPD_NROF) 486 if (flags & UPD_NROF)
490 sl << uint32 (op->nrof); 487 sl << uint32 (op->nrof);
491 488
492 Send_With_Handling (&pl->contr->socket, &sl); 489 pl->contr->socket->send_packet (sl);
493} 490}
494 491
495/** 492/**
496 * Sends item's info to player. 493 * Sends item's info to player.
497 */ 494 */
507 /* if the item is on the ground, mark that the look needs to 504 /* if the item is on the ground, mark that the look needs to
508 * be updated. 505 * be updated.
509 */ 506 */
510 if (!op->env) 507 if (!op->env)
511 { 508 {
512 pl->contr->socket.update_look = 1; 509 pl->contr->socket->update_look = 1;
513 return; 510 return;
514 } 511 }
515 } 512 }
516 513
517 packet sl; 514 packet sl;
518 515
519 sl.printf ("item%d ", pl->contr->socket.itemcmd); 516 sl.printf ("item%d ", pl->contr->socket->itemcmd);
520 517
521 if (op->head) 518 if (op->head)
522 op = op->head; 519 op = op->head;
523 520
524 sl << uint32 (op->env ? op->env->count : 0); 521 sl << uint32 (op->env ? op->env->count : 0);
525 522
526 add_object_to_socklist (pl->contr->socket, sl, op); 523 add_object_to_socklist (*pl->contr->socket, sl, op);
527 524
528 Send_With_Handling (&pl->contr->socket, &sl); 525 pl->contr->socket->send_packet (sl);
529 SET_FLAG (op, FLAG_CLIENT_SENT); 526 SET_FLAG (op, FLAG_CLIENT_SENT);
530
531} 527}
532 528
533/** 529/**
534 * Tells the client to delete an item. Uses the item 530 * Tells the client to delete an item. Uses the item
535 * command with a -1 location. 531 * command with a -1 location.
541 packet sl; 537 packet sl;
542 538
543 sl << "delitem " 539 sl << "delitem "
544 << uint32 (tag); 540 << uint32 (tag);
545 541
546 Send_With_Handling (&pl->socket, &sl); 542 pl->socket->send_packet (sl);
547} 543}
548 544
549 545
550/******************************************************************************* 546/*******************************************************************************
551 * 547 *
573 for (tmp = op->inv; tmp; tmp = tmp->below) 569 for (tmp = op->inv; tmp; tmp = tmp->below)
574 if (tmp->count == count) 570 if (tmp->count == count)
575 return tmp; 571 return tmp;
576 572
577 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above) 573 for (op = get_map_ob (pl->map, pl->x, pl->y); op; op = op->above)
578 if (op->head != NULL && op->head->count == count) 574 if (op->head && op->head->count == count)
579 return op; 575 return op;
580 else if (op->count == count) 576 else if (op->count == count)
581 return op; 577 return op;
582 else if (op->type == CONTAINER && pl->container == op) 578 else if (op->type == CONTAINER && pl->container == op)
583 for (tmp = op->inv; tmp; tmp = tmp->below) 579 for (tmp = op->inv; tmp; tmp = tmp->below)
584 if (tmp->count == count) 580 if (tmp->count == count)
585 return tmp; 581 return tmp;
586 582
587 return NULL; 583 return 0;
588} 584}
589 585
590 586
591/** Client wants to examine some object. So lets do so. */ 587/** Client wants to examine some object. So lets do so. */
592void 588void
607 } 603 }
608 604
609 examine (pl->ob, op); 605 examine (pl->ob, op);
610} 606}
611 607
612/** Client wants to apply some object. Lets do so. */ 608/** Client wants to apply some object. Lets do so. */
613void 609void
614ApplyCmd (char *buf, int len, player *pl) 610ApplyCmd (char *buf, int len, player *pl)
615{ 611{
616 tag_t tag = atoi (buf); 612 tag_t tag = atoi (buf);
617 613
622 return; 618 return;
623 619
624 /* If the high bit is set, player applied a pseudo object. */ 620 /* If the high bit is set, player applied a pseudo object. */
625 if (tag & 0x80000000) 621 if (tag & 0x80000000)
626 { 622 {
627 pl->socket.look_position = tag & 0x7fffffff; 623 pl->socket->look_position = tag & 0x7fffffff;
628 pl->socket.update_look = 1; 624 pl->socket->update_look = 1;
629 return; 625 return;
630 } 626 }
631 627
632 object *op = esrv_get_ob_from_count (pl->ob, tag); 628 object *op = esrv_get_ob_from_count (pl->ob, tag);
633 629
640 player_apply (pl->ob, op, 0, 0); 636 player_apply (pl->ob, op, 0, 0);
641} 637}
642 638
643/** Client wants to apply some object. Lets do so. */ 639/** Client wants to apply some object. Lets do so. */
644void 640void
645LockItem (uint8 *data, int len, player *pl) 641LockItem (char *data, int len, player *pl)
646{ 642{
647 int flag = data[0]; 643 int flag = data[0];
648 tag_t tag = net_uint32 (data + 1); 644 tag_t tag = net_uint32 ((uint8 *)data + 1);
649 object *op = esrv_get_ob_from_count (pl->ob, tag); 645 object *op = esrv_get_ob_from_count (pl->ob, tag);
650 646
651 if (!op) 647 if (!op)
652 { 648 {
653 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); 649 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock");
662 esrv_update_item (UPD_FLAGS, pl->ob, op); 658 esrv_update_item (UPD_FLAGS, pl->ob, op);
663} 659}
664 660
665/** Client wants to apply some object. Lets do so. */ 661/** Client wants to apply some object. Lets do so. */
666void 662void
667MarkItem (uint8 * data, int len, player *pl) 663MarkItem (char *data, int len, player *pl)
668{ 664{
669 tag_t tag = net_uint32 (data); 665 tag_t tag = net_uint32 ((uint8 *)data);
670 object *op = esrv_get_ob_from_count (pl->ob, tag); 666 object *op = esrv_get_ob_from_count (pl->ob, tag);
671 667
672 if (!op) 668 if (!op)
673 { 669 {
674 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 670 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark");
758 { 754 {
759 return; 755 return;
760 } 756 }
761 dy = atoi (cp); 757 dy = atoi (cp);
762 758
763 if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2) 759 if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2)
764 return; 760 return;
765 761
766 if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) 762 if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2])
767 return; 763 return;
768 764
769 look_at (pl->ob, dx, dy); 765 look_at (pl->ob, dx, dy);
770} 766}
771 767
801 } 797 }
802 798
803 esrv_update_item (UPD_WEIGHT, pl, op); 799 esrv_update_item (UPD_WEIGHT, pl, op);
804 } 800 }
805 else 801 else
806 {
807 drop_object (pl, op, nrof); 802 drop_object (pl, op, nrof);
808 } 803
809 return; 804 return;
810 } 805 }
811 else if (to == pl->count) 806 else if (to == pl->count)
812 { /* pick it up to the inventory */ 807 { /* pick it up to the inventory */
813 /* return if player has already picked it up */ 808 /* return if player has already picked it up */
830 * has already been done (eg, it can be picked up and fits in 825 * 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 826 * 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. 827 * an make sure env is in fact a container for that matter.
833 */ 828 */
834 if (env->type == CONTAINER && can_pick (pl, op) && sack_can_hold (pl, env, op, nrof)) 829 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); 830 put_object_in_sack (pl, env, op, nrof);
837 }
838} 831}
839 832

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines