--- deliantra/server/socket/request.C 2006/12/14 04:30:33 1.36 +++ deliantra/server/socket/request.C 2006/12/15 04:21:29 1.40 @@ -62,13 +62,8 @@ #include #include -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef HAVE_SYS_TIME_H -# include -#endif +#include +#include #include "sounds.h" @@ -223,6 +218,50 @@ socket.current_y = ob->y; } +/** + * RequestInfo is sort of a meta command. There is some specific + * request of information, but we call other functions to provide + * that information. + */ +void +RequestInfo (char *buf, int len, client_socket * ns) +{ + char *params = NULL, *cp; + + /* No match */ + char bigbuf[MAX_BUF]; + int slen; + + /* Set up replyinfo before we modify any of the buffers - this is used + * if we don't find a match. + */ + strcpy (bigbuf, "replyinfo "); + slen = strlen (bigbuf); + safe_strcat (bigbuf, buf, &slen, MAX_BUF); + + /* find the first space, make it null, and update the + * params pointer. + */ + for (cp = buf; *cp != '\0'; cp++) + if (*cp == ' ') + { + *cp = '\0'; + params = cp + 1; + break; + } + + if (!strcmp (buf, "image_info")) + send_image_info (ns, params); + else if (!strcmp (buf, "image_sums")) + send_image_sums (ns, params); + else if (!strcmp (buf, "skill_info")) + send_skill_info (ns, params); + else if (!strcmp (buf, "spell_paths")) + send_spell_paths (ns, params); + else + ns->send_packet (bigbuf, len); +} + void ExtCmd (char *buf, int len, player *pl) { @@ -701,7 +740,7 @@ << uint16 (face) << uint16 (smoothface); - Send_With_Handling (ns, &sl); + ns->send_packet (sl); } /** @@ -776,7 +815,7 @@ * can throttle. */ void -NewPlayerCmd (uint8 * buf, int len, player *pl) +NewPlayerCmd (char *buf, int len, player *pl) { int time, repeat; char command[MAX_BUF]; @@ -788,8 +827,8 @@ return; } - pktlen = net_uint16 (buf); - repeat = net_uint32 (buf + 2); + pktlen = net_uint16 ((uint8 *)buf); + repeat = net_uint32 ((uint8 *)buf + 2); /* -1 is special - no repeat, but don't update */ if (repeat != -1) @@ -799,18 +838,7 @@ len = MAX_BUF - 5; strncpy ((char *) command, (char *) buf + 6, len - 4); - command[len - 4] = '\0'; - - /* The following should never happen with a proper or honest client. - * Therefore, the error message doesn't have to be too clear - if - * someone is playing with a hacked/non working client, this gives them - * an idea of the problem, but they deserve what they get - */ - if (pl->state != ST_PLAYING) - { - new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf); - return; - } + command[len - 4] = 0; /* This should not happen anymore. */ if (pl->ob->speed_left < -1.0) @@ -834,7 +862,7 @@ packet sl; sl << "comc " << uint16 (pktlen) << uint32 (time); - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); } @@ -1175,7 +1203,7 @@ /* Only send it away if we have some actual data */ if (sl.length () > 6) - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); } /** @@ -1194,7 +1222,7 @@ << uint32 (pl->ob->face->number) << data8 (pl->ob->name); - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } @@ -1236,7 +1264,7 @@ sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ } - Send_With_Handling (ns, &sl); + ns->send_packet (sl); ns->anims_sent[anim_num] = 1; } @@ -1870,11 +1898,11 @@ */ got_one = 0; for (i = oldlen + 2; i < sl.length (); i++) - if (sl.buf[i]) + if (sl[i]) got_one = 1; if (got_one && (mask & 0xf)) - sl.buf[oldlen + 1] = mask & 0xff; + sl[oldlen + 1] = mask & 0xff; else { /*either all faces blank, either no face at all */ if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ @@ -1950,7 +1978,7 @@ } if ((mask & 0xf) || need_send) - sl.buf[oldlen + 1] = mask & 0xff; + sl[oldlen + 1] = mask & 0xff; else sl.reset (oldlen); } @@ -1990,7 +2018,7 @@ if (socket.extmap) { *last_ext |= 0x80; - last_ext = sl.buf + sl.length (); + last_ext = &sl[sl.length ()]; sl << uint8 (d); } else @@ -2034,14 +2062,14 @@ mask |= 0x8; *last_ext |= 0x80; - last_ext = sl.buf + sl.length (); + last_ext = &sl[sl.length ()]; sl << uint8 (5) << uint8 (stat_hp); if (stat_width > 1) { *last_ext |= 0x80; - last_ext = sl.buf + sl.length (); + last_ext = &sl[sl.length ()]; sl << uint8 (6) << uint8 (stat_width); } @@ -2053,7 +2081,7 @@ mask |= 0x8; *last_ext |= 0x80; - last_ext = sl.buf + sl.length (); + last_ext = &sl[sl.length ()]; sl << uint8 (0x47) << uint8 (8) << (uint64)player; } @@ -2064,7 +2092,7 @@ mask |= 0x8; *last_ext |= 0x80; - last_ext = sl.buf + sl.length (); + last_ext = &sl[sl.length ()]; sl << uint8 (8) << uint8 (flags); } @@ -2116,12 +2144,12 @@ * value, so we don't send those bits. */ if (mask & 0xf) - sl.buf[oldlen + 1] = mask & 0xff; + sl[oldlen + 1] = mask & 0xff; else sl.reset (oldlen); if (emask & 0xf) - esl.buf[eoldlen + 1] = emask & 0xff; + esl[eoldlen + 1] = emask & 0xff; else esl.reset (eoldlen); } /* else this is a viewable space */ @@ -2137,16 +2165,16 @@ * it doesn't need draw! */ ewhatflag &= (~EMI_NOREDRAW); - esl.buf[ewhatstart + 1] = ewhatflag & 0xff; + esl[ewhatstart + 1] = ewhatflag & 0xff; } if (esl.length () > estartlen) - Send_With_Handling (&socket, &esl); + socket.send_packet (esl); } if (sl.length () > startlen || socket.sent_scroll) { - Send_With_Handling (&socket, &sl); + socket.send_packet (sl); socket.sent_scroll = 0; } } @@ -2248,7 +2276,7 @@ fatal (0); } - Send_With_Handling (ns, &sl); + ns->send_packet (sl); } /** @@ -2271,7 +2299,7 @@ fatal (0); } - Send_With_Handling (ns, &sl); + ns->send_packet (sl); } /** @@ -2321,7 +2349,7 @@ if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); } } } @@ -2344,7 +2372,7 @@ sl << "delspell " << uint32 (spell->count); - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); } /* appends the spell *spell to the Socklist we will send the data to. */ @@ -2431,7 +2459,7 @@ if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) { - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); sl.reset (); sl << "addspell "; @@ -2455,6 +2483,6 @@ } /* finally, we can send the packet */ - Send_With_Handling (pl->socket, &sl); + pl->socket->send_packet (sl); }