--- deliantra/server/socket/request.C 2006/09/21 14:51:16 1.25 +++ deliantra/server/socket/request.C 2006/12/13 18:08:02 1.27 @@ -59,13 +59,11 @@ /* This block is basically taken from socket.c - I assume if it works there, * it should work here. */ -#ifndef WIN32 /* ---win32 exclude unix headers */ -# include -# include -# include -# include -# include -#endif /* win32 */ +#include +#include +#include +#include +#include #ifdef HAVE_UNISTD_H # include @@ -708,8 +706,9 @@ sl.buf = reply; strcpy ((char *) sl.buf, "smooth "); sl.len = strlen ((char *) sl.buf); - SockList_AddShort (&sl, face); - SockList_AddShort (&sl, smoothface); + + sl << uint16 (face) << uint16 (smoothface); + Send_With_Handling (ns, &sl); } @@ -844,12 +843,14 @@ sl.buf = command; strcpy ((char *) sl.buf, "comc "); sl.len = 5; - SockList_AddShort (&sl, packet); + if (FABS (pl->ob->speed) < 0.001) time = MAX_TIME * 100; else time = (int) (MAX_TIME / FABS (pl->ob->speed)); - SockList_AddInt (&sl, time); + + sl << uint16 (packet) << uint32 (time); + Send_With_Handling (&pl->socket, &sl); } @@ -2086,7 +2087,7 @@ uint8 stat_hp = 0; uint8 stat_width = 0; uint8 flags = 0; - tag_t player = 0; + UUID player = 0; // send hp information, if applicable if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) @@ -2117,15 +2118,15 @@ mask |= 0x8; *last_ext |= 0x80; last_ext = sl.buf + sl.len; - SockList_AddChar (&sl, 5); - SockList_AddChar (&sl, stat_hp); + + sl << uint8 (5) << uint8 (stat_hp); if (stat_width > 1) { *last_ext |= 0x80; last_ext = sl.buf + sl.len; - SockList_AddChar (&sl, 6); - SockList_AddChar (&sl, stat_width); + + sl << uint8 (6) << uint8 (stat_width); } } @@ -2136,9 +2137,8 @@ mask |= 0x8; *last_ext |= 0x80; last_ext = sl.buf + sl.len; - SockList_AddChar (&sl, 0x47); - SockList_AddChar (&sl, 4); - SockList_AddInt (&sl, player); + + sl << uint8 (0x47) << uint8 (8) << (uint64)player; } if (lastcell.flags != flags) @@ -2148,8 +2148,8 @@ mask |= 0x8; *last_ext |= 0x80; last_ext = sl.buf + sl.len; - SockList_AddChar (&sl, 8); - SockList_AddChar (&sl, flags); + + sl << uint8 (8) << uint8 (flags); } } @@ -2179,7 +2179,7 @@ if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) esrv_send_face (&socket, pl->face->number, 0); - SockList_AddShort (&sl, pl->face->number); + sl << uint16 (pl->face->number); } } else @@ -2468,14 +2468,13 @@ sl.buf = (unsigned char *) malloc (MAXSOCKBUF); strcpy ((char *) sl.buf, "updspell "); sl.len = strlen ((char *) sl.buf); - SockList_AddChar (&sl, flags); - SockList_AddInt (&sl, spell->count); - if (flags & UPD_SP_MANA) - SockList_AddShort (&sl, spell->last_sp); - if (flags & UPD_SP_GRACE) - SockList_AddShort (&sl, spell->last_grace); - if (flags & UPD_SP_DAMAGE) - SockList_AddShort (&sl, spell->last_eat); + + sl << uint8 (flags) << uint32 (spell->count); + + if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); + if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); + if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); + flags = 0; Send_With_Handling (&pl->socket, &sl); free (sl.buf); @@ -2499,14 +2498,16 @@ sl.buf = (unsigned char *) malloc (MAXSOCKBUF); strcpy ((char *) sl.buf, "delspell "); sl.len = strlen ((char *) sl.buf); - SockList_AddInt (&sl, spell->count); + + sl << uint32 (spell->count); + Send_With_Handling (&pl->socket, &sl); free (sl.buf); } /* appends the spell *spell to the Socklist we will send the data to. */ static void -append_spell (player *pl, SockList * sl, object *spell) +append_spell (player *pl, SockList &sl, object *spell) { int len, i, skill = 0; @@ -2515,17 +2516,11 @@ LOG (llevError, "item number %d is a spell with no name.\n", spell->count); return; } - SockList_AddInt (sl, spell->count); - SockList_AddShort (sl, spell->level); - SockList_AddShort (sl, spell->casting_time); + /* store costs and damage in the object struct, to compare to later */ - spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); + spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); - spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); - /* send the current values */ - SockList_AddShort (sl, spell->last_sp); - SockList_AddShort (sl, spell->last_grace); - SockList_AddShort (sl, spell->last_eat); + spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); /* figure out which skill it uses, if it uses one */ if (spell->skill) @@ -2537,27 +2532,19 @@ break; } } - SockList_AddChar (sl, skill); - - SockList_AddInt (sl, spell->path_attuned); - SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); - - len = strlen (spell->name); - SockList_AddChar (sl, (char) len); - memcpy (sl->buf + sl->len, spell->name, len); - sl->len += len; - if (!spell->msg) - { - SockList_AddShort (sl, 0); - } - else - { - len = strlen (spell->msg); - SockList_AddShort (sl, len); - memcpy (sl->buf + sl->len, spell->msg, len); - sl->len += len; - } + /* send the current values */ + sl << uint32 (spell->count) + << uint16 (spell->level) + << uint16 (spell->casting_time) + << uint16 (spell->last_sp) + << uint16 (spell->last_grace) + << uint16 (spell->last_eat) + << uint8 (skill) + << uint32 (spell->path_attuned) + << uint32 (spell->face ? spell->face->number : 0) + << data8 (spell->name) + << data16 (spell->msg); } /** @@ -2598,13 +2585,15 @@ */ if (spell->type != SPELL) continue; + if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) { Send_With_Handling (&pl->socket, &sl); strcpy ((char *) sl.buf, "addspell "); sl.len = strlen ((char *) sl.buf); } - append_spell (pl, &sl, spell); + + append_spell (pl, sl, spell); } } else if (spell->type != SPELL) @@ -2613,12 +2602,14 @@ return; } else - append_spell (pl, &sl, spell); + append_spell (pl, sl, spell); + if (sl.len >= MAXSOCKBUF) { LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); fatal (0); } + /* finally, we can send the packet */ Send_With_Handling (&pl->socket, &sl); free (sl.buf);