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.172 by root, Thu Apr 15 00:36:51 2010 UTC vs.
Revision 1.188 by root, Mon Oct 29 23:55:57 2012 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,2012 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
158static void 155static void
159send_map_info (player *pl) 156send_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 }
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/**
350 345
351 while (*buf && map && max_distance) 346 while (*buf && map && max_distance)
352 { 347 {
353 int dir = *buf++ - '1'; 348 int dir = *buf++ - '1';
354 349
355 if (dir >= 0 && dir <= 3) 350 // 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 };
352
353 // maybe we should only allow the four flat directions
354 if (IN_RANGE_EXC (dir, 0, array_length (dirmap)))
356 { 355 {
356 dir = dirmap [dir];
357
357 if (!map->tile_path [dir]) 358 if (!map->tile_path [dir])
358 map = 0; 359 map = 0;
359 else if (map->tile_available (dir, false)) 360 else if (map->tile_available (dir, false))
360 { 361 {
361 maptile *neigh = map->tile_map [dir]; 362 maptile *neigh = map->tile_map [dir];
384 send_packet_printf ("mapinfo %s nomap", token); 385 send_packet_printf ("mapinfo %s nomap", token);
385 else 386 else
386 { 387 {
387 int flags = 0; 388 int flags = 0;
388 389
390 // due to historical glitches, the bit ordering and map index ordering differs
389 if (map->tile_path[0]) flags |= 1; 391 if (map->tile_path [TILE_NORTH]) flags |= 0x01;
390 if (map->tile_path[1]) flags |= 2; 392 if (map->tile_path [TILE_EAST ]) flags |= 0x02;
391 if (map->tile_path[2]) flags |= 4; 393 if (map->tile_path [TILE_SOUTH]) flags |= 0x04;
392 if (map->tile_path[3]) flags |= 8; 394 if (map->tile_path [TILE_WEST ]) flags |= 0x08;
395 // these two are debatable
396 if (map->tile_path [TILE_UP ]) flags |= 0x10;
397 if (map->tile_path [TILE_DOWN ]) flags |= 0x20;
393 398
394 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); 399 send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path);
395 } 400 }
396 401
397 return 1; 402 return 1;
711 * commands for now. 716 * commands for now.
712 */ 717 */
713void 718void
714esrv_update_stats (player *pl) 719esrv_update_stats (player *pl)
715{ 720{
716 char buf[MAX_BUF];
717 uint16 flags;
718
719 client *ns = pl->ns; 721 client *ns = pl->ns;
720 if (!ns) 722 if (!ns)
721 return; 723 return;
722 724
723 object *ob = pl->observe; 725 object *ob = pl->observe;
764 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); 766 AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK);
765 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); 767 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); 768 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); 769 AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM);
768 770
769 flags = (opl->fire_on ? SF_FIREON : 0) 771 int flags = (opl->fire_on ? SF_FIREON : 0)
770 | (opl->run_on ? SF_RUNON : 0); 772 | (opl->run_on ? SF_RUNON : 0);
771 773
772 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); 774 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
773 775
774 for (int i = 0; i < NROFATTACKS; i++) 776 for (int i = 0; i < NROFATTACKS; i++)
775 {
776 /* Skip ones we won't send */ 777 /* Skip ones we won't send */
777 if (atnr_cs_stat[i] == -1) 778 if (atnr_cs_stat[i] >= 0)
778 continue;
779
780 AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); 779 AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]);
781 }
782 780
783 if (pl->ns->monitor_spells) 781 if (pl->ns->monitor_spells)
784 { 782 {
785 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); 783 AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE);
786 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); 784 AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL);
787 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); 785 AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY);
788 } 786 }
789 787
788 char buf[MAX_BUF];
790 rangetostring (opl, buf); /* we want use the new fire & run system in new client */ 789 rangetostring (opl, buf); /* we want use the new fire & run system in new client */
791 AddIfString (ns->stats.range, buf, CS_STAT_RANGE); 790 AddIfString (ns->stats.range, buf, CS_STAT_RANGE);
792 set_title (ob, buf); 791 set_title (ob, buf);
793 AddIfString (ns->stats.title, buf, CS_STAT_TITLE); 792 AddIfString (ns->stats.title, buf, CS_STAT_TITLE);
794 793
888 887
889 /* Nothing changed */ 888 /* Nothing changed */
890 return 0; 889 return 0;
891} 890}
892 891
893//-GPL
894
895// prefetch (and touch) all maps within a specific distancd
896static void
897prefetch_surrounding_maps (maptile *map, int distance)
898{
899 map->touch ();
900
901 if (--distance)
902 for (int dir = 4; dir--; )
903 if (const shstr &path = map->tile_path [dir])
904 if (maptile *&neigh = map->tile_map [dir])
905 prefetch_surrounding_maps (neigh, distance);
906 else
907 neigh = maptile::find_async (path, map);
908}
909
910// prefetch a generous area around the player
911static void
912prefetch_surrounding_maps (object *op)
913{
914 prefetch_surrounding_maps (op->map, 3);
915}
916
917//+GPL
918
919/** 892/**
920 * Draws client map. 893 * Draws client map.
921 */ 894 */
922void 895void
923draw_client_map (player *pl) 896draw_client_map (player *pl)
928 901
929 /* If player is just joining the game, he isn't here yet, so the map 902 /* If player is just joining the game, he isn't here yet, so the map
930 * can get swapped out. If so, don't try to send them a map. All will 903 * can get swapped out. If so, don't try to send them a map. All will
931 * be OK once they really log in. 904 * be OK once they really log in.
932 */ 905 */
933 if (!ob->map || ob->map->in_memory != MAP_ACTIVE) 906 if (!ob->map || ob->map->state != MAP_ACTIVE)
934 return; 907 return;
935 908
936 int startlen, oldlen; 909 int startlen, oldlen;
937 910
938 check_map_change (pl); 911 check_map_change (pl);
939 prefetch_surrounding_maps (pl->ob); 912 pl->ob->prefetch_surrounding_maps ();
940 913
941 /* do LOS after calls to update_position */ 914 /* do LOS after calls to update_position */
942 /* unfortunately, we need to udpate los when observing, currently */ 915 /* unfortunately, we need to udpate los when observing, currently */
943 if (pl->do_los || pl->viewpoint != pl->ob) 916 if (pl->do_los || pl->viewpoint != pl->ob)
944 { 917 {
969 * look like. 942 * look like.
970 */ 943 */
971 944
972 client &socket = *pl->ns; 945 client &socket = *pl->ns;
973 946
974 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 947 packet sl ("map1a");
975 948
976 startlen = sl.length (); 949 startlen = sl.length ();
977 950
978 int hx = socket.mapx / 2; 951 int hx = socket.mapx / 2;
979 int hy = socket.mapy / 2; 952 int hy = socket.mapy / 2;
1262 1235
1263/* appends the spell *spell to the Socklist we will send the data to. */ 1236/* appends the spell *spell to the Socklist we will send the data to. */
1264static void 1237static void
1265append_spell (player *pl, packet &sl, object *spell) 1238append_spell (player *pl, packet &sl, object *spell)
1266{ 1239{
1267 int i, skill = 0; 1240 int skill = 0;
1268 1241
1269 if (!(spell->name)) 1242 if (!(spell->name))
1270 { 1243 {
1271 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1244 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1272 return; 1245 return;
1362 } 1335 }
1363 else 1336 else
1364 append_spell (pl, sl, spell); 1337 append_spell (pl, sl, spell);
1365 1338
1366 if (sl.length () > MAXSOCKBUF) 1339 if (sl.length () > MAXSOCKBUF)
1367 {
1368 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 1340 cleanup ("buffer overflow in esrv_add_spells!");
1369 fatal (0);
1370 }
1371 1341
1372 /* finally, we can send the packet */ 1342 /* finally, we can send the packet */
1373 pl->ns->flush_fx (); 1343 pl->ns->flush_fx ();
1374 pl->ns->send_packet (sl); 1344 pl->ns->send_packet (sl);
1375} 1345}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines