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.23 by root, Fri Dec 15 19:59:20 2006 UTC

33 */ 33 */
34 34
35 35
36#include <global.h> 36#include <global.h>
37#include <object.h> /* LOOK_OBJ */ 37#include <object.h> /* LOOK_OBJ */
38#include <newclient.h>
39#include <newserver.h>
40#include <sproto.h> 38#include <sproto.h>
41 39
42/** This is the maximum number of bytes we expect any one item to take up */ 40/** This is the maximum number of bytes we expect any one item to take up */
43#define MAXITEMLEN 300 41#define MAXITEMLEN 300
44 42
114/* Used in the send_look to put object head into packet 112/* 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 113 * sl for socket ns. Need socket to know if we need to send
116 * animation of face to the client. 114 * animation of face to the client.
117 */ 115 */
118static void 116static void
119add_object_to_socklist (NewSocket &ns, packet &sl, object *head) 117add_object_to_socklist (client &ns, packet &sl, object *head)
120{ 118{
121 int flags, len, anim_speed; 119 int flags, len, anim_speed;
122 char item_n[MAX_BUF]; 120 char item_n[MAX_BUF];
123 const char *item_p; 121 const char *item_p;
124 122
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 } /* If LOOK_OBJ() */
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 363
366} 364}
367 365
368/** 366/**
369 * Updates object *op for player *pl. 367 * Updates object *op for player *pl.
422 op->contr->last_weight = weight; 420 op->contr->last_weight = weight;
423 } 421 }
424 422
425 if (flags & UPD_FACE) 423 if (flags & UPD_FACE)
426 { 424 {
427 if (!(pl->contr->socket.faces_sent[op->face->number] & NS_FACESENT_FACE)) 425 if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE))
428 esrv_send_face (&pl->contr->socket, op->face->number, 0); 426 esrv_send_face (pl->contr->socket, op->face->number, 0);
429 427
430 sl << uint32 (op->face->number); 428 sl << uint32 (op->face->number);
431 } 429 }
432 430
433 if (flags & UPD_NAME) 431 if (flags & UPD_NAME)
487 } 485 }
488 486
489 if (flags & UPD_NROF) 487 if (flags & UPD_NROF)
490 sl << uint32 (op->nrof); 488 sl << uint32 (op->nrof);
491 489
492 Send_With_Handling (&pl->contr->socket, &sl); 490 pl->contr->socket->send_packet (sl);
493} 491}
494 492
495/** 493/**
496 * Sends item's info to player. 494 * Sends item's info to player.
497 */ 495 */
507 /* if the item is on the ground, mark that the look needs to 505 /* if the item is on the ground, mark that the look needs to
508 * be updated. 506 * be updated.
509 */ 507 */
510 if (!op->env) 508 if (!op->env)
511 { 509 {
512 pl->contr->socket.update_look = 1; 510 pl->contr->socket->update_look = 1;
513 return; 511 return;
514 } 512 }
515 } 513 }
516 514
517 packet sl; 515 packet sl;
518 516
519 sl.printf ("item%d ", pl->contr->socket.itemcmd); 517 sl.printf ("item%d ", pl->contr->socket->itemcmd);
520 518
521 if (op->head) 519 if (op->head)
522 op = op->head; 520 op = op->head;
523 521
524 sl << uint32 (op->env ? op->env->count : 0); 522 sl << uint32 (op->env ? op->env->count : 0);
525 523
526 add_object_to_socklist (pl->contr->socket, sl, op); 524 add_object_to_socklist (*pl->contr->socket, sl, op);
527 525
528 Send_With_Handling (&pl->contr->socket, &sl); 526 pl->contr->socket->send_packet (sl);
529 SET_FLAG (op, FLAG_CLIENT_SENT); 527 SET_FLAG (op, FLAG_CLIENT_SENT);
530 528
531} 529}
532 530
533/** 531/**
541 packet sl; 539 packet sl;
542 540
543 sl << "delitem " 541 sl << "delitem "
544 << uint32 (tag); 542 << uint32 (tag);
545 543
546 Send_With_Handling (&pl->socket, &sl); 544 pl->socket->send_packet (sl);
547} 545}
548 546
549 547
550/******************************************************************************* 548/*******************************************************************************
551 * 549 *
622 return; 620 return;
623 621
624 /* If the high bit is set, player applied a pseudo object. */ 622 /* If the high bit is set, player applied a pseudo object. */
625 if (tag & 0x80000000) 623 if (tag & 0x80000000)
626 { 624 {
627 pl->socket.look_position = tag & 0x7fffffff; 625 pl->socket->look_position = tag & 0x7fffffff;
628 pl->socket.update_look = 1; 626 pl->socket->update_look = 1;
629 return; 627 return;
630 } 628 }
631 629
632 object *op = esrv_get_ob_from_count (pl->ob, tag); 630 object *op = esrv_get_ob_from_count (pl->ob, tag);
633 631
640 player_apply (pl->ob, op, 0, 0); 638 player_apply (pl->ob, op, 0, 0);
641} 639}
642 640
643/** Client wants to apply some object. Lets do so. */ 641/** Client wants to apply some object. Lets do so. */
644void 642void
645LockItem (uint8 *data, int len, player *pl) 643LockItem (char *data, int len, player *pl)
646{ 644{
647 int flag = data[0]; 645 int flag = data[0];
648 tag_t tag = net_uint32 (data + 1); 646 tag_t tag = net_uint32 ((uint8 *)data + 1);
649 object *op = esrv_get_ob_from_count (pl->ob, tag); 647 object *op = esrv_get_ob_from_count (pl->ob, tag);
650 648
651 if (!op) 649 if (!op)
652 { 650 {
653 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock"); 651 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to lock/unlock");
662 esrv_update_item (UPD_FLAGS, pl->ob, op); 660 esrv_update_item (UPD_FLAGS, pl->ob, op);
663} 661}
664 662
665/** Client wants to apply some object. Lets do so. */ 663/** Client wants to apply some object. Lets do so. */
666void 664void
667MarkItem (uint8 * data, int len, player *pl) 665MarkItem (char *data, int len, player *pl)
668{ 666{
669 tag_t tag = net_uint32 (data); 667 tag_t tag = net_uint32 ((uint8 *)data);
670 object *op = esrv_get_ob_from_count (pl->ob, tag); 668 object *op = esrv_get_ob_from_count (pl->ob, tag);
671 669
672 if (!op) 670 if (!op)
673 { 671 {
674 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark"); 672 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Could not find object to mark");
758 { 756 {
759 return; 757 return;
760 } 758 }
761 dy = atoi (cp); 759 dy = atoi (cp);
762 760
763 if (FABS (dx) > pl->socket.mapx / 2 || FABS (dy) > pl->socket.mapy / 2) 761 if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2)
764 return; 762 return;
765 763
766 if (pl->blocked_los[dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]) 764 if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2])
767 return; 765 return;
768 766
769 look_at (pl->ob, dx, dy); 767 look_at (pl->ob, dx, dy);
770} 768}
771 769

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines