1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | 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 |
… | |
… | |
337 | { |
338 | { |
338 | object *tmp, *last; |
339 | object *tmp, *last; |
339 | int got_one = 0, start_look = 0, end_look = 0; |
340 | int got_one = 0, start_look = 0, end_look = 0; |
340 | char buf[MAX_BUF]; |
341 | char buf[MAX_BUF]; |
341 | |
342 | |
342 | if (!pl->contr->socket->update_look) |
343 | if (!pl->contr->ns->update_look) |
343 | { |
344 | { |
344 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
345 | LOG (llevDebug, "esrv_draw_look called when update_look was not set\n"); |
345 | return; |
346 | return; |
346 | } |
347 | } |
347 | else |
348 | else |
348 | pl->contr->socket->update_look = 0; |
349 | pl->contr->ns->update_look = 0; |
349 | |
350 | |
350 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
351 | if (QUERY_FLAG (pl, FLAG_REMOVED) |
351 | || !pl->map |
352 | || !pl->map |
352 | || pl->map->in_memory != MAP_IN_MEMORY |
353 | || pl->map->in_memory != MAP_IN_MEMORY |
353 | || out_of_map (pl->map, pl->x, pl->y)) |
354 | || out_of_map (pl->map, pl->x, pl->y)) |
354 | return; |
355 | return; |
355 | |
356 | |
356 | for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
357 | for (tmp = GET_MAP_OB (pl->map, pl->x, pl->y); tmp && tmp->above; tmp = tmp->above) |
357 | ; |
358 | ; |
358 | |
359 | |
359 | pl->contr->socket->send_packet ("delinv 0"); |
360 | pl->contr->ns->send_packet ("delinv 0"); |
360 | |
361 | |
361 | packet sl; |
362 | packet sl; |
362 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
363 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
363 | |
364 | |
364 | sl << uint32 (0); |
365 | sl << uint32 (0); |
365 | |
366 | |
366 | if (!(pl->contr->socket->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
367 | if (!(pl->contr->ns->faces_sent[empty_face->number] & NS_FACESENT_FACE)) |
367 | esrv_send_face (pl->contr->socket, empty_face->number, 0); |
368 | esrv_send_face (pl->contr->ns, empty_face->number, 0); |
368 | |
369 | |
369 | if (pl->contr->socket->look_position) |
370 | if (pl->contr->ns->look_position) |
370 | { |
371 | { |
371 | char buf[80]; |
372 | char buf[80]; |
372 | snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); |
373 | snprintf (buf, 80, "Apply this to see %d previous items", FLOORBOX_PAGESIZE); |
373 | |
374 | |
374 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position - FLOORBOX_PAGESIZE)) |
375 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position - FLOORBOX_PAGESIZE)) |
375 | << uint32 (0) |
376 | << uint32 (0) |
376 | << sint32 (-1) |
377 | << sint32 (-1) |
377 | << uint32 (empty_face->number) |
378 | << uint32 (empty_face->number) |
378 | << data8 (buf) |
379 | << data8 (buf) |
379 | << uint16 (0) |
380 | << uint16 (0) |
380 | << uint8 (0) |
381 | << uint8 (0) |
381 | << uint32 (0); |
382 | << uint32 (0); |
382 | |
383 | |
383 | if (pl->contr->socket->itemcmd == 2) |
384 | if (pl->contr->ns->itemcmd == 2) |
384 | sl << uint16 (0); |
385 | sl << uint16 (0); |
385 | } |
386 | } |
386 | |
387 | |
387 | for (last = NULL; tmp != last; tmp = tmp->below) |
388 | for (last = NULL; tmp != last; tmp = tmp->below) |
388 | { |
389 | { |
… | |
… | |
395 | last = last->below; |
396 | last = last->below; |
396 | } |
397 | } |
397 | |
398 | |
398 | if (LOOK_OBJ (tmp)) |
399 | if (LOOK_OBJ (tmp)) |
399 | { |
400 | { |
400 | if (++start_look < pl->contr->socket->look_position) |
401 | if (++start_look < pl->contr->ns->look_position) |
401 | continue; |
402 | continue; |
402 | |
403 | |
403 | end_look++; |
404 | end_look++; |
404 | |
405 | |
405 | if (end_look > FLOORBOX_PAGESIZE) |
406 | if (end_look > FLOORBOX_PAGESIZE) |
406 | { |
407 | { |
407 | /* What we basically do is make a 'fake' object - when the user applies it, |
408 | /* What we basically do is make a 'fake' object - when the user applies it, |
408 | * we notice the special tag the object has, and act accordingly. |
409 | * we notice the special tag the object has, and act accordingly. |
409 | */ |
410 | */ |
410 | sl << uint32 (0x80000000 | (pl->contr->socket->look_position + FLOORBOX_PAGESIZE)) |
411 | sl << uint32 (0x80000000 | (pl->contr->ns->look_position + FLOORBOX_PAGESIZE)) |
411 | << uint32 (0) |
412 | << uint32 (0) |
412 | << uint32 ((uint32) - 1) |
413 | << uint32 ((uint32) - 1) |
413 | << uint32 (empty_face->number) |
414 | << uint32 (empty_face->number) |
414 | << data8 ("Apply this to see next group of items") |
415 | << data8 ("Apply this to see next group of items") |
415 | << uint16 (0) |
416 | << uint16 (0) |
416 | << uint8 (0) |
417 | << uint8 (0) |
417 | << uint32 (0); |
418 | << uint32 (0); |
418 | |
419 | |
419 | if (pl->contr->socket->itemcmd == 2) |
420 | if (pl->contr->ns->itemcmd == 2) |
420 | sl << uint16 (0); |
421 | sl << uint16 (0); |
421 | |
422 | |
422 | break; |
423 | break; |
423 | } |
424 | } |
424 | |
425 | |
425 | if (tmp->head) |
426 | if (tmp->head) |
426 | head = tmp->head; |
427 | head = tmp->head; |
427 | else |
428 | else |
428 | head = tmp; |
429 | head = tmp; |
429 | |
430 | |
430 | add_object_to_socklist (*pl->contr->socket, sl, head); |
431 | add_object_to_socklist (*pl->contr->ns, sl, head); |
431 | got_one++; |
432 | got_one++; |
432 | |
433 | |
433 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
434 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
434 | { |
435 | { |
435 | pl->contr->socket->send_packet (sl); |
436 | pl->contr->ns->send_packet (sl); |
436 | |
437 | |
437 | sl.reset (); |
438 | sl.reset (); |
438 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
439 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
439 | sl << uint32 (0); |
440 | sl << uint32 (0); |
440 | got_one = 0; |
441 | got_one = 0; |
441 | } |
442 | } |
442 | } |
443 | } |
443 | } |
444 | } |
444 | |
445 | |
445 | if (got_one) |
446 | if (got_one) |
446 | pl->contr->socket->send_packet (sl); |
447 | pl->contr->ns->send_packet (sl); |
447 | |
448 | |
448 | } |
449 | } |
449 | |
450 | |
450 | /** |
451 | /** |
451 | * Sends whole inventory. |
452 | * Sends whole inventory. |
… | |
… | |
455 | { |
456 | { |
456 | object *tmp; |
457 | object *tmp; |
457 | int got_one = 0; |
458 | int got_one = 0; |
458 | |
459 | |
459 | |
460 | |
460 | pl->contr->socket->send_packet_printf ("delinv %d", op->count); |
461 | pl->contr->ns->send_packet_printf ("delinv %d", op->count); |
461 | |
462 | |
462 | packet sl; |
463 | packet sl; |
463 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
464 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
464 | |
465 | |
465 | sl << uint32 (op->count); |
466 | sl << uint32 (op->count); |
466 | |
467 | |
467 | for (tmp = op->inv; tmp; tmp = tmp->below) |
468 | for (tmp = op->inv; tmp; tmp = tmp->below) |
468 | { |
469 | { |
… | |
… | |
473 | else |
474 | else |
474 | head = tmp; |
475 | head = tmp; |
475 | |
476 | |
476 | if (LOOK_OBJ (head)) |
477 | if (LOOK_OBJ (head)) |
477 | { |
478 | { |
478 | add_object_to_socklist (*pl->contr->socket, sl, head); |
479 | add_object_to_socklist (*pl->contr->ns, sl, head); |
479 | |
480 | |
480 | got_one++; |
481 | got_one++; |
481 | |
482 | |
482 | /* IT is possible for players to accumulate a huge amount of |
483 | /* IT is possible for players to accumulate a huge amount of |
483 | * items (especially with some of the bags out there) to |
484 | * items (especially with some of the bags out there) to |
484 | * overflow the buffer. IF so, send multiple item commands. |
485 | * overflow the buffer. IF so, send multiple item commands. |
485 | */ |
486 | */ |
486 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
487 | if (sl.length () >= (MAXSOCKBUF - MAXITEMLEN)) |
487 | { |
488 | { |
488 | pl->contr->socket->send_packet (sl); |
489 | pl->contr->ns->send_packet (sl); |
489 | |
490 | |
490 | sl.reset (); |
491 | sl.reset (); |
491 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
492 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
492 | sl << uint32 (op->count); |
493 | sl << uint32 (op->count); |
493 | got_one = 0; |
494 | got_one = 0; |
494 | } |
495 | } |
495 | } /* If LOOK_OBJ() */ |
496 | } /* If LOOK_OBJ() */ |
496 | } |
497 | } |
497 | |
498 | |
498 | if (got_one) |
499 | if (got_one) |
499 | pl->contr->socket->send_packet (sl); |
500 | pl->contr->ns->send_packet (sl); |
500 | } |
501 | } |
501 | |
502 | |
502 | /** |
503 | /** |
503 | * Updates object *op for player *pl. |
504 | * Updates object *op for player *pl. |
504 | * |
505 | * |
… | |
… | |
555 | op->contr->last_weight = weight; |
556 | op->contr->last_weight = weight; |
556 | } |
557 | } |
557 | |
558 | |
558 | if (flags & UPD_FACE) |
559 | if (flags & UPD_FACE) |
559 | { |
560 | { |
560 | if (!(pl->contr->socket->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
561 | if (!(pl->contr->ns->faces_sent[op->face->number] & NS_FACESENT_FACE)) |
561 | esrv_send_face (pl->contr->socket, op->face->number, 0); |
562 | esrv_send_face (pl->contr->ns, op->face->number, 0); |
562 | |
563 | |
563 | sl << uint32 (op->face->number); |
564 | sl << uint32 (op->face->number); |
564 | } |
565 | } |
565 | |
566 | |
566 | if (flags & UPD_NAME) |
567 | if (flags & UPD_NAME) |
… | |
… | |
620 | } |
621 | } |
621 | |
622 | |
622 | if (flags & UPD_NROF) |
623 | if (flags & UPD_NROF) |
623 | sl << uint32 (op->nrof); |
624 | sl << uint32 (op->nrof); |
624 | |
625 | |
625 | pl->contr->socket->send_packet (sl); |
626 | pl->contr->ns->send_packet (sl); |
626 | } |
627 | } |
627 | |
628 | |
628 | /** |
629 | /** |
629 | * Sends item's info to player. |
630 | * Sends item's info to player. |
630 | */ |
631 | */ |
… | |
… | |
640 | /* if the item is on the ground, mark that the look needs to |
641 | /* if the item is on the ground, mark that the look needs to |
641 | * be updated. |
642 | * be updated. |
642 | */ |
643 | */ |
643 | if (!op->env) |
644 | if (!op->env) |
644 | { |
645 | { |
645 | pl->contr->socket->floorbox_update (); |
646 | pl->contr->ns->floorbox_update (); |
646 | return; |
647 | return; |
647 | } |
648 | } |
648 | } |
649 | } |
649 | |
650 | |
650 | packet sl; |
651 | packet sl; |
651 | |
652 | |
652 | sl.printf ("item%d ", pl->contr->socket->itemcmd); |
653 | sl.printf ("item%d ", pl->contr->ns->itemcmd); |
653 | |
654 | |
654 | if (op->head) |
655 | if (op->head) |
655 | op = op->head; |
656 | op = op->head; |
656 | |
657 | |
657 | sl << uint32 (op->env ? op->env->count : 0); |
658 | sl << uint32 (op->env ? op->env->count : 0); |
658 | |
659 | |
659 | add_object_to_socklist (*pl->contr->socket, sl, op); |
660 | add_object_to_socklist (*pl->contr->ns, sl, op); |
660 | |
661 | |
661 | pl->contr->socket->send_packet (sl); |
662 | pl->contr->ns->send_packet (sl); |
662 | SET_FLAG (op, FLAG_CLIENT_SENT); |
663 | SET_FLAG (op, FLAG_CLIENT_SENT); |
663 | } |
664 | } |
664 | |
665 | |
665 | /** |
666 | /** |
666 | * Tells the client to delete an item. Uses the item |
667 | * Tells the client to delete an item. Uses the item |
… | |
… | |
672 | { |
673 | { |
673 | packet sl ("delitem"); |
674 | packet sl ("delitem"); |
674 | |
675 | |
675 | sl << uint32 (tag); |
676 | sl << uint32 (tag); |
676 | |
677 | |
677 | pl->socket->send_packet (sl); |
678 | pl->ns->send_packet (sl); |
678 | } |
679 | } |
679 | |
680 | |
680 | |
681 | |
681 | /******************************************************************************* |
682 | /******************************************************************************* |
682 | * |
683 | * |
… | |
… | |
753 | return; |
754 | return; |
754 | |
755 | |
755 | /* If the high bit is set, player applied a pseudo object. */ |
756 | /* If the high bit is set, player applied a pseudo object. */ |
756 | if (tag & 0x80000000) |
757 | if (tag & 0x80000000) |
757 | { |
758 | { |
758 | pl->socket->look_position = tag & 0x7fffffff; |
759 | pl->ns->look_position = tag & 0x7fffffff; |
759 | pl->socket->floorbox_update (); |
760 | pl->ns->floorbox_update (); |
760 | return; |
761 | return; |
761 | } |
762 | } |
762 | |
763 | |
763 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
764 | object *op = esrv_get_ob_from_count (pl->ob, tag); |
764 | |
765 | |
… | |
… | |
889 | { |
890 | { |
890 | return; |
891 | return; |
891 | } |
892 | } |
892 | dy = atoi (cp); |
893 | dy = atoi (cp); |
893 | |
894 | |
894 | if (FABS (dx) > pl->socket->mapx / 2 || FABS (dy) > pl->socket->mapy / 2) |
895 | if (FABS (dx) > pl->ns->mapx / 2 || FABS (dy) > pl->ns->mapy / 2) |
895 | return; |
896 | return; |
896 | |
897 | |
897 | if (pl->blocked_los[dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]) |
898 | if (pl->blocked_los[dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2]) |
898 | return; |
899 | return; |
899 | |
900 | |
900 | look_at (pl->ob, dx, dy); |
901 | look_at (pl->ob, dx, dy); |
901 | } |
902 | } |
902 | |
903 | |