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.174 by root, Thu Apr 15 00:40:34 2010 UTC vs.
Revision 1.182 by root, Thu May 5 18:59:43 2011 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 (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 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
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
158static void 155static void
159send_map_info (player *pl) 156send_map_info (player *pl)
165 { 162 {
166 if (ob->map && ob->map->path[0]) 163 if (ob->map && ob->map->path[0])
167 { 164 {
168 int flags = 0; 165 int flags = 0;
169 166
170 if (ob->map->tile_path[0]) flags |= 1; 167 if (ob->map->tile_path[0]) flags |= 0x01;
171 if (ob->map->tile_path[1]) flags |= 2; 168 if (ob->map->tile_path[1]) flags |= 0x02;
172 if (ob->map->tile_path[2]) flags |= 4; 169 if (ob->map->tile_path[2]) flags |= 0x04;
173 if (ob->map->tile_path[3]) flags |= 8; 170 if (ob->map->tile_path[3]) flags |= 0x08;
171 // these two are debatable
172 if (ob->map->tile_path[4]) flags |= 0x10;
173 if (ob->map->tile_path[5]) flags |= 0x20;
174 174
175 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", 175 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
176 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, 176 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
177 ob->map->width, ob->map->height, &ob->map->path); 177 ob->map->width, ob->map->height, &ob->map->path);
178 } 178 }
246 246
247 for (int i = 0; i < skillvec.size (); ++i) 247 for (int i = 0; i < skillvec.size (); ++i)
248 sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); 248 sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name);
249 249
250 if (sl.length () > MAXSOCKBUF) 250 if (sl.length () > MAXSOCKBUF)
251 {
252 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 251 cleanup ("buffer overflow in send_skill_info!");
253 fatal (0);
254 }
255 252
256 ns->send_packet (sl); 253 ns->send_packet (sl);
257} 254}
258 255
259/** 256/**
269 266
270 for (int i = 0; i < NRSPELLPATHS; i++) 267 for (int i = 0; i < NRSPELLPATHS; i++)
271 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); 268 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
272 269
273 if (sl.length () > MAXSOCKBUF) 270 if (sl.length () > MAXSOCKBUF)
274 {
275 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 271 cleanup ("buffer overflow in send_spell_paths!");
276 fatal (0);
277 }
278 272
279 ns->send_packet (sl); 273 ns->send_packet (sl);
280} 274}
281 275
282/** 276/**
350 344
351 while (*buf && map && max_distance) 345 while (*buf && map && max_distance)
352 { 346 {
353 int dir = *buf++ - '1'; 347 int dir = *buf++ - '1';
354 348
355 if (dir >= 0 && dir <= 3) 349 // maybe we should only allow the four flat directions
350 if (dir >= 0 && dir < array_length (map->tile_path))
356 { 351 {
357 if (!map->tile_path [dir]) 352 if (!map->tile_path [dir])
358 map = 0; 353 map = 0;
359 else if (map->tile_available (dir, false)) 354 else if (map->tile_available (dir, false))
360 { 355 {
384 send_packet_printf ("mapinfo %s nomap", token); 379 send_packet_printf ("mapinfo %s nomap", token);
385 else 380 else
386 { 381 {
387 int flags = 0; 382 int flags = 0;
388 383
389 if (map->tile_path[0]) flags |= 1; 384 if (map->tile_path[0]) flags |= 0x01;
390 if (map->tile_path[1]) flags |= 2; 385 if (map->tile_path[1]) flags |= 0x02;
391 if (map->tile_path[2]) flags |= 4; 386 if (map->tile_path[2]) flags |= 0x04;
392 if (map->tile_path[3]) flags |= 8; 387 if (map->tile_path[3]) flags |= 0x08;
388 // these two are debatable
389 if (map->tile_path[4]) flags |= 0x10;
390 if (map->tile_path[5]) flags |= 0x20;
393 391
394 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); 392 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path);
395 } 393 }
396 394
397 return 1; 395 return 1;
884 return 0; 882 return 0;
885} 883}
886 884
887//-GPL 885//-GPL
888 886
889// prefetch (and touch) all maps within a specific distancd 887// prefetch some flat area around the player
890static void 888static void
891prefetch_surrounding_maps (maptile *map, int distance) 889prefetch_surrounding_area (object *op, maptile *map, int range)
892{ 890{
893 map->touch (); 891 for (maprect *rect = map->split_to_tiles (mapwalk_buf,
894 892 op->x - range , op->y - range ,
895 if (--distance) 893 op->x + range + 1, op->y + range + 1);
896 for (int dir = 4; dir--; ) 894 rect->m;
897 if (const shstr &path = map->tile_path [dir]) 895 ++rect)
898 if (maptile *&neigh = map->tile_map [dir]) 896 {
899 prefetch_surrounding_maps (neigh, distance); 897 rect->m->touch ();
900 else 898 rect->m->activate ();
901 neigh = maptile::find_async (path, map); 899 }
902} 900}
903 901
904// prefetch a generous area around the player 902// prefetch a generous area around the player, also up and down
905static void 903void
906prefetch_surrounding_maps (object *op) 904object::prefetch_surrounding_maps ()
907{ 905{
908 prefetch_surrounding_maps (op->map, 3); 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);
909} 913}
910 914
911//+GPL 915//+GPL
912 916
913/** 917/**
922 926
923 /* If player is just joining the game, he isn't here yet, so the map 927 /* 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 928 * can get swapped out. If so, don't try to send them a map. All will
925 * be OK once they really log in. 929 * be OK once they really log in.
926 */ 930 */
927 if (!ob->map || ob->map->in_memory != MAP_ACTIVE) 931 if (!ob->map || ob->map->state != MAP_ACTIVE)
928 return; 932 return;
929 933
930 int startlen, oldlen; 934 int startlen, oldlen;
931 935
932 check_map_change (pl); 936 check_map_change (pl);
933 prefetch_surrounding_maps (pl->ob); 937 pl->ob->prefetch_surrounding_maps ();
934 938
935 /* do LOS after calls to update_position */ 939 /* do LOS after calls to update_position */
936 /* unfortunately, we need to udpate los when observing, currently */ 940 /* unfortunately, we need to udpate los when observing, currently */
937 if (pl->do_los || pl->viewpoint != pl->ob) 941 if (pl->do_los || pl->viewpoint != pl->ob)
938 { 942 {
963 * look like. 967 * look like.
964 */ 968 */
965 969
966 client &socket = *pl->ns; 970 client &socket = *pl->ns;
967 971
968 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 972 packet sl ("map1a");
969 973
970 startlen = sl.length (); 974 startlen = sl.length ();
971 975
972 int hx = socket.mapx / 2; 976 int hx = socket.mapx / 2;
973 int hy = socket.mapy / 2; 977 int hy = socket.mapy / 2;
1356 } 1360 }
1357 else 1361 else
1358 append_spell (pl, sl, spell); 1362 append_spell (pl, sl, spell);
1359 1363
1360 if (sl.length () > MAXSOCKBUF) 1364 if (sl.length () > MAXSOCKBUF)
1361 {
1362 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 1365 cleanup ("buffer overflow in esrv_add_spells!");
1363 fatal (0);
1364 }
1365 1366
1366 /* finally, we can send the packet */ 1367 /* finally, we can send the packet */
1367 pl->ns->flush_fx (); 1368 pl->ns->flush_fx ();
1368 pl->ns->send_packet (sl); 1369 pl->ns->send_packet (sl);
1369} 1370}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines