1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
5 | * Copyright (©) 2001,2007 Mark Wedel |
5 | * Copyright (©) 2001,2007 Mark Wedel |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
9 | * under the terms of the GNU General Public License as published by the Free |
9 | * it under the terms of the GNU General Public License as published by |
10 | * Software Foundation; either version 2 of the License, or (at your option) |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, but |
13 | * This program is distributed in the hope that it will be useful, |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License along |
18 | * You should have received a copy of the GNU General Public License |
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
20 | * |
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
23 | */ |
22 | */ |
24 | |
23 | |
25 | /** |
24 | /** |
… | |
… | |
191 | socket.current_y = ob->y; |
190 | socket.current_y = ob->y; |
192 | |
191 | |
193 | region *reg = ob->region (); |
192 | region *reg = ob->region (); |
194 | if (socket.current_region != reg) |
193 | if (socket.current_region != reg) |
195 | { |
194 | { |
|
|
195 | INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); |
196 | socket.current_region = reg; |
196 | socket.current_region = reg; |
197 | socket.send_packet_printf ("drawinfo 0 You are now %s.\n(use whereami for more details)", ®->longname); |
|
|
198 | } |
197 | } |
199 | } |
198 | } |
200 | |
199 | |
201 | /** |
200 | /** |
202 | * RequestInfo is sort of a meta command. There is some specific |
201 | * RequestInfo is sort of a meta command. There is some specific |
203 | * request of information, but we call other functions to provide |
202 | * request of information, but we call other functions to provide |
204 | * that information. |
203 | * that information. |
205 | */ |
204 | */ |
206 | void |
205 | void |
207 | RequestInfo (char *buf, int len, client * ns) |
206 | RequestInfo (char *buf, int len, client *ns) |
208 | { |
207 | { |
209 | char *params = NULL, *cp; |
208 | char *params; |
210 | |
|
|
211 | /* No match */ |
|
|
212 | char bigbuf[MAX_BUF]; |
|
|
213 | int slen; |
|
|
214 | |
|
|
215 | /* Set up replyinfo before we modify any of the buffers - this is used |
|
|
216 | * if we don't find a match. |
|
|
217 | */ |
|
|
218 | strcpy (bigbuf, "replyinfo "); |
|
|
219 | slen = strlen (bigbuf); |
|
|
220 | safe_strcat (bigbuf, buf, &slen, MAX_BUF); |
|
|
221 | |
209 | |
222 | /* find the first space, make it null, and update the |
210 | /* find the first space, make it null, and update the |
223 | * params pointer. |
211 | * params pointer. |
224 | */ |
212 | */ |
225 | for (cp = buf; *cp != '\0'; cp++) |
213 | for (params = buf; *params; params++) |
226 | if (*cp == ' ') |
214 | if (*params == ' ') |
227 | { |
215 | { |
228 | *cp = '\0'; |
|
|
229 | params = cp + 1; |
216 | *params++ = 0; |
230 | break; |
217 | break; |
231 | } |
218 | } |
232 | |
219 | |
233 | if (!strcmp (buf, "image_info")) |
220 | if (!strcmp (buf, "image_info")) |
234 | send_image_info (ns, params); |
221 | send_image_info (ns, params); |
… | |
… | |
237 | else if (!strcmp (buf, "skill_info")) |
224 | else if (!strcmp (buf, "skill_info")) |
238 | send_skill_info (ns, params); |
225 | send_skill_info (ns, params); |
239 | else if (!strcmp (buf, "spell_paths")) |
226 | else if (!strcmp (buf, "spell_paths")) |
240 | send_spell_paths (ns, params); |
227 | send_spell_paths (ns, params); |
241 | else |
228 | else |
242 | ns->send_packet (bigbuf, len); |
229 | { |
|
|
230 | // undo tokenisation above and send replyinfo with the request unchanged |
|
|
231 | if (*params) |
|
|
232 | *--params = ' '; |
|
|
233 | |
|
|
234 | ns->send_packet_printf ("replyinfo %s", buf); |
|
|
235 | } |
243 | } |
236 | } |
244 | |
237 | |
245 | void |
238 | void |
246 | ExtCmd (char *buf, int len, player *pl) |
239 | ExtCmd (char *buf, int len, player *pl) |
247 | { |
240 | { |
… | |
… | |
512 | void |
505 | void |
513 | NewPlayerCmd (char *buf, int len, player *pl) |
506 | NewPlayerCmd (char *buf, int len, player *pl) |
514 | { |
507 | { |
515 | if (len <= 6) |
508 | if (len <= 6) |
516 | { |
509 | { |
517 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
510 | LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len); |
518 | return; |
511 | return; |
519 | } |
512 | } |
520 | |
513 | |
521 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
514 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
522 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
515 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
… | |
… | |
938 | |
931 | |
939 | if (!ns.faces_sent[face_num]) |
932 | if (!ns.faces_sent[face_num]) |
940 | if (ob) |
933 | if (ob) |
941 | ns.send_faces (ob); |
934 | ns.send_faces (ob); |
942 | else |
935 | else |
943 | ns.send_face (face_num); |
936 | ns.send_face (face_num, 10); |
944 | |
937 | |
945 | sl << uint16 (face_num); |
938 | sl << uint16 (face_num); |
946 | return 1; |
939 | return 1; |
947 | } |
940 | } |
948 | |
941 | |
… | |
… | |
1537 | { |
1530 | { |
1538 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1531 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1539 | spell->face = face_find ("burnout.x11", blank_face); |
1532 | spell->face = face_find ("burnout.x11", blank_face); |
1540 | } |
1533 | } |
1541 | |
1534 | |
|
|
1535 | pl->ns->send_face (spell->face); |
|
|
1536 | |
1542 | /* send the current values */ |
1537 | /* send the current values */ |
1543 | sl << uint32 (spell->count) |
1538 | sl << uint32 (spell->count) |
1544 | << uint16 (spell->level) |
1539 | << uint16 (spell->level) |
1545 | << uint16 (spell->casting_time) |
1540 | << uint16 (spell->casting_time) |
1546 | << uint16 (spell->last_sp) |
1541 | << uint16 (spell->last_sp) |
… | |
… | |
1581 | * bytes and 3 strings (because that is the spec) so we need to |
1576 | * bytes and 3 strings (because that is the spec) so we need to |
1582 | * check that the length of those 3 strings, plus the 23 bytes, |
1577 | * check that the length of those 3 strings, plus the 23 bytes, |
1583 | * won't take us over the length limit for the socket, if it does, |
1578 | * won't take us over the length limit for the socket, if it does, |
1584 | * we need to send what we already have, and restart packet formation |
1579 | * we need to send what we already have, and restart packet formation |
1585 | */ |
1580 | */ |
|
|
1581 | if (spell->type != SPELL) |
|
|
1582 | continue; |
|
|
1583 | |
1586 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
1584 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
1587 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
1585 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
1588 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
1586 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
1589 | * like it will fix this |
1587 | * like it will fix this |
1590 | */ |
1588 | */ |
1591 | if (spell->type != SPELL) |
|
|
1592 | continue; |
|
|
1593 | |
|
|
1594 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
1589 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
1595 | { |
1590 | { |
|
|
1591 | pl->ns->flush_fx (); |
1596 | pl->ns->send_packet (sl); |
1592 | pl->ns->send_packet (sl); |
1597 | |
1593 | |
1598 | sl.reset (); |
1594 | sl.reset (); |
1599 | sl << "addspell "; |
1595 | sl << "addspell "; |
1600 | } |
1596 | } |
… | |
… | |
1615 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1611 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1616 | fatal (0); |
1612 | fatal (0); |
1617 | } |
1613 | } |
1618 | |
1614 | |
1619 | /* finally, we can send the packet */ |
1615 | /* finally, we can send the packet */ |
|
|
1616 | pl->ns->flush_fx (); |
1620 | pl->ns->send_packet (sl); |
1617 | pl->ns->send_packet (sl); |
1621 | } |
1618 | } |
1622 | |
1619 | |