ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.25 by root, Thu Sep 21 14:51:16 2006 UTC vs.
Revision 1.27 by root, Wed Dec 13 18:08:02 2006 UTC

57#include <commands.h> 57#include <commands.h>
58 58
59/* This block is basically taken from socket.c - I assume if it works there, 59/* This block is basically taken from socket.c - I assume if it works there,
60 * it should work here. 60 * it should work here.
61 */ 61 */
62#ifndef WIN32 /* ---win32 exclude unix headers */
63# include <sys/types.h> 62#include <sys/types.h>
64# include <sys/time.h> 63#include <sys/time.h>
65# include <sys/socket.h> 64#include <sys/socket.h>
66# include <netinet/in.h> 65#include <netinet/in.h>
67# include <netdb.h> 66#include <netdb.h>
68#endif /* win32 */
69 67
70#ifdef HAVE_UNISTD_H 68#ifdef HAVE_UNISTD_H
71# include <unistd.h> 69# include <unistd.h>
72#endif 70#endif
73 71
706 ns->faces_sent[face] |= NS_FACESENT_SMOOTH; 704 ns->faces_sent[face] |= NS_FACESENT_SMOOTH;
707 705
708 sl.buf = reply; 706 sl.buf = reply;
709 strcpy ((char *) sl.buf, "smooth "); 707 strcpy ((char *) sl.buf, "smooth ");
710 sl.len = strlen ((char *) sl.buf); 708 sl.len = strlen ((char *) sl.buf);
711 SockList_AddShort (&sl, face); 709
712 SockList_AddShort (&sl, smoothface); 710 sl << uint16 (face) << uint16 (smoothface);
711
713 Send_With_Handling (ns, &sl); 712 Send_With_Handling (ns, &sl);
714} 713}
715 714
716 /** 715 /**
717 * Tells client the picture it has to use 716 * Tells client the picture it has to use
842 841
843 /* Send confirmation of command execution now */ 842 /* Send confirmation of command execution now */
844 sl.buf = command; 843 sl.buf = command;
845 strcpy ((char *) sl.buf, "comc "); 844 strcpy ((char *) sl.buf, "comc ");
846 sl.len = 5; 845 sl.len = 5;
847 SockList_AddShort (&sl, packet); 846
848 if (FABS (pl->ob->speed) < 0.001) 847 if (FABS (pl->ob->speed) < 0.001)
849 time = MAX_TIME * 100; 848 time = MAX_TIME * 100;
850 else 849 else
851 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 850 time = (int) (MAX_TIME / FABS (pl->ob->speed));
852 SockList_AddInt (&sl, time); 851
852 sl << uint16 (packet) << uint32 (time);
853
853 Send_With_Handling (&pl->socket, &sl); 854 Send_With_Handling (&pl->socket, &sl);
854} 855}
855 856
856 857
857/** This is a reply to a previous query. */ 858/** This is a reply to a previous query. */
2084 if (socket.extmap) 2085 if (socket.extmap)
2085 { 2086 {
2086 uint8 stat_hp = 0; 2087 uint8 stat_hp = 0;
2087 uint8 stat_width = 0; 2088 uint8 stat_width = 0;
2088 uint8 flags = 0; 2089 uint8 flags = 0;
2089 tag_t player = 0; 2090 UUID player = 0;
2090 2091
2091 // send hp information, if applicable 2092 // send hp information, if applicable
2092 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) 2093 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0))
2093 { 2094 {
2094 if (op->head || op->invisible) 2095 if (op->head || op->invisible)
2115 lastcell.stat_hp = stat_hp; 2116 lastcell.stat_hp = stat_hp;
2116 2117
2117 mask |= 0x8; 2118 mask |= 0x8;
2118 *last_ext |= 0x80; 2119 *last_ext |= 0x80;
2119 last_ext = sl.buf + sl.len; 2120 last_ext = sl.buf + sl.len;
2120 SockList_AddChar (&sl, 5); 2121
2121 SockList_AddChar (&sl, stat_hp); 2122 sl << uint8 (5) << uint8 (stat_hp);
2122 2123
2123 if (stat_width > 1) 2124 if (stat_width > 1)
2124 { 2125 {
2125 *last_ext |= 0x80; 2126 *last_ext |= 0x80;
2126 last_ext = sl.buf + sl.len; 2127 last_ext = sl.buf + sl.len;
2127 SockList_AddChar (&sl, 6); 2128
2128 SockList_AddChar (&sl, stat_width); 2129 sl << uint8 (6) << uint8 (stat_width);
2129 } 2130 }
2130 } 2131 }
2131 2132
2132 if (lastcell.player != player) 2133 if (lastcell.player != player)
2133 { 2134 {
2134 lastcell.player = player; 2135 lastcell.player = player;
2135 2136
2136 mask |= 0x8; 2137 mask |= 0x8;
2137 *last_ext |= 0x80; 2138 *last_ext |= 0x80;
2138 last_ext = sl.buf + sl.len; 2139 last_ext = sl.buf + sl.len;
2139 SockList_AddChar (&sl, 0x47); 2140
2140 SockList_AddChar (&sl, 4); 2141 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2141 SockList_AddInt (&sl, player);
2142 } 2142 }
2143 2143
2144 if (lastcell.flags != flags) 2144 if (lastcell.flags != flags)
2145 { 2145 {
2146 lastcell.flags = flags; 2146 lastcell.flags = flags;
2147 2147
2148 mask |= 0x8; 2148 mask |= 0x8;
2149 *last_ext |= 0x80; 2149 *last_ext |= 0x80;
2150 last_ext = sl.buf + sl.len; 2150 last_ext = sl.buf + sl.len;
2151 SockList_AddChar (&sl, 8); 2151
2152 SockList_AddChar (&sl, flags); 2152 sl << uint8 (8) << uint8 (flags);
2153 } 2153 }
2154 } 2154 }
2155 2155
2156 /* Floor face */ 2156 /* Floor face */
2157 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2157 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2))
2177 mask |= 0x1; 2177 mask |= 0x1;
2178 2178
2179 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2179 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2180 esrv_send_face (&socket, pl->face->number, 0); 2180 esrv_send_face (&socket, pl->face->number, 0);
2181 2181
2182 SockList_AddShort (&sl, pl->face->number); 2182 sl << uint16 (pl->face->number);
2183 } 2183 }
2184 } 2184 }
2185 else 2185 else
2186 { 2186 {
2187 /* Top face */ 2187 /* Top face */
2466 if (flags != 0) 2466 if (flags != 0)
2467 { 2467 {
2468 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2468 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2469 strcpy ((char *) sl.buf, "updspell "); 2469 strcpy ((char *) sl.buf, "updspell ");
2470 sl.len = strlen ((char *) sl.buf); 2470 sl.len = strlen ((char *) sl.buf);
2471 SockList_AddChar (&sl, flags); 2471
2472 SockList_AddInt (&sl, spell->count); 2472 sl << uint8 (flags) << uint32 (spell->count);
2473 if (flags & UPD_SP_MANA) 2473
2474 SockList_AddShort (&sl, spell->last_sp); 2474 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2475 if (flags & UPD_SP_GRACE) 2475 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2476 SockList_AddShort (&sl, spell->last_grace); 2476 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2477 if (flags & UPD_SP_DAMAGE) 2477
2478 SockList_AddShort (&sl, spell->last_eat);
2479 flags = 0; 2478 flags = 0;
2480 Send_With_Handling (&pl->socket, &sl); 2479 Send_With_Handling (&pl->socket, &sl);
2481 free (sl.buf); 2480 free (sl.buf);
2482 } 2481 }
2483 } 2482 }
2497 return; 2496 return;
2498 } 2497 }
2499 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2498 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2500 strcpy ((char *) sl.buf, "delspell "); 2499 strcpy ((char *) sl.buf, "delspell ");
2501 sl.len = strlen ((char *) sl.buf); 2500 sl.len = strlen ((char *) sl.buf);
2502 SockList_AddInt (&sl, spell->count); 2501
2502 sl << uint32 (spell->count);
2503
2503 Send_With_Handling (&pl->socket, &sl); 2504 Send_With_Handling (&pl->socket, &sl);
2504 free (sl.buf); 2505 free (sl.buf);
2505} 2506}
2506 2507
2507/* appends the spell *spell to the Socklist we will send the data to. */ 2508/* appends the spell *spell to the Socklist we will send the data to. */
2508static void 2509static void
2509append_spell (player *pl, SockList * sl, object *spell) 2510append_spell (player *pl, SockList &sl, object *spell)
2510{ 2511{
2511 int len, i, skill = 0; 2512 int len, i, skill = 0;
2512 2513
2513 if (!(spell->name)) 2514 if (!(spell->name))
2514 { 2515 {
2515 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 2516 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
2516 return; 2517 return;
2517 } 2518 }
2518 SockList_AddInt (sl, spell->count); 2519
2519 SockList_AddShort (sl, spell->level);
2520 SockList_AddShort (sl, spell->casting_time);
2521 /* store costs and damage in the object struct, to compare to later */ 2520 /* store costs and damage in the object struct, to compare to later */
2522 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 2521 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
2523 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 2522 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
2524 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 2523 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
2525 /* send the current values */
2526 SockList_AddShort (sl, spell->last_sp);
2527 SockList_AddShort (sl, spell->last_grace);
2528 SockList_AddShort (sl, spell->last_eat);
2529 2524
2530 /* figure out which skill it uses, if it uses one */ 2525 /* figure out which skill it uses, if it uses one */
2531 if (spell->skill) 2526 if (spell->skill)
2532 { 2527 {
2533 for (i = 1; i < NUM_SKILLS; i++) 2528 for (i = 1; i < NUM_SKILLS; i++)
2535 { 2530 {
2536 skill = i + CS_STAT_SKILLINFO; 2531 skill = i + CS_STAT_SKILLINFO;
2537 break; 2532 break;
2538 } 2533 }
2539 } 2534 }
2540 SockList_AddChar (sl, skill);
2541 2535
2542 SockList_AddInt (sl, spell->path_attuned); 2536 /* send the current values */
2537 sl << uint32 (spell->count)
2538 << uint16 (spell->level)
2539 << uint16 (spell->casting_time)
2540 << uint16 (spell->last_sp)
2541 << uint16 (spell->last_grace)
2542 << uint16 (spell->last_eat)
2543 << uint8 (skill)
2544 << uint32 (spell->path_attuned)
2543 SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); 2545 << uint32 (spell->face ? spell->face->number : 0)
2544 2546 << data8 (spell->name)
2545 len = strlen (spell->name); 2547 << data16 (spell->msg);
2546 SockList_AddChar (sl, (char) len);
2547 memcpy (sl->buf + sl->len, spell->name, len);
2548 sl->len += len;
2549
2550 if (!spell->msg)
2551 {
2552 SockList_AddShort (sl, 0);
2553 }
2554 else
2555 {
2556 len = strlen (spell->msg);
2557 SockList_AddShort (sl, len);
2558 memcpy (sl->buf + sl->len, spell->msg, len);
2559 sl->len += len;
2560 }
2561} 2548}
2562 2549
2563/** 2550/**
2564 * This tells the client to add the spell *ob, if *ob is NULL, then add 2551 * This tells the client to add the spell *ob, if *ob is NULL, then add
2565 * all spells in the player's inventory. 2552 * all spells in the player's inventory.
2596 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem 2583 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem
2597 * like it will fix this 2584 * like it will fix this
2598 */ 2585 */
2599 if (spell->type != SPELL) 2586 if (spell->type != SPELL)
2600 continue; 2587 continue;
2588
2601 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2589 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2602 { 2590 {
2603 Send_With_Handling (&pl->socket, &sl); 2591 Send_With_Handling (&pl->socket, &sl);
2604 strcpy ((char *) sl.buf, "addspell "); 2592 strcpy ((char *) sl.buf, "addspell ");
2605 sl.len = strlen ((char *) sl.buf); 2593 sl.len = strlen ((char *) sl.buf);
2606 } 2594 }
2595
2607 append_spell (pl, &sl, spell); 2596 append_spell (pl, sl, spell);
2608 } 2597 }
2609 } 2598 }
2610 else if (spell->type != SPELL) 2599 else if (spell->type != SPELL)
2611 { 2600 {
2612 LOG (llevError, "Asked to send a non-spell object as a spell"); 2601 LOG (llevError, "Asked to send a non-spell object as a spell");
2613 return; 2602 return;
2614 } 2603 }
2615 else 2604 else
2616 append_spell (pl, &sl, spell); 2605 append_spell (pl, sl, spell);
2606
2617 if (sl.len >= MAXSOCKBUF) 2607 if (sl.len >= MAXSOCKBUF)
2618 { 2608 {
2619 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2609 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2620 fatal (0); 2610 fatal (0);
2621 } 2611 }
2612
2622 /* finally, we can send the packet */ 2613 /* finally, we can send the packet */
2623 Send_With_Handling (&pl->socket, &sl); 2614 Send_With_Handling (&pl->socket, &sl);
2624 free (sl.buf); 2615 free (sl.buf);
2625} 2616}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines