1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel |
5 | * Copyright (©) 2001 Mark Wedel |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
28 | * \file |
28 | * \file |
29 | * Client handling. |
29 | * Client handling. |
30 | * |
30 | * |
31 | * \date 2003-12-02 |
31 | * \date 2003-12-02 |
32 | * |
32 | * |
33 | * This file implements all of the goo on the server side for handling |
33 | * This file implements all of the goo on the server side for handling |
34 | * clients. It's got a bunch of global variables for keeping track of |
34 | * clients. It's got a bunch of global variables for keeping track of |
35 | * each of the clients. |
35 | * each of the clients. |
36 | * |
36 | * |
37 | * Note: All functions that are used to process data from the client |
37 | * Note: All functions that are used to process data from the client |
38 | * have the prototype of (char *data, int datalen, int client_num). This |
38 | * have the prototype of (char *data, int datalen, int client_num). This |
39 | * way, we can use one dispatch table. |
39 | * way, we can use one dispatch table. |
40 | * |
40 | * |
… | |
… | |
276 | |
276 | |
277 | /** |
277 | /** |
278 | * RequestInfo is sort of a meta command. There is some specific |
278 | * RequestInfo is sort of a meta command. There is some specific |
279 | * request of information, but we call other functions to provide |
279 | * request of information, but we call other functions to provide |
280 | * that information. |
280 | * that information. |
|
|
281 | * requestinfo is completely deprecated, use resource exti request |
|
|
282 | * and the fxix or http protocols. |
281 | */ |
283 | */ |
282 | void |
284 | void |
283 | RequestInfo (char *buf, int len, client *ns) |
285 | RequestInfo (char *buf, int len, client *ns) |
284 | { |
286 | { |
285 | char *params; |
287 | char *params; |
… | |
… | |
494 | * Cleaning up the input should probably be done first - all actions |
496 | * Cleaning up the input should probably be done first - all actions |
495 | * for the command that issued the count should be done before any other |
497 | * for the command that issued the count should be done before any other |
496 | * commands. |
498 | * commands. |
497 | */ |
499 | */ |
498 | pl->count = 0; |
500 | pl->count = 0; |
499 | } |
|
|
500 | |
|
|
501 | /** |
|
|
502 | * This handles the general commands from the client (ie, north, fire, cast, |
|
|
503 | * etc.). It is a lot like PlayerCmd above, but is called with the |
|
|
504 | * 'ncom' method which gives more information back to the client so it |
|
|
505 | * can throttle. |
|
|
506 | */ |
|
|
507 | void |
|
|
508 | NewPlayerCmd (char *buf, int len, player *pl) |
|
|
509 | { |
|
|
510 | if (len <= 6) |
|
|
511 | { |
|
|
512 | LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len); |
|
|
513 | return; |
|
|
514 | } |
|
|
515 | |
|
|
516 | uint16 cmdid = net_uint16 ((uint8 *)buf); |
|
|
517 | sint32 repeat = net_sint32 ((uint8 *)buf + 2); |
|
|
518 | |
|
|
519 | /* -1 is special - no repeat, but don't update */ |
|
|
520 | if (repeat != -1) |
|
|
521 | pl->count = repeat; |
|
|
522 | |
|
|
523 | buf += 6; //len -= 6; |
|
|
524 | |
|
|
525 | execute_newserver_command (pl->ob, buf); |
|
|
526 | |
|
|
527 | /* Perhaps something better should be done with a left over count. |
|
|
528 | * Cleaning up the input should probably be done first - all actions |
|
|
529 | * for the command that issued the count should be done before any other |
|
|
530 | * commands. |
|
|
531 | */ |
|
|
532 | pl->count = 0; |
|
|
533 | |
|
|
534 | //TODO: schmorp thinks whatever this calculates, it makes no sense at all |
|
|
535 | int time = pl->ob->has_active_speed () |
|
|
536 | ? (int) (MAX_TIME / pl->ob->speed) |
|
|
537 | : MAX_TIME * 100; |
|
|
538 | |
|
|
539 | /* Send confirmation of command execution now */ |
|
|
540 | packet sl ("comc"); |
|
|
541 | sl << uint16 (cmdid) << uint32 (time); |
|
|
542 | pl->ns->send_packet (sl); |
|
|
543 | } |
501 | } |
544 | |
502 | |
545 | /** This is a reply to a previous query. */ |
503 | /** This is a reply to a previous query. */ |
546 | void |
504 | void |
547 | ReplyCmd (char *buf, int len, client *ns) |
505 | ReplyCmd (char *buf, int len, client *ns) |
… | |
… | |
982 | { |
940 | { |
983 | /* This block deals with spaces that are not visible for whatever |
941 | /* This block deals with spaces that are not visible for whatever |
984 | * reason. Still may need to send the head for this space. |
942 | * reason. Still may need to send the head for this space. |
985 | */ |
943 | */ |
986 | if (lastcell.count != -1 |
944 | if (lastcell.count != -1 |
987 | || lastcell.faces[0] |
945 | || lastcell.faces[0] |
988 | || lastcell.faces[1] |
946 | || lastcell.faces[1] |
989 | || lastcell.faces[2] |
947 | || lastcell.faces[2] |
990 | || lastcell.stat_hp |
948 | || lastcell.stat_hp |
991 | || lastcell.flags |
949 | || lastcell.flags |
992 | || lastcell.player) |
950 | || lastcell.player) |
993 | sl << uint16 (mask); |
951 | sl << uint16 (mask); |
994 | |
952 | |
995 | /* properly clear a previously sent big face */ |
953 | /* properly clear a previously sent big face */ |
996 | map_clearcell (&lastcell, -1); |
954 | map_clearcell (&lastcell, -1); |
… | |
… | |
1272 | << uint16 (spell->cached_grace) |
1230 | << uint16 (spell->cached_grace) |
1273 | << uint16 (spell->cached_eat) |
1231 | << uint16 (spell->cached_eat) |
1274 | << uint8 (skill) |
1232 | << uint8 (skill) |
1275 | << uint32 (spell->path_attuned) |
1233 | << uint32 (spell->path_attuned) |
1276 | << uint32 (spell->face) |
1234 | << uint32 (spell->face) |
1277 | << data8 (spell->name) |
1235 | << data8 (spell->name); |
|
|
1236 | |
|
|
1237 | if (pl->ns->monitor_spells < 2) |
1278 | << data16 (spell->msg); |
1238 | sl << data16 (spell->msg); |
1279 | } |
1239 | } |
1280 | |
1240 | |
1281 | /** |
1241 | /** |
1282 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
1242 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
1283 | * all spells in the player's inventory. |
1243 | * all spells in the player's inventory. |
1284 | */ |
1244 | */ |
1285 | void |
1245 | void |
1286 | esrv_add_spells (player *pl, object *spell) |
1246 | esrv_add_spells (player *pl, object *spell) |
1287 | { |
1247 | { |
… | |
… | |
1298 | |
1258 | |
1299 | if (!spell) |
1259 | if (!spell) |
1300 | { |
1260 | { |
1301 | for (spell = pl->ob->inv; spell; spell = spell->below) |
1261 | for (spell = pl->ob->inv; spell; spell = spell->below) |
1302 | { |
1262 | { |
1303 | /* were we to simply keep appending data here, we could exceed |
1263 | /* were we to simply keep appending data here, we could exceed |
1304 | * MAXSOCKBUF if the player has enough spells to add, we know that |
1264 | * MAXSOCKBUF if the player has enough spells to add, we know that |
1305 | * append_spells will always append 19 data bytes, plus 4 length |
1265 | * append_spells will always append 19 data bytes, plus 4 length |
1306 | * bytes and 3 strings (because that is the spec) so we need to |
1266 | * bytes and 3 strings (because that is the spec) so we need to |
1307 | * check that the length of those 3 strings, plus the 23 bytes, |
1267 | * check that the length of those 3 strings, plus the 23 bytes, |
1308 | * won't take us over the length limit for the socket, if it does, |
1268 | * won't take us over the length limit for the socket, if it does, |
1309 | * we need to send what we already have, and restart packet formation |
1269 | * we need to send what we already have, and restart packet formation |
1310 | */ |
1270 | */ |
1311 | if (spell->type != SPELL) |
1271 | if (spell->type != SPELL) |
1312 | continue; |
1272 | continue; |
1313 | |
1273 | |
1314 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
1274 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |