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.183 by root, Sat May 7 20:03:28 2011 UTC vs.
Revision 1.195 by root, Sat Nov 17 23:40:05 2018 UTC

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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * 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 6 * Copyright (©) 2001 Mark Wedel
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25//+GPL 26//+GPL
26 27
28 * \file 29 * \file
29 * Client handling. 30 * Client handling.
30 * 31 *
31 * \date 2003-12-02 32 * \date 2003-12-02
32 * 33 *
33 * This file implements all of the goo on the server side for handling 34 * 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 35 * clients. It's got a bunch of global variables for keeping track of
35 * each of the clients. 36 * each of the clients.
36 * 37 *
37 * Note: All functions that are used to process data from the client 38 * 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 39 * have the prototype of (char *data, int datalen, int client_num). This
39 * way, we can use one dispatch table. 40 * way, we can use one dispatch table.
40 * 41 *
163 if (ob->map && ob->map->path) 164 if (ob->map && ob->map->path)
164 { 165 {
165 int flags = 0; 166 int flags = 0;
166 167
167 // due to historical glitches, the bit ordering and map index ordering differs 168 // due to historical glitches, the bit ordering and map index ordering differs
168 if (ob->map->tile_path[TILE_NORTH]) flags |= 0x01; 169 if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01;
169 if (ob->map->tile_path[TILE_EAST ]) flags |= 0x02; 170 if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02;
170 if (ob->map->tile_path[TILE_SOUTH]) flags |= 0x04; 171 if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04;
171 if (ob->map->tile_path[TILE_WEST ]) flags |= 0x08; 172 if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08;
172 // these two are debatable 173 // these two are debatable
173 if (ob->map->tile_path[TILE_UP ]) flags |= 0x10; 174 if (ob->map->tile_path [TILE_UP ]) flags |= 0x10;
174 if (ob->map->tile_path[TILE_DOWN ]) flags |= 0x20; 175 if (ob->map->tile_path [TILE_DOWN ]) flags |= 0x20;
175 176
176 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", 177 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
177 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, 178 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
178 ob->map->width, ob->map->height, &ob->map->path); 179 ob->map->width, ob->map->height, &ob->map->path);
179 } 180 }
194 { 195 {
195 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); 196 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
196 socket.current_region = reg; 197 socket.current_region = reg;
197 } 198 }
198 199
199 // first try to aovid a full newmap on tiled map scrolls 200 // first try to avoid a full newmap on tiled map scrolls
200 if (socket.current_map != ob->map && !socket.force_newmap) 201 if (socket.current_map != ob->map && !socket.force_newmap)
201 { 202 {
202 rv_vector rv; 203 rv_vector rv;
203 204
204 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); 205 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0);
276 277
277/** 278/**
278 * RequestInfo is sort of a meta command. There is some specific 279 * RequestInfo is sort of a meta command. There is some specific
279 * request of information, but we call other functions to provide 280 * request of information, but we call other functions to provide
280 * that information. 281 * that information.
282 * requestinfo is completely deprecated, use resource exti request
283 * and the fxix or http protocols.
281 */ 284 */
282void 285void
283RequestInfo (char *buf, int len, client *ns) 286RequestInfo (char *buf, int len, client *ns)
284{ 287{
285 char *params; 288 char *params;
349 352
350 // due to historical glitches, the mapinfo index and tile index differs 353 // due to historical glitches, the mapinfo index and tile index differs
351 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN }; 354 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN };
352 355
353 // maybe we should only allow the four flat directions 356 // maybe we should only allow the four flat directions
354 if (dir >= 0 && dir < array_length (dirmap)) 357 if (IN_RANGE_EXC (dir, 0, array_length (dirmap)))
355 { 358 {
356 dir = dirmap [dir]; 359 dir = dirmap [dir];
357 360
358 if (!map->tile_path [dir]) 361 if (!map->tile_path [dir])
359 map = 0; 362 map = 0;
386 else 389 else
387 { 390 {
388 int flags = 0; 391 int flags = 0;
389 392
390 // due to historical glitches, the bit ordering and map index ordering differs 393 // due to historical glitches, the bit ordering and map index ordering differs
391 if (map->tile_path[TILE_NORTH]) flags |= 0x01; 394 if (map->tile_path [TILE_NORTH]) flags |= 0x01;
392 if (map->tile_path[TILE_EAST ]) flags |= 0x02; 395 if (map->tile_path [TILE_EAST ]) flags |= 0x02;
393 if (map->tile_path[TILE_SOUTH]) flags |= 0x04; 396 if (map->tile_path [TILE_SOUTH]) flags |= 0x04;
394 if (map->tile_path[TILE_WEST ]) flags |= 0x08; 397 if (map->tile_path [TILE_WEST ]) flags |= 0x08;
395 // these two are debatable 398 // these two are debatable
396 if (map->tile_path[TILE_UP ]) flags |= 0x10; 399 if (map->tile_path [TILE_UP ]) flags |= 0x10;
397 if (map->tile_path[TILE_DOWN ]) flags |= 0x20; 400 if (map->tile_path [TILE_DOWN ]) flags |= 0x20;
398 401
399 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); 402 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path);
400 } 403 }
401 404
402 return 1; 405 return 1;
494 * Cleaning up the input should probably be done first - all actions 497 * 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 498 * for the command that issued the count should be done before any other
496 * commands. 499 * commands.
497 */ 500 */
498 pl->count = 0; 501 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 */
507void
508NewPlayerCmd (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} 502}
544 503
545/** This is a reply to a previous query. */ 504/** This is a reply to a previous query. */
546void 505void
547ReplyCmd (char *buf, int len, client *ns) 506ReplyCmd (char *buf, int len, client *ns)
886 } 845 }
887 846
888 /* Nothing changed */ 847 /* Nothing changed */
889 return 0; 848 return 0;
890} 849}
891
892//-GPL
893
894// prefetch some flat area around the player
895static void
896prefetch_surrounding_area (object *op, maptile *map, int range)
897{
898 for (maprect *rect = map->split_to_tiles (mapwalk_buf,
899 op->x - range , op->y - range ,
900 op->x + range + 1, op->y + range + 1);
901 rect->m;
902 ++rect)
903 {
904 rect->m->touch ();
905 rect->m->activate ();
906 }
907}
908
909// prefetch a generous area around the player, also up and down
910void
911object::prefetch_surrounding_maps ()
912{
913 prefetch_surrounding_area (this, map, 40);
914
915 if (maptile *m = map->tile_available (TILE_DOWN))
916 prefetch_surrounding_area (this, m, 20);
917
918 if (maptile *m = map->tile_available (TILE_UP))
919 prefetch_surrounding_area (this, m, 20);
920}
921
922//+GPL
923 850
924/** 851/**
925 * Draws client map. 852 * Draws client map.
926 */ 853 */
927void 854void
1014 { 941 {
1015 /* This block deals with spaces that are not visible for whatever 942 /* This block deals with spaces that are not visible for whatever
1016 * reason. Still may need to send the head for this space. 943 * reason. Still may need to send the head for this space.
1017 */ 944 */
1018 if (lastcell.count != -1 945 if (lastcell.count != -1
1019 || lastcell.faces[0] 946 || lastcell.faces[0]
1020 || lastcell.faces[1] 947 || lastcell.faces[1]
1021 || lastcell.faces[2] 948 || lastcell.faces[2]
1022 || lastcell.stat_hp 949 || lastcell.stat_hp
1023 || lastcell.flags 950 || lastcell.flags
1024 || lastcell.player) 951 || lastcell.player)
1025 sl << uint16 (mask); 952 sl << uint16 (mask);
1026 953
1027 /* properly clear a previously sent big face */ 954 /* properly clear a previously sent big face */
1028 map_clearcell (&lastcell, -1); 955 map_clearcell (&lastcell, -1);
1267 1194
1268/* appends the spell *spell to the Socklist we will send the data to. */ 1195/* appends the spell *spell to the Socklist we will send the data to. */
1269static void 1196static void
1270append_spell (player *pl, packet &sl, object *spell) 1197append_spell (player *pl, packet &sl, object *spell)
1271{ 1198{
1272 int i, skill = 0; 1199 int skill = 0;
1273 1200
1274 if (!(spell->name)) 1201 if (!(spell->name))
1275 { 1202 {
1276 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1203 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1277 return; 1204 return;
1304 << uint16 (spell->cached_grace) 1231 << uint16 (spell->cached_grace)
1305 << uint16 (spell->cached_eat) 1232 << uint16 (spell->cached_eat)
1306 << uint8 (skill) 1233 << uint8 (skill)
1307 << uint32 (spell->path_attuned) 1234 << uint32 (spell->path_attuned)
1308 << uint32 (spell->face) 1235 << uint32 (spell->face)
1309 << data8 (spell->name) 1236 << data8 (spell->name);
1237
1238 if (pl->ns->monitor_spells < 2)
1310 << data16 (spell->msg); 1239 sl << data16 (spell->msg);
1311} 1240}
1312 1241
1313/** 1242/**
1314 * This tells the client to add the spell *ob, if *ob is NULL, then add 1243 * This tells the client to add the spell *ob, if *ob is NULL, then add
1315 * all spells in the player's inventory. 1244 * all spells in the player's inventory.
1316 */ 1245 */
1317void 1246void
1318esrv_add_spells (player *pl, object *spell) 1247esrv_add_spells (player *pl, object *spell)
1319{ 1248{
1330 1259
1331 if (!spell) 1260 if (!spell)
1332 { 1261 {
1333 for (spell = pl->ob->inv; spell; spell = spell->below) 1262 for (spell = pl->ob->inv; spell; spell = spell->below)
1334 { 1263 {
1335 /* were we to simply keep appending data here, we could exceed 1264 /* were we to simply keep appending data here, we could exceed
1336 * MAXSOCKBUF if the player has enough spells to add, we know that 1265 * MAXSOCKBUF if the player has enough spells to add, we know that
1337 * append_spells will always append 19 data bytes, plus 4 length 1266 * append_spells will always append 19 data bytes, plus 4 length
1338 * bytes and 3 strings (because that is the spec) so we need to 1267 * bytes and 3 strings (because that is the spec) so we need to
1339 * check that the length of those 3 strings, plus the 23 bytes, 1268 * check that the length of those 3 strings, plus the 23 bytes,
1340 * won't take us over the length limit for the socket, if it does, 1269 * won't take us over the length limit for the socket, if it does,
1341 * we need to send what we already have, and restart packet formation 1270 * we need to send what we already have, and restart packet formation
1342 */ 1271 */
1343 if (spell->type != SPELL) 1272 if (spell->type != SPELL)
1344 continue; 1273 continue;
1345 1274
1346 /* Seeing crashes by overflowed buffers. Quick arithemetic seems 1275 /* Seeing crashes by overflowed buffers. Quick arithemetic seems

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines