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.181 by root, Wed May 4 07:41:14 2011 UTC vs.
Revision 1.196 by root, Sun Nov 18 00:37:11 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 *
158 client &socket = *pl->ns; 159 client &socket = *pl->ns;
159 object *ob = pl->viewpoint; 160 object *ob = pl->viewpoint;
160 161
161 if (socket.mapinfocmd) 162 if (socket.mapinfocmd)
162 { 163 {
163 if (ob->map && ob->map->path[0]) 164 if (ob->map && ob->map->path)
164 { 165 {
165 int flags = 0; 166 int flags = 0;
166 167
168 // due to historical glitches, the bit ordering and map index ordering differs
167 if (ob->map->tile_path[0]) flags |= 0x01; 169 if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01;
168 if (ob->map->tile_path[1]) flags |= 0x02; 170 if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02;
169 if (ob->map->tile_path[2]) flags |= 0x04; 171 if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04;
170 if (ob->map->tile_path[3]) flags |= 0x08; 172 if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08;
171 // these two are debatable 173 // these two are debatable
172 if (ob->map->tile_path[4]) flags |= 0x10; 174 if (ob->map->tile_path [TILE_UP ]) flags |= 0x10;
173 if (ob->map->tile_path[5]) flags |= 0x20; 175 if (ob->map->tile_path [TILE_DOWN ]) flags |= 0x20;
174 176
175 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",
176 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, 178 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
177 ob->map->width, ob->map->height, &ob->map->path); 179 ob->map->width, ob->map->height, &ob->map->path);
178 } 180 }
193 { 195 {
194 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));
195 socket.current_region = reg; 197 socket.current_region = reg;
196 } 198 }
197 199
198 // first try to aovid a full newmap on tiled map scrolls 200 // first try to avoid a full newmap on tiled map scrolls
199 if (socket.current_map != ob->map && !socket.force_newmap) 201 if (socket.current_map != ob->map && !socket.force_newmap)
200 { 202 {
201 rv_vector rv; 203 rv_vector rv;
202 204
203 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);
275 277
276/** 278/**
277 * RequestInfo is sort of a meta command. There is some specific 279 * RequestInfo is sort of a meta command. There is some specific
278 * request of information, but we call other functions to provide 280 * request of information, but we call other functions to provide
279 * that information. 281 * that information.
282 * requestinfo is completely deprecated, use resource exti request
283 * and the fxix or http protocols.
280 */ 284 */
281void 285void
282RequestInfo (char *buf, int len, client *ns) 286RequestInfo (char *buf, int len, client *ns)
283{ 287{
284 char *params; 288 char *params;
322//-GPL 326//-GPL
323 327
324void 328void
325client::mapinfo_queue_clear () 329client::mapinfo_queue_clear ()
326{ 330{
327 for (auto (i, mapinfo_queue.begin ()); i != mapinfo_queue.end (); ++i) 331 for (auto &&i : mapinfo_queue)
328 free (*i); 332 free (i);
329 333
330 mapinfo_queue.clear (); 334 mapinfo_queue.clear ();
331} 335}
332 336
333bool 337bool
344 348
345 while (*buf && map && max_distance) 349 while (*buf && map && max_distance)
346 { 350 {
347 int dir = *buf++ - '1'; 351 int dir = *buf++ - '1';
348 352
353 // due to historical glitches, the mapinfo index and tile index differs
354 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN };
355
349 // maybe we should only allow the four flat directions 356 // maybe we should only allow the four flat directions
350 if (dir >= 0 && dir < TILE_NUM) 357 if (IN_RANGE_EXC (dir, 0, array_length (dirmap)))
351 { 358 {
359 dir = dirmap [dir];
360
352 if (!map->tile_path [dir]) 361 if (!map->tile_path [dir])
353 map = 0; 362 map = 0;
354 else if (map->tile_available (dir, false)) 363 else if (map->tile_available (dir, false))
355 { 364 {
356 maptile *neigh = map->tile_map [dir]; 365 maptile *neigh = map->tile_map [dir];
379 send_packet_printf ("mapinfo %s nomap", token); 388 send_packet_printf ("mapinfo %s nomap", token);
380 else 389 else
381 { 390 {
382 int flags = 0; 391 int flags = 0;
383 392
393 // due to historical glitches, the bit ordering and map index ordering differs
384 if (map->tile_path[0]) flags |= 0x01; 394 if (map->tile_path [TILE_NORTH]) flags |= 0x01;
385 if (map->tile_path[1]) flags |= 0x02; 395 if (map->tile_path [TILE_EAST ]) flags |= 0x02;
386 if (map->tile_path[2]) flags |= 0x04; 396 if (map->tile_path [TILE_SOUTH]) flags |= 0x04;
387 if (map->tile_path[3]) flags |= 0x08; 397 if (map->tile_path [TILE_WEST ]) flags |= 0x08;
388 // these two are debatable 398 // these two are debatable
389 if (map->tile_path[4]) flags |= 0x10; 399 if (map->tile_path [TILE_UP ]) flags |= 0x10;
390 if (map->tile_path[5]) flags |= 0x20; 400 if (map->tile_path [TILE_DOWN ]) flags |= 0x20;
391 401
392 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);
393 } 403 }
394 404
395 return 1; 405 return 1;
487 * Cleaning up the input should probably be done first - all actions 497 * Cleaning up the input should probably be done first - all actions
488 * 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
489 * commands. 499 * commands.
490 */ 500 */
491 pl->count = 0; 501 pl->count = 0;
492}
493
494/**
495 * This handles the general commands from the client (ie, north, fire, cast,
496 * etc.). It is a lot like PlayerCmd above, but is called with the
497 * 'ncom' method which gives more information back to the client so it
498 * can throttle.
499 */
500void
501NewPlayerCmd (char *buf, int len, player *pl)
502{
503 if (len <= 6)
504 {
505 LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len);
506 return;
507 }
508
509 uint16 cmdid = net_uint16 ((uint8 *)buf);
510 sint32 repeat = net_sint32 ((uint8 *)buf + 2);
511
512 /* -1 is special - no repeat, but don't update */
513 if (repeat != -1)
514 pl->count = repeat;
515
516 buf += 6; //len -= 6;
517
518 execute_newserver_command (pl->ob, buf);
519
520 /* Perhaps something better should be done with a left over count.
521 * Cleaning up the input should probably be done first - all actions
522 * for the command that issued the count should be done before any other
523 * commands.
524 */
525 pl->count = 0;
526
527 //TODO: schmorp thinks whatever this calculates, it makes no sense at all
528 int time = pl->ob->has_active_speed ()
529 ? (int) (MAX_TIME / pl->ob->speed)
530 : MAX_TIME * 100;
531
532 /* Send confirmation of command execution now */
533 packet sl ("comc");
534 sl << uint16 (cmdid) << uint32 (time);
535 pl->ns->send_packet (sl);
536} 502}
537 503
538/** This is a reply to a previous query. */ 504/** This is a reply to a previous query. */
539void 505void
540ReplyCmd (char *buf, int len, client *ns) 506ReplyCmd (char *buf, int len, client *ns)
879 } 845 }
880 846
881 /* Nothing changed */ 847 /* Nothing changed */
882 return 0; 848 return 0;
883} 849}
884
885//-GPL
886
887// prefetch some flat area around the player
888static void
889prefetch_surrounding_area (object *op, maptile *map, int range)
890{
891 for (maprect *rect = map->split_to_tiles (mapwalk_buf,
892 op->x - range , op->y - range ,
893 op->x + range + 1, op->y + range + 1);
894 rect->m;
895 ++rect)
896 {
897 rect->m->touch ();
898 rect->m->activate ();
899 }
900}
901
902// prefetch a generous area around the player, also up and down
903void
904object::prefetch_surrounding_maps ()
905{
906 prefetch_surrounding_area (this, map, 40);
907
908 if (maptile *m = map->tile_available (TILE_DOWN))
909 prefetch_surrounding_area (this, m, 20);
910
911 if (maptile *m = map->tile_available (TILE_UP))
912 prefetch_surrounding_area (this, m, 20);
913}
914
915//+GPL
916 850
917/** 851/**
918 * Draws client map. 852 * Draws client map.
919 */ 853 */
920void 854void
1007 { 941 {
1008 /* This block deals with spaces that are not visible for whatever 942 /* This block deals with spaces that are not visible for whatever
1009 * reason. Still may need to send the head for this space. 943 * reason. Still may need to send the head for this space.
1010 */ 944 */
1011 if (lastcell.count != -1 945 if (lastcell.count != -1
1012 || lastcell.faces[0] 946 || lastcell.faces[0]
1013 || lastcell.faces[1] 947 || lastcell.faces[1]
1014 || lastcell.faces[2] 948 || lastcell.faces[2]
1015 || lastcell.stat_hp 949 || lastcell.stat_hp
1016 || lastcell.flags 950 || lastcell.flags
1017 || lastcell.player) 951 || lastcell.player)
1018 sl << uint16 (mask); 952 sl << uint16 (mask);
1019 953
1020 /* properly clear a previously sent big face */ 954 /* properly clear a previously sent big face */
1021 map_clearcell (&lastcell, -1); 955 map_clearcell (&lastcell, -1);
1260 1194
1261/* 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. */
1262static void 1196static void
1263append_spell (player *pl, packet &sl, object *spell) 1197append_spell (player *pl, packet &sl, object *spell)
1264{ 1198{
1265 int i, skill = 0; 1199 int skill = 0;
1266 1200
1267 if (!(spell->name)) 1201 if (!(spell->name))
1268 { 1202 {
1269 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);
1270 return; 1204 return;
1297 << uint16 (spell->cached_grace) 1231 << uint16 (spell->cached_grace)
1298 << uint16 (spell->cached_eat) 1232 << uint16 (spell->cached_eat)
1299 << uint8 (skill) 1233 << uint8 (skill)
1300 << uint32 (spell->path_attuned) 1234 << uint32 (spell->path_attuned)
1301 << uint32 (spell->face) 1235 << uint32 (spell->face)
1302 << data8 (spell->name) 1236 << data8 (spell->name);
1237
1238 if (pl->ns->monitor_spells < 2)
1303 << data16 (spell->msg); 1239 sl << data16 (spell->msg);
1304} 1240}
1305 1241
1306/** 1242/**
1307 * 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
1308 * all spells in the player's inventory. 1244 * all spells in the player's inventory.
1309 */ 1245 */
1310void 1246void
1311esrv_add_spells (player *pl, object *spell) 1247esrv_add_spells (player *pl, object *spell)
1312{ 1248{
1323 1259
1324 if (!spell) 1260 if (!spell)
1325 { 1261 {
1326 for (spell = pl->ob->inv; spell; spell = spell->below) 1262 for (spell = pl->ob->inv; spell; spell = spell->below)
1327 { 1263 {
1328 /* were we to simply keep appending data here, we could exceed 1264 /* were we to simply keep appending data here, we could exceed
1329 * 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
1330 * append_spells will always append 19 data bytes, plus 4 length 1266 * append_spells will always append 19 data bytes, plus 4 length
1331 * 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
1332 * 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,
1333 * 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,
1334 * 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
1335 */ 1271 */
1336 if (spell->type != SPELL) 1272 if (spell->type != SPELL)
1337 continue; 1273 continue;
1338 1274
1339 /* 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