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.170 by root, Thu Apr 8 20:05:36 2010 UTC vs.
Revision 1.183 by root, Sat May 7 20:03:28 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
65 * This table translates the attack numbers as used within the 65 * This table translates the attack numbers as used within the
66 * program to the value we use when sending STATS command to the 66 * program to the value we use when sending STATS command to the
67 * client. If a value is -1, then we don't send that to the 67 * client. If a value is -1, then we don't send that to the
68 * client. 68 * client.
69 */ 69 */
70static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, 70static short atnr_cs_stat[NROFATTACKS] =
71 CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, 71{
72 CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, 72 CS_STAT_RES_PHYS,
73 CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , 73 CS_STAT_RES_MAG,
74 CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, 74 CS_STAT_RES_FIRE,
75 CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, 75 CS_STAT_RES_ELEC,
76 CS_STAT_RES_FEAR, -1 /* Cancellation */ , 76 CS_STAT_RES_COLD,
77 CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, 77 CS_STAT_RES_CONF,
78 -1 /* Chaos */ , -1 /* Counterspell */ , 78 CS_STAT_RES_ACID,
79 -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, 79 CS_STAT_RES_DRAIN,
80 -1 /* weaponmagic */,
81 CS_STAT_RES_GHOSTHIT,
82 CS_STAT_RES_POISON,
83 CS_STAT_RES_SLOW,
84 CS_STAT_RES_PARA,
85 CS_STAT_TURN_UNDEAD,
86 CS_STAT_RES_FEAR,
87 -1 /* Cancellation */,
88 CS_STAT_RES_DEPLETE,
89 CS_STAT_RES_DEATH,
90 -1 /* Chaos */,
91 -1 /* Counterspell */,
92 -1 /* Godpower */,
93 CS_STAT_RES_HOLYWORD,
80 CS_STAT_RES_BLIND, 94 CS_STAT_RES_BLIND,
81 -1, /* Internal */ 95 -1, /* Internal */
82 -1, /* life stealing */ 96 -1, /* life stealing */
83 -1 /* Disease - not fully done yet */ 97 -1 /* Disease - not fully done yet */
84}; 98};
132 pl->ns->mapinfo_queue_clear (); 146 pl->ns->mapinfo_queue_clear ();
133 147
134 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); 148 memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap));
135 149
136 pl->ns->force_newmap = false; 150 pl->ns->force_newmap = false;
137
138 if (pl->ns->newmapcmd == 1)
139 pl->ns->send_packet ("newmap"); 151 pl->ns->send_packet ("newmap");
140
141 pl->ns->floorbox_reset (); 152 pl->ns->floorbox_reset ();
142} 153}
143 154
144static void 155static void
145send_map_info (player *pl) 156send_map_info (player *pl)
147 client &socket = *pl->ns; 158 client &socket = *pl->ns;
148 object *ob = pl->viewpoint; 159 object *ob = pl->viewpoint;
149 160
150 if (socket.mapinfocmd) 161 if (socket.mapinfocmd)
151 { 162 {
152 if (ob->map && ob->map->path[0]) 163 if (ob->map && ob->map->path)
153 { 164 {
154 int flags = 0; 165 int flags = 0;
155 166
167 // due to historical glitches, the bit ordering and map index ordering differs
156 if (ob->map->tile_path[0]) flags |= 1; 168 if (ob->map->tile_path[TILE_NORTH]) flags |= 0x01;
157 if (ob->map->tile_path[1]) flags |= 2; 169 if (ob->map->tile_path[TILE_EAST ]) flags |= 0x02;
158 if (ob->map->tile_path[2]) flags |= 4; 170 if (ob->map->tile_path[TILE_SOUTH]) flags |= 0x04;
159 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;
160 175
161 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",
162 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, 177 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
163 ob->map->width, ob->map->height, &ob->map->path); 178 ob->map->width, ob->map->height, &ob->map->path);
164 } 179 }
228send_skill_info (client *ns, char *params) 243send_skill_info (client *ns, char *params)
229{ 244{
230 packet sl; 245 packet sl;
231 sl << "replyinfo skill_info\n"; 246 sl << "replyinfo skill_info\n";
232 247
233 for (int i = 1; i < NUM_SKILLS; i++) 248 for (int i = 0; i < skillvec.size (); ++i)
234 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); 249 sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name);
235 250
236 if (sl.length () > MAXSOCKBUF) 251 if (sl.length () > MAXSOCKBUF)
237 {
238 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 252 cleanup ("buffer overflow in send_skill_info!");
239 fatal (0);
240 }
241 253
242 ns->send_packet (sl); 254 ns->send_packet (sl);
243} 255}
244 256
245/** 257/**
255 267
256 for (int i = 0; i < NRSPELLPATHS; i++) 268 for (int i = 0; i < NRSPELLPATHS; i++)
257 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); 269 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
258 270
259 if (sl.length () > MAXSOCKBUF) 271 if (sl.length () > MAXSOCKBUF)
260 {
261 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 272 cleanup ("buffer overflow in send_spell_paths!");
262 fatal (0);
263 }
264 273
265 ns->send_packet (sl); 274 ns->send_packet (sl);
266} 275}
267 276
268/** 277/**
336 345
337 while (*buf && map && max_distance) 346 while (*buf && map && max_distance)
338 { 347 {
339 int dir = *buf++ - '1'; 348 int dir = *buf++ - '1';
340 349
341 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 (dir >= 0 && dir < array_length (dirmap))
342 { 355 {
356 dir = dirmap [dir];
357
343 if (!map->tile_path [dir]) 358 if (!map->tile_path [dir])
344 map = 0; 359 map = 0;
345 else if (map->tile_available (dir, false)) 360 else if (map->tile_available (dir, false))
346 { 361 {
347 maptile *neigh = map->tile_map [dir]; 362 maptile *neigh = map->tile_map [dir];
370 send_packet_printf ("mapinfo %s nomap", token); 385 send_packet_printf ("mapinfo %s nomap", token);
371 else 386 else
372 { 387 {
373 int flags = 0; 388 int flags = 0;
374 389
390 // due to historical glitches, the bit ordering and map index ordering differs
375 if (map->tile_path[0]) flags |= 1; 391 if (map->tile_path[TILE_NORTH]) flags |= 0x01;
376 if (map->tile_path[1]) flags |= 2; 392 if (map->tile_path[TILE_EAST ]) flags |= 0x02;
377 if (map->tile_path[2]) flags |= 4; 393 if (map->tile_path[TILE_SOUTH]) flags |= 0x04;
378 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;
379 398
380 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);
381 } 400 }
382 401
383 return 1; 402 return 1;
697 * commands for now. 716 * commands for now.
698 */ 717 */
699void 718void
700esrv_update_stats (player *pl) 719esrv_update_stats (player *pl)
701{ 720{
702 char buf[MAX_BUF];
703 uint16 flags;
704
705 client *ns = pl->ns; 721 client *ns = pl->ns;
706 if (!ns) 722 if (!ns)
707 return; 723 return;
708 724
709 object *ob = pl->observe; 725 object *ob = pl->observe;
726 AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); 742 AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT);
727 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 743 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
728 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 744 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
729 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 745 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
730 746
731 for (int s = 0; s < NUM_SKILLS; s++) 747 for (int s = 0; s < CS_NUM_SKILLS; s++)
732 if (object *skill = opl->last_skill_ob [s]) 748 if (object *skill = opl->last_skill_ob [s])
733 if (skill->stats.exp != ns->last_skill_exp [s]) 749 if (skill->stats.exp != ns->last_skill_exp [s])
734 { 750 {
735 ns->last_skill_exp [s] = skill->stats.exp; 751 ns->last_skill_exp [s] = skill->stats.exp;
736 752
737 /* Always send along the level if exp changes. This is only 753 /* Always send along the level if exp changes. This is only
738 * 1 extra byte, but keeps processing simpler. 754 * 1 extra byte, but keeps processing simpler.
739 */ 755 */
740 sl << uint8 (s + CS_STAT_SKILLINFO) 756 sl << uint8 (CS_STAT_SKILLINFO + s)
741 << uint8 (skill->level) 757 << uint8 (skill->level)
742 << uint64 (skill->stats.exp); 758 << uint64 (skill->stats.exp);
743 } 759 }
744 760
745 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); 761 AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64);
750 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);
751 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); 767 AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD);
752 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);
753 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);
754 770
755 flags = 0; 771 int flags = (opl->fire_on ? SF_FIREON : 0)
756 772 | (opl->run_on ? SF_RUNON : 0);
757 if (opl->fire_on)
758 flags |= SF_FIREON;
759
760 if (opl->run_on)
761 flags |= SF_RUNON;
762 773
763 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); 774 AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
764 775
765 for (int i = 0; i < NROFATTACKS; i++) 776 for (int i = 0; i < NROFATTACKS; i++)
766 {
767 /* Skip ones we won't send */ 777 /* Skip ones we won't send */
768 if (atnr_cs_stat[i] == -1) 778 if (atnr_cs_stat[i] >= 0)
769 continue;
770
771 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]);
772 }
773 780
774 if (pl->ns->monitor_spells) 781 if (pl->ns->monitor_spells)
775 { 782 {
776 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);
777 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);
778 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);
779 } 786 }
780 787
788 char buf[MAX_BUF];
781 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 */
782 AddIfString (ns->stats.range, buf, CS_STAT_RANGE); 790 AddIfString (ns->stats.range, buf, CS_STAT_RANGE);
783 set_title (ob, buf); 791 set_title (ob, buf);
784 AddIfString (ns->stats.title, buf, CS_STAT_TITLE); 792 AddIfString (ns->stats.title, buf, CS_STAT_TITLE);
785 793
881 return 0; 889 return 0;
882} 890}
883 891
884//-GPL 892//-GPL
885 893
886// prefetch (and touch) all maps within a specific distancd 894// prefetch some flat area around the player
887static void 895static void
888prefetch_surrounding_maps (maptile *map, int distance) 896prefetch_surrounding_area (object *op, maptile *map, int range)
889{ 897{
890 map->touch (); 898 for (maprect *rect = map->split_to_tiles (mapwalk_buf,
891 899 op->x - range , op->y - range ,
892 if (--distance) 900 op->x + range + 1, op->y + range + 1);
893 for (int dir = 4; dir--; ) 901 rect->m;
894 if (const shstr &path = map->tile_path [dir]) 902 ++rect)
895 if (maptile *&neigh = map->tile_map [dir]) 903 {
896 prefetch_surrounding_maps (neigh, distance); 904 rect->m->touch ();
897 else 905 rect->m->activate ();
898 neigh = maptile::find_async (path, map); 906 }
899} 907}
900 908
901// prefetch a generous area around the player 909// prefetch a generous area around the player, also up and down
902static void 910void
903prefetch_surrounding_maps (object *op) 911object::prefetch_surrounding_maps ()
904{ 912{
905 prefetch_surrounding_maps (op->map, 3); 913 prefetch_surrounding_area (this, map, 40);
914
915 if (maptile *m = map->tile_available (TILE_DOWN))
916 prefetch_surrounding_area (this, m, 20);
917
918 if (maptile *m = map->tile_available (TILE_UP))
919 prefetch_surrounding_area (this, m, 20);
906} 920}
907 921
908//+GPL 922//+GPL
909 923
910/** 924/**
919 933
920 /* If player is just joining the game, he isn't here yet, so the map 934 /* If player is just joining the game, he isn't here yet, so the map
921 * can get swapped out. If so, don't try to send them a map. All will 935 * can get swapped out. If so, don't try to send them a map. All will
922 * be OK once they really log in. 936 * be OK once they really log in.
923 */ 937 */
924 if (!ob->map || ob->map->in_memory != MAP_ACTIVE) 938 if (!ob->map || ob->map->state != MAP_ACTIVE)
925 return; 939 return;
926 940
927 int startlen, oldlen; 941 int startlen, oldlen;
928 942
929 check_map_change (pl); 943 check_map_change (pl);
930 prefetch_surrounding_maps (pl->ob); 944 pl->ob->prefetch_surrounding_maps ();
931 945
932 /* do LOS after calls to update_position */ 946 /* do LOS after calls to update_position */
933 /* unfortunately, we need to udpate los when observing, currently */ 947 /* unfortunately, we need to udpate los when observing, currently */
934 if (pl->do_los || pl->viewpoint != pl->ob) 948 if (pl->do_los || pl->viewpoint != pl->ob)
935 { 949 {
960 * look like. 974 * look like.
961 */ 975 */
962 976
963 client &socket = *pl->ns; 977 client &socket = *pl->ns;
964 978
965 packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); 979 packet sl ("map1a");
966 980
967 startlen = sl.length (); 981 startlen = sl.length ();
968 982
969 int hx = socket.mapx / 2; 983 int hx = socket.mapx / 2;
970 int hy = socket.mapy / 2; 984 int hy = socket.mapy / 2;
1062 { 1076 {
1063 if (op->stats.maxhp > op->stats.hp 1077 if (op->stats.maxhp > op->stats.hp
1064 && op->stats.maxhp > 0 1078 && op->stats.maxhp > 0
1065 && (op->type == PLAYER 1079 && (op->type == PLAYER
1066 || op->type == DOOR // does not work, have maxhp 0 1080 || op->type == DOOR // does not work, have maxhp 0
1067 || QUERY_FLAG (op, FLAG_MONSTER) 1081 || op->flag [FLAG_MONSTER]
1068 || QUERY_FLAG (op, FLAG_ALIVE) 1082 || op->flag [FLAG_ALIVE]
1069 || QUERY_FLAG (op, FLAG_GENERATOR))) 1083 || op->flag [FLAG_GENERATOR]))
1070 { 1084 {
1071 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1085 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1072 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge 1086 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1073 } 1087 }
1074 1088
1269 spell->cached_eat = casting_level (pl->ob, spell); 1283 spell->cached_eat = casting_level (pl->ob, spell);
1270 1284
1271 /* figure out which skill it uses, if it uses one */ 1285 /* figure out which skill it uses, if it uses one */
1272 if (spell->skill) 1286 if (spell->skill)
1273 if (object *tmp = pl->find_skill (spell->skill)) 1287 if (object *tmp = pl->find_skill (spell->skill))
1274 skill = tmp->subtype + CS_STAT_SKILLINFO; 1288 skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp);
1275 1289
1276 // spells better have a face 1290 // spells better have a face
1277 if (!spell->face) 1291 if (!spell->face)
1278 { 1292 {
1279 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); 1293 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name);
1353 } 1367 }
1354 else 1368 else
1355 append_spell (pl, sl, spell); 1369 append_spell (pl, sl, spell);
1356 1370
1357 if (sl.length () > MAXSOCKBUF) 1371 if (sl.length () > MAXSOCKBUF)
1358 {
1359 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 1372 cleanup ("buffer overflow in esrv_add_spells!");
1360 fatal (0);
1361 }
1362 1373
1363 /* finally, we can send the packet */ 1374 /* finally, we can send the packet */
1364 pl->ns->flush_fx (); 1375 pl->ns->flush_fx ();
1365 pl->ns->send_packet (sl); 1376 pl->ns->send_packet (sl);
1366} 1377}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines