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 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 |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | //+GPL |
25 | //+GPL |
26 | |
26 | |
… | |
… | |
146 | pl->ns->mapinfo_queue_clear (); |
146 | pl->ns->mapinfo_queue_clear (); |
147 | |
147 | |
148 | memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); |
148 | memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); |
149 | |
149 | |
150 | pl->ns->force_newmap = false; |
150 | pl->ns->force_newmap = false; |
151 | |
|
|
152 | if (pl->ns->newmapcmd == 1) |
|
|
153 | pl->ns->send_packet ("newmap"); |
151 | pl->ns->send_packet ("newmap"); |
154 | |
|
|
155 | pl->ns->floorbox_reset (); |
152 | pl->ns->floorbox_reset (); |
156 | } |
153 | } |
157 | |
154 | |
158 | static void |
155 | static void |
159 | send_map_info (player *pl) |
156 | send_map_info (player *pl) |
… | |
… | |
161 | client &socket = *pl->ns; |
158 | client &socket = *pl->ns; |
162 | object *ob = pl->viewpoint; |
159 | object *ob = pl->viewpoint; |
163 | |
160 | |
164 | if (socket.mapinfocmd) |
161 | if (socket.mapinfocmd) |
165 | { |
162 | { |
166 | if (ob->map && ob->map->path[0]) |
163 | if (ob->map && ob->map->path) |
167 | { |
164 | { |
168 | int flags = 0; |
165 | int flags = 0; |
169 | |
166 | |
|
|
167 | // due to historical glitches, the bit ordering and map index ordering differs |
170 | if (ob->map->tile_path[0]) flags |= 1; |
168 | if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01; |
171 | if (ob->map->tile_path[1]) flags |= 2; |
169 | if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02; |
172 | if (ob->map->tile_path[2]) flags |= 4; |
170 | if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04; |
173 | if (ob->map->tile_path[3]) flags |= 8; |
171 | if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08; |
|
|
172 | // these two are debatable |
|
|
173 | if (ob->map->tile_path [TILE_UP ]) flags |= 0x10; |
|
|
174 | if (ob->map->tile_path [TILE_DOWN ]) flags |= 0x20; |
174 | |
175 | |
175 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
176 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
176 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
177 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
177 | ob->map->width, ob->map->height, &ob->map->path); |
178 | ob->map->width, ob->map->height, &ob->map->path); |
178 | } |
179 | } |
… | |
… | |
193 | { |
194 | { |
194 | INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); |
195 | INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region)); |
195 | socket.current_region = reg; |
196 | socket.current_region = reg; |
196 | } |
197 | } |
197 | |
198 | |
198 | // first try to aovid a full newmap on tiled map scrolls |
199 | // first try to avoid a full newmap on tiled map scrolls |
199 | if (socket.current_map != ob->map && !socket.force_newmap) |
200 | if (socket.current_map != ob->map && !socket.force_newmap) |
200 | { |
201 | { |
201 | rv_vector rv; |
202 | rv_vector rv; |
202 | |
203 | |
203 | get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); |
204 | get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0); |
… | |
… | |
246 | |
247 | |
247 | for (int i = 0; i < skillvec.size (); ++i) |
248 | for (int i = 0; i < skillvec.size (); ++i) |
248 | sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); |
249 | sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); |
249 | |
250 | |
250 | if (sl.length () > MAXSOCKBUF) |
251 | if (sl.length () > MAXSOCKBUF) |
251 | { |
|
|
252 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
252 | cleanup ("buffer overflow in send_skill_info!"); |
253 | fatal (0); |
|
|
254 | } |
|
|
255 | |
253 | |
256 | ns->send_packet (sl); |
254 | ns->send_packet (sl); |
257 | } |
255 | } |
258 | |
256 | |
259 | /** |
257 | /** |
… | |
… | |
269 | |
267 | |
270 | for (int i = 0; i < NRSPELLPATHS; i++) |
268 | for (int i = 0; i < NRSPELLPATHS; i++) |
271 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
269 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
272 | |
270 | |
273 | if (sl.length () > MAXSOCKBUF) |
271 | if (sl.length () > MAXSOCKBUF) |
274 | { |
|
|
275 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
272 | cleanup ("buffer overflow in send_spell_paths!"); |
276 | fatal (0); |
|
|
277 | } |
|
|
278 | |
273 | |
279 | ns->send_packet (sl); |
274 | ns->send_packet (sl); |
280 | } |
275 | } |
281 | |
276 | |
282 | /** |
277 | /** |
283 | * RequestInfo is sort of a meta command. There is some specific |
278 | * RequestInfo is sort of a meta command. There is some specific |
284 | * request of information, but we call other functions to provide |
279 | * request of information, but we call other functions to provide |
285 | * that information. |
280 | * that information. |
|
|
281 | * requestinfo is completely deprecated, use resource exti request |
|
|
282 | * and the fxix or http protocols. |
286 | */ |
283 | */ |
287 | void |
284 | void |
288 | RequestInfo (char *buf, int len, client *ns) |
285 | RequestInfo (char *buf, int len, client *ns) |
289 | { |
286 | { |
290 | char *params; |
287 | char *params; |
… | |
… | |
350 | |
347 | |
351 | while (*buf && map && max_distance) |
348 | while (*buf && map && max_distance) |
352 | { |
349 | { |
353 | int dir = *buf++ - '1'; |
350 | int dir = *buf++ - '1'; |
354 | |
351 | |
355 | if (dir >= 0 && dir <= 3) |
352 | // due to historical glitches, the mapinfo index and tile index differs |
|
|
353 | static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN }; |
|
|
354 | |
|
|
355 | // maybe we should only allow the four flat directions |
|
|
356 | if (IN_RANGE_EXC (dir, 0, array_length (dirmap))) |
356 | { |
357 | { |
|
|
358 | dir = dirmap [dir]; |
|
|
359 | |
357 | if (!map->tile_path [dir]) |
360 | if (!map->tile_path [dir]) |
358 | map = 0; |
361 | map = 0; |
359 | else if (map->tile_available (dir, false)) |
362 | else if (map->tile_available (dir, false)) |
360 | { |
363 | { |
361 | maptile *neigh = map->tile_map [dir]; |
364 | maptile *neigh = map->tile_map [dir]; |
… | |
… | |
384 | send_packet_printf ("mapinfo %s nomap", token); |
387 | send_packet_printf ("mapinfo %s nomap", token); |
385 | else |
388 | else |
386 | { |
389 | { |
387 | int flags = 0; |
390 | int flags = 0; |
388 | |
391 | |
|
|
392 | // due to historical glitches, the bit ordering and map index ordering differs |
389 | if (map->tile_path[0]) flags |= 1; |
393 | if (map->tile_path [TILE_NORTH]) flags |= 0x01; |
390 | if (map->tile_path[1]) flags |= 2; |
394 | if (map->tile_path [TILE_EAST ]) flags |= 0x02; |
391 | if (map->tile_path[2]) flags |= 4; |
395 | if (map->tile_path [TILE_SOUTH]) flags |= 0x04; |
392 | if (map->tile_path[3]) flags |= 8; |
396 | if (map->tile_path [TILE_WEST ]) flags |= 0x08; |
|
|
397 | // these two are debatable |
|
|
398 | if (map->tile_path [TILE_UP ]) flags |= 0x10; |
|
|
399 | if (map->tile_path [TILE_DOWN ]) flags |= 0x20; |
393 | |
400 | |
394 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
401 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
395 | } |
402 | } |
396 | |
403 | |
397 | return 1; |
404 | return 1; |
… | |
… | |
489 | * Cleaning up the input should probably be done first - all actions |
496 | * 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 |
497 | * for the command that issued the count should be done before any other |
491 | * commands. |
498 | * commands. |
492 | */ |
499 | */ |
493 | pl->count = 0; |
500 | 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 | */ |
|
|
502 | void |
|
|
503 | NewPlayerCmd (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 | } |
501 | } |
539 | |
502 | |
540 | /** This is a reply to a previous query. */ |
503 | /** This is a reply to a previous query. */ |
541 | void |
504 | void |
542 | ReplyCmd (char *buf, int len, client *ns) |
505 | ReplyCmd (char *buf, int len, client *ns) |
… | |
… | |
882 | |
845 | |
883 | /* Nothing changed */ |
846 | /* Nothing changed */ |
884 | return 0; |
847 | return 0; |
885 | } |
848 | } |
886 | |
849 | |
887 | //-GPL |
|
|
888 | |
|
|
889 | // prefetch (and touch) all maps within a specific distancd |
|
|
890 | static void |
|
|
891 | prefetch_surrounding_maps (maptile *map, int distance) |
|
|
892 | { |
|
|
893 | map->touch (); |
|
|
894 | |
|
|
895 | if (--distance) |
|
|
896 | for (int dir = 4; dir--; ) |
|
|
897 | if (const shstr &path = map->tile_path [dir]) |
|
|
898 | if (maptile *&neigh = map->tile_map [dir]) |
|
|
899 | prefetch_surrounding_maps (neigh, distance); |
|
|
900 | else |
|
|
901 | neigh = maptile::find_async (path, map); |
|
|
902 | } |
|
|
903 | |
|
|
904 | // prefetch a generous area around the player |
|
|
905 | static void |
|
|
906 | prefetch_surrounding_maps (object *op) |
|
|
907 | { |
|
|
908 | prefetch_surrounding_maps (op->map, 3); |
|
|
909 | } |
|
|
910 | |
|
|
911 | //+GPL |
|
|
912 | |
|
|
913 | /** |
850 | /** |
914 | * Draws client map. |
851 | * Draws client map. |
915 | */ |
852 | */ |
916 | void |
853 | void |
917 | draw_client_map (player *pl) |
854 | draw_client_map (player *pl) |
… | |
… | |
922 | |
859 | |
923 | /* If player is just joining the game, he isn't here yet, so the map |
860 | /* If player is just joining the game, he isn't here yet, so the map |
924 | * can get swapped out. If so, don't try to send them a map. All will |
861 | * can get swapped out. If so, don't try to send them a map. All will |
925 | * be OK once they really log in. |
862 | * be OK once they really log in. |
926 | */ |
863 | */ |
927 | if (!ob->map || ob->map->in_memory != MAP_ACTIVE) |
864 | if (!ob->map || ob->map->state != MAP_ACTIVE) |
928 | return; |
865 | return; |
929 | |
866 | |
930 | int startlen, oldlen; |
867 | int startlen, oldlen; |
931 | |
868 | |
932 | check_map_change (pl); |
869 | check_map_change (pl); |
933 | prefetch_surrounding_maps (pl->ob); |
870 | pl->ob->prefetch_surrounding_maps (); |
934 | |
871 | |
935 | /* do LOS after calls to update_position */ |
872 | /* do LOS after calls to update_position */ |
936 | /* unfortunately, we need to udpate los when observing, currently */ |
873 | /* unfortunately, we need to udpate los when observing, currently */ |
937 | if (pl->do_los || pl->viewpoint != pl->ob) |
874 | if (pl->do_los || pl->viewpoint != pl->ob) |
938 | { |
875 | { |
… | |
… | |
963 | * look like. |
900 | * look like. |
964 | */ |
901 | */ |
965 | |
902 | |
966 | client &socket = *pl->ns; |
903 | client &socket = *pl->ns; |
967 | |
904 | |
968 | packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); |
905 | packet sl ("map1a"); |
969 | |
906 | |
970 | startlen = sl.length (); |
907 | startlen = sl.length (); |
971 | |
908 | |
972 | int hx = socket.mapx / 2; |
909 | int hx = socket.mapx / 2; |
973 | int hy = socket.mapy / 2; |
910 | int hy = socket.mapy / 2; |
… | |
… | |
1256 | |
1193 | |
1257 | /* appends the spell *spell to the Socklist we will send the data to. */ |
1194 | /* appends the spell *spell to the Socklist we will send the data to. */ |
1258 | static void |
1195 | static void |
1259 | append_spell (player *pl, packet &sl, object *spell) |
1196 | append_spell (player *pl, packet &sl, object *spell) |
1260 | { |
1197 | { |
1261 | int i, skill = 0; |
1198 | int skill = 0; |
1262 | |
1199 | |
1263 | if (!(spell->name)) |
1200 | if (!(spell->name)) |
1264 | { |
1201 | { |
1265 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
1202 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
1266 | return; |
1203 | return; |
… | |
… | |
1293 | << uint16 (spell->cached_grace) |
1230 | << uint16 (spell->cached_grace) |
1294 | << uint16 (spell->cached_eat) |
1231 | << uint16 (spell->cached_eat) |
1295 | << uint8 (skill) |
1232 | << uint8 (skill) |
1296 | << uint32 (spell->path_attuned) |
1233 | << uint32 (spell->path_attuned) |
1297 | << uint32 (spell->face) |
1234 | << uint32 (spell->face) |
1298 | << data8 (spell->name) |
1235 | << data8 (spell->name); |
|
|
1236 | |
|
|
1237 | if (pl->ns->monitor_spells < 2) |
1299 | << data16 (spell->msg); |
1238 | sl << data16 (spell->msg); |
1300 | } |
1239 | } |
1301 | |
1240 | |
1302 | /** |
1241 | /** |
1303 | * 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 |
1304 | * all spells in the player's inventory. |
1243 | * all spells in the player's inventory. |
… | |
… | |
1356 | } |
1295 | } |
1357 | else |
1296 | else |
1358 | append_spell (pl, sl, spell); |
1297 | append_spell (pl, sl, spell); |
1359 | |
1298 | |
1360 | if (sl.length () > MAXSOCKBUF) |
1299 | if (sl.length () > MAXSOCKBUF) |
1361 | { |
|
|
1362 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1300 | cleanup ("buffer overflow in esrv_add_spells!"); |
1363 | fatal (0); |
|
|
1364 | } |
|
|
1365 | |
1301 | |
1366 | /* finally, we can send the packet */ |
1302 | /* finally, we can send the packet */ |
1367 | pl->ns->flush_fx (); |
1303 | pl->ns->flush_fx (); |
1368 | pl->ns->send_packet (sl); |
1304 | pl->ns->send_packet (sl); |
1369 | } |
1305 | } |