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.173 by root, Thu Apr 15 00:37:24 2010 UTC vs.
Revision 1.197 by root, Sat Dec 1 20:22:13 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 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 *
146 pl->ns->mapinfo_queue_clear (); 147 pl->ns->mapinfo_queue_clear ();
147 148
148 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); 149 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap));
149 150
150 pl->ns->force_newmap = false; 151 pl->ns->force_newmap = false;
151
152 if (pl->ns->newmapcmd == 1)
153 pl->ns->send_packet ("newmap"); 152 pl->ns->send_packet ("newmap");
154
155 pl->ns->floorbox_reset (); 153 pl->ns->floorbox_reset ();
156} 154}
157 155
158static void 156static void
159send_map_info (player *pl) 157send_map_info (player *pl)
161 client &socket = *pl->ns; 159 client &socket = *pl->ns;
162 object *ob = pl->viewpoint; 160 object *ob = pl->viewpoint;
163 161
164 if (socket.mapinfocmd) 162 if (socket.mapinfocmd)
165 { 163 {
166 if (ob->map && ob->map->path[0]) 164 if (ob->map && ob->map->path)
167 { 165 {
168 int flags = 0; 166 int flags = 0;
169 167
168 // due to historical glitches, the bit ordering and map index ordering differs
170 if (ob->map->tile_path[0]) flags |= 1; 169 if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01;
171 if (ob->map->tile_path[1]) flags |= 2; 170 if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02;
172 if (ob->map->tile_path[2]) flags |= 4; 171 if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04;
173 if (ob->map->tile_path[3]) flags |= 8; 172 if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08;
173 // these two are debatable
174 if (ob->map->tile_path [TILE_UP ]) flags |= 0x10;
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);
246 248
247 for (int i = 0; i < skillvec.size (); ++i) 249 for (int i = 0; i < skillvec.size (); ++i)
248 sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); 250 sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name);
249 251
250 if (sl.length () > MAXSOCKBUF) 252 if (sl.length () > MAXSOCKBUF)
251 {
252 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 253 cleanup ("buffer overflow in send_skill_info!");
253 fatal (0);
254 }
255 254
256 ns->send_packet (sl); 255 ns->send_packet (sl);
257} 256}
258 257
259/** 258/**
269 268
270 for (int i = 0; i < NRSPELLPATHS; i++) 269 for (int i = 0; i < NRSPELLPATHS; i++)
271 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); 270 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
272 271
273 if (sl.length () > MAXSOCKBUF) 272 if (sl.length () > MAXSOCKBUF)
274 {
275 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 273 cleanup ("buffer overflow in send_spell_paths!");
276 fatal (0);
277 }
278 274
279 ns->send_packet (sl); 275 ns->send_packet (sl);
280} 276}
281 277
282/** 278/**
283 * RequestInfo is sort of a meta command. There is some specific 279 * RequestInfo is sort of a meta command. There is some specific
284 * request of information, but we call other functions to provide 280 * request of information, but we call other functions to provide
285 * that information. 281 * that information.
282 * requestinfo is completely deprecated, use resource exti request
283 * and the fxix or http protocols.
286 */ 284 */
287void 285void
288RequestInfo (char *buf, int len, client *ns) 286RequestInfo (char *buf, int len, client *ns)
289{ 287{
290 char *params; 288 char *params;
328//-GPL 326//-GPL
329 327
330void 328void
331client::mapinfo_queue_clear () 329client::mapinfo_queue_clear ()
332{ 330{
333 for (auto (i, mapinfo_queue.begin ()); i != mapinfo_queue.end (); ++i) 331 for (auto &&i : mapinfo_queue)
334 free (*i); 332 free (i);
335 333
336 mapinfo_queue.clear (); 334 mapinfo_queue.clear ();
337} 335}
338 336
339bool 337bool
350 348
351 while (*buf && map && max_distance) 349 while (*buf && map && max_distance)
352 { 350 {
353 int dir = *buf++ - '1'; 351 int dir = *buf++ - '1';
354 352
355 if (dir >= 0 && dir <= 3) 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
356 // maybe we should only allow the four flat directions
357 if (IN_RANGE_EXC (dir, 0, ecb_array_length (dirmap)))
356 { 358 {
359 dir = dirmap [dir];
360
357 if (!map->tile_path [dir]) 361 if (!map->tile_path [dir])
358 map = 0; 362 map = 0;
359 else if (map->tile_available (dir, false)) 363 else if (map->tile_available (dir, false))
360 { 364 {
361 maptile *neigh = map->tile_map [dir]; 365 maptile *neigh = map->tile_map [dir];
384 send_packet_printf ("mapinfo %s nomap", token); 388 send_packet_printf ("mapinfo %s nomap", token);
385 else 389 else
386 { 390 {
387 int flags = 0; 391 int flags = 0;
388 392
393 // due to historical glitches, the bit ordering and map index ordering differs
389 if (map->tile_path[0]) flags |= 1; 394 if (map->tile_path [TILE_NORTH]) flags |= 0x01;
390 if (map->tile_path[1]) flags |= 2; 395 if (map->tile_path [TILE_EAST ]) flags |= 0x02;
391 if (map->tile_path[2]) flags |= 4; 396 if (map->tile_path [TILE_SOUTH]) flags |= 0x04;
392 if (map->tile_path[3]) flags |= 8; 397 if (map->tile_path [TILE_WEST ]) flags |= 0x08;
398 // these two are debatable
399 if (map->tile_path [TILE_UP ]) flags |= 0x10;
400 if (map->tile_path [TILE_DOWN ]) flags |= 0x20;
393 401
394 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);
395 } 403 }
396 404
397 return 1; 405 return 1;
489 * Cleaning up the input should probably be done first - all actions 497 * Cleaning up the input should probably be done first - all actions
490 * 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
491 * commands. 499 * commands.
492 */ 500 */
493 pl->count = 0; 501 pl->count = 0;
494}
495
496/**
497 * This handles the general commands from the client (ie, north, fire, cast,
498 * etc.). It is a lot like PlayerCmd above, but is called with the
499 * 'ncom' method which gives more information back to the client so it
500 * can throttle.
501 */
502void
503NewPlayerCmd (char *buf, int len, player *pl)
504{
505 if (len <= 6)
506 {
507 LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len);
508 return;
509 }
510
511 uint16 cmdid = net_uint16 ((uint8 *)buf);
512 sint32 repeat = net_sint32 ((uint8 *)buf + 2);
513
514 /* -1 is special - no repeat, but don't update */
515 if (repeat != -1)
516 pl->count = repeat;
517
518 buf += 6; //len -= 6;
519
520 execute_newserver_command (pl->ob, buf);
521
522 /* Perhaps something better should be done with a left over count.
523 * Cleaning up the input should probably be done first - all actions
524 * for the command that issued the count should be done before any other
525 * commands.
526 */
527 pl->count = 0;
528
529 //TODO: schmorp thinks whatever this calculates, it makes no sense at all
530 int time = pl->ob->has_active_speed ()
531 ? (int) (MAX_TIME / pl->ob->speed)
532 : MAX_TIME * 100;
533
534 /* Send confirmation of command execution now */
535 packet sl ("comc");
536 sl << uint16 (cmdid) << uint32 (time);
537 pl->ns->send_packet (sl);
538} 502}
539 503
540/** This is a reply to a previous query. */ 504/** This is a reply to a previous query. */
541void 505void
542ReplyCmd (char *buf, int len, client *ns) 506ReplyCmd (char *buf, int len, client *ns)
711 * commands for now. 675 * commands for now.
712 */ 676 */
713void 677void
714esrv_update_stats (player *pl) 678esrv_update_stats (player *pl)
715{ 679{
716 char buf[MAX_BUF];
717 uint16 flags;
718
719 client *ns = pl->ns; 680 client *ns = pl->ns;
720 if (!ns) 681 if (!ns)
721 return; 682 return;
722 683
723 object *ob = pl->observe; 684 object *ob = pl->observe;
764 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); 725 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK);
765 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); 726 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD);
766 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); 727 AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK);
767 AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); 728 AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM);
768 729
769 flags = (opl->fire_on ? SF_FIREON : 0) 730 int flags = (opl->fire_on ? SF_FIREON : 0)
770 | (opl->run_on ? SF_RUNON : 0); 731 | (opl->run_on ? SF_RUNON : 0);
771 732
772 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); 733 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
773 734
774 for (int i = 0; i < NROFATTACKS; i++) 735 for (int i = 0; i < NROFATTACKS; i++)
775 /* Skip ones we won't send */ 736 /* Skip ones we won't send */
781 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); 742 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE);
782 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); 743 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL);
783 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); 744 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY);
784 } 745 }
785 746
747 char buf[MAX_BUF];
786 rangetostring (opl, buf); /* we want use the new fire & run system in new client */ 748 rangetostring (opl, buf); /* we want use the new fire & run system in new client */
787 AddIfString (ns->stats.range, buf, CS_STAT_RANGE); 749 AddIfString (ns->stats.range, buf, CS_STAT_RANGE);
788 set_title (ob, buf); 750 set_title (ob, buf);
789 AddIfString (ns->stats.title, buf, CS_STAT_TITLE); 751 AddIfString (ns->stats.title, buf, CS_STAT_TITLE);
790 752
884 846
885 /* Nothing changed */ 847 /* Nothing changed */
886 return 0; 848 return 0;
887} 849}
888 850
889//-GPL
890
891// prefetch (and touch) all maps within a specific distancd
892static void
893prefetch_surrounding_maps (maptile *map, int distance)
894{
895 map->touch ();
896
897 if (--distance)
898 for (int dir = 4; dir--; )
899 if (const shstr &path = map->tile_path [dir])
900 if (maptile *&neigh = map->tile_map [dir])
901 prefetch_surrounding_maps (neigh, distance);
902 else
903 neigh = maptile::find_async (path, map);
904}
905
906// prefetch a generous area around the player
907static void
908prefetch_surrounding_maps (object *op)
909{
910 prefetch_surrounding_maps (op->map, 3);
911}
912
913//+GPL
914
915/** 851/**
916 * Draws client map. 852 * Draws client map.
917 */ 853 */
918void 854void
919draw_client_map (player *pl) 855draw_client_map (player *pl)
924 860
925 /* If player is just joining the game, he isn't here yet, so the map 861 /* If player is just joining the game, he isn't here yet, so the map
926 * can get swapped out. If so, don't try to send them a map. All will 862 * can get swapped out. If so, don't try to send them a map. All will
927 * be OK once they really log in. 863 * be OK once they really log in.
928 */ 864 */
929 if (!ob->map || ob->map->in_memory != MAP_ACTIVE) 865 if (!ob->map || ob->map->state != MAP_ACTIVE)
930 return; 866 return;
931 867
932 int startlen, oldlen; 868 int startlen, oldlen;
933 869
934 check_map_change (pl); 870 check_map_change (pl);
935 prefetch_surrounding_maps (pl->ob); 871 pl->ob->prefetch_surrounding_maps ();
936 872
937 /* do LOS after calls to update_position */ 873 /* do LOS after calls to update_position */
938 /* unfortunately, we need to udpate los when observing, currently */ 874 /* unfortunately, we need to udpate los when observing, currently */
939 if (pl->do_los || pl->viewpoint != pl->ob) 875 if (pl->do_los || pl->viewpoint != pl->ob)
940 { 876 {
965 * look like. 901 * look like.
966 */ 902 */
967 903
968 client &socket = *pl->ns; 904 client &socket = *pl->ns;
969 905
970 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 906 packet sl ("map1a");
971 907
972 startlen = sl.length (); 908 startlen = sl.length ();
973 909
974 int hx = socket.mapx / 2; 910 int hx = socket.mapx / 2;
975 int hy = socket.mapy / 2; 911 int hy = socket.mapy / 2;
1005 { 941 {
1006 /* This block deals with spaces that are not visible for whatever 942 /* This block deals with spaces that are not visible for whatever
1007 * reason. Still may need to send the head for this space. 943 * reason. Still may need to send the head for this space.
1008 */ 944 */
1009 if (lastcell.count != -1 945 if (lastcell.count != -1
1010 || lastcell.faces[0] 946 || lastcell.faces[0]
1011 || lastcell.faces[1] 947 || lastcell.faces[1]
1012 || lastcell.faces[2] 948 || lastcell.faces[2]
1013 || lastcell.stat_hp 949 || lastcell.stat_hp
1014 || lastcell.flags 950 || lastcell.flags
1015 || lastcell.player) 951 || lastcell.player)
1016 sl << uint16 (mask); 952 sl << uint16 (mask);
1017 953
1018 /* properly clear a previously sent big face */ 954 /* properly clear a previously sent big face */
1019 map_clearcell (&lastcell, -1); 955 map_clearcell (&lastcell, -1);
1258 1194
1259/* 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. */
1260static void 1196static void
1261append_spell (player *pl, packet &sl, object *spell) 1197append_spell (player *pl, packet &sl, object *spell)
1262{ 1198{
1263 int i, skill = 0; 1199 int skill = 0;
1264 1200
1265 if (!(spell->name)) 1201 if (!(spell->name))
1266 { 1202 {
1267 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);
1268 return; 1204 return;
1295 << uint16 (spell->cached_grace) 1231 << uint16 (spell->cached_grace)
1296 << uint16 (spell->cached_eat) 1232 << uint16 (spell->cached_eat)
1297 << uint8 (skill) 1233 << uint8 (skill)
1298 << uint32 (spell->path_attuned) 1234 << uint32 (spell->path_attuned)
1299 << uint32 (spell->face) 1235 << uint32 (spell->face)
1300 << data8 (spell->name) 1236 << data8 (spell->name);
1237
1238 if (pl->ns->monitor_spells < 2)
1301 << data16 (spell->msg); 1239 sl << data16 (spell->msg);
1302} 1240}
1303 1241
1304/** 1242/**
1305 * 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
1306 * all spells in the player's inventory. 1244 * all spells in the player's inventory.
1307 */ 1245 */
1308void 1246void
1309esrv_add_spells (player *pl, object *spell) 1247esrv_add_spells (player *pl, object *spell)
1310{ 1248{
1321 1259
1322 if (!spell) 1260 if (!spell)
1323 { 1261 {
1324 for (spell = pl->ob->inv; spell; spell = spell->below) 1262 for (spell = pl->ob->inv; spell; spell = spell->below)
1325 { 1263 {
1326 /* were we to simply keep appending data here, we could exceed 1264 /* were we to simply keep appending data here, we could exceed
1327 * 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
1328 * append_spells will always append 19 data bytes, plus 4 length 1266 * append_spells will always append 19 data bytes, plus 4 length
1329 * 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
1330 * 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,
1331 * 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,
1332 * 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
1333 */ 1271 */
1334 if (spell->type != SPELL) 1272 if (spell->type != SPELL)
1335 continue; 1273 continue;
1336 1274
1337 /* Seeing crashes by overflowed buffers. Quick arithemetic seems 1275 /* Seeing crashes by overflowed buffers. Quick arithemetic seems
1358 } 1296 }
1359 else 1297 else
1360 append_spell (pl, sl, spell); 1298 append_spell (pl, sl, spell);
1361 1299
1362 if (sl.length () > MAXSOCKBUF) 1300 if (sl.length () > MAXSOCKBUF)
1363 {
1364 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 1301 cleanup ("buffer overflow in esrv_add_spells!");
1365 fatal (0);
1366 }
1367 1302
1368 /* finally, we can send the packet */ 1303 /* finally, we can send the packet */
1369 pl->ns->flush_fx (); 1304 pl->ns->flush_fx ();
1370 pl->ns->send_packet (sl); 1305 pl->ns->send_packet (sl);
1371} 1306}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines