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.119 by root, Fri Aug 24 00:26:10 2007 UTC vs.
Revision 1.133 by root, Sun Jul 13 11:57:25 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel 5 * Copyright (©) 2001,2007 Mark Wedel
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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,
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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24/** 24/**
25 * \file 25 * \file
26 * Client handling. 26 * Client handling.
141 pl->ns->send_packet ("newmap"); 141 pl->ns->send_packet ("newmap");
142 142
143 pl->ns->floorbox_reset (); 143 pl->ns->floorbox_reset ();
144} 144}
145 145
146static void
147send_map_info (player *pl)
148{
149 client &socket = *pl->ns;
150 object *ob = pl->observe;
151
152 if (socket.mapinfocmd)
153 {
154 if (ob->map && ob->map->path[0])
155 {
156 int flags = 0;
157
158 if (ob->map->tile_path[0]) flags |= 1;
159 if (ob->map->tile_path[1]) flags |= 2;
160 if (ob->map->tile_path[2]) flags |= 4;
161 if (ob->map->tile_path[3]) flags |= 8;
162
163 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
164 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
165 ob->map->width, ob->map->height, &ob->map->path);
166 }
167 else
168 socket.send_packet ("mapinfo current");
169 }
170}
171
146/** check for map/region change and send new map data */ 172/** check for map/region change and send new map data */
147static void 173static void
148check_map_change (player *pl) 174check_map_change (player *pl)
149{ 175{
150 client &socket = *pl->ns; 176 client &socket = *pl->ns;
151 object *ob = pl->observe; 177 object *ob = pl->observe;
152 178
179 region *reg = ob->region ();
180 if (socket.current_region != reg)
181 {
182 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
183 socket.current_region = reg;
184 }
185
186 // first try to aovid a full newmap on tiled map scrolls
187 if (socket.current_map != ob->map && !socket.force_newmap)
188 {
189 rv_vector rv;
190
191 get_rangevector_from_mapcoord (socket.current_map, socket.current_x, socket.current_y, ob, &rv, 0);
192
193 // manhattan distance is very handy here
194 if (rv.distance < 8) // 8 works nicely for speed << 70 and buggy gcfclient
195 {
196 socket.current_map = ob->map;
197 socket.current_x = ob->x;
198 socket.current_y = ob->y;
199
200 socket_map_scroll (&socket, rv.distance_x, rv.distance_y);
201 socket.floorbox_reset ();
202 send_map_info (pl);
203 }
204 }
205
153 if (socket.current_map != ob->map || socket.force_newmap) 206 if (socket.current_map != ob->map || socket.force_newmap)
154 { 207 {
155 clear_map (pl); 208 clear_map (pl);
156 socket.current_map = ob->map; 209 socket.current_map = ob->map;
157 210 send_map_info (pl);
158 if (socket.mapinfocmd)
159 {
160 if (ob->map && ob->map->path[0])
161 {
162 int flags = 0;
163
164 if (ob->map->tile_path[0]) flags |= 1;
165 if (ob->map->tile_path[1]) flags |= 2;
166 if (ob->map->tile_path[2]) flags |= 4;
167 if (ob->map->tile_path[3]) flags |= 8;
168
169 socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s",
170 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y,
171 ob->map->width, ob->map->height, &ob->map->path);
172 }
173 else
174 socket.send_packet ("mapinfo current");
175 }
176 } 211 }
177 else if (socket.current_x != ob->x || socket.current_y != ob->y) 212 else if (socket.current_x != ob->x || socket.current_y != ob->y)
178 { 213 {
179 int dx = ob->x - socket.current_x; 214 int dx = ob->x - socket.current_x;
180 int dy = ob->y - socket.current_y; 215 int dy = ob->y - socket.current_y;
188 } 223 }
189 } 224 }
190 225
191 socket.current_x = ob->x; 226 socket.current_x = ob->x;
192 socket.current_y = ob->y; 227 socket.current_y = ob->y;
193
194 region *reg = ob->region ();
195 if (socket.current_region != reg)
196 {
197 INVOKE_PLAYER (REGION_CHANGE, pl, ARG_REGION (reg), ARG_REGION (socket.current_region));
198 socket.current_region = reg;
199 }
200} 228}
201 229
202/** 230/**
203 * RequestInfo is sort of a meta command. There is some specific 231 * RequestInfo is sort of a meta command. There is some specific
204 * request of information, but we call other functions to provide 232 * request of information, but we call other functions to provide
263{ 291{
264 char *token = buf; 292 char *token = buf;
265 buf += strlen (buf) + 9; 293 buf += strlen (buf) + 9;
266 294
267 // initial map and its origin 295 // initial map and its origin
268 maptile *map = pl->ob->map; 296 maptile *map = pl->observe->map;
269 int mapx = pl->ns->mapx / 2 - pl->ob->x; 297 int mapx = pl->ns->mapx / 2 - pl->observe->x;
270 int mapy = pl->ns->mapy / 2 - pl->ob->y; 298 int mapy = pl->ns->mapy / 2 - pl->observe->y;
271 int max_distance = 8; // limit maximum path length to something generous 299 int max_distance = 8; // limit maximum path length to something generous
272 300
273 while (*buf && map && max_distance) 301 while (*buf && map && max_distance)
274 { 302 {
275 int dir = *buf++ - '1'; 303 int dir = *buf++ - '1';
276 304
277 if (dir >= 0 && dir <= 3) 305 if (dir >= 0 && dir <= 3)
278 { 306 {
279 if (!map->tile_path [dir]) 307 if (!map->tile_path [dir])
280 map = 0; 308 map = 0;
281 else if (map->tile_available (dir)) 309 else if (map->tile_available (dir, false))
282 { 310 {
283 maptile *neigh = map->tile_map [dir]; 311 maptile *neigh = map->tile_map [dir];
284 312
285 switch (dir) 313 switch (dir)
286 { 314 {
300 max_distance = 0; 328 max_distance = 0;
301 } 329 }
302 330
303 if (!max_distance) 331 if (!max_distance)
304 send_packet_printf ("mapinfo %s error", token); 332 send_packet_printf ("mapinfo %s error", token);
305 else if (!map || !map->path[0]) 333 else if (!map || !map->path)
306 send_packet_printf ("mapinfo %s nomap", token); 334 send_packet_printf ("mapinfo %s nomap", token);
307 else 335 else
308 { 336 {
309 int flags = 0; 337 int flags = 0;
310 338
686 * syntax is: move (to) (tag) (nrof) 714 * syntax is: move (to) (tag) (nrof)
687 */ 715 */
688void 716void
689MoveCmd (char *buf, int len, player *pl) 717MoveCmd (char *buf, int len, player *pl)
690{ 718{
691 int vals[3], i; 719 int to, tag, nrof;
692 720
693 /* A little funky here. We only cycle for 2 records, because 721 if (3 != sscanf (buf, "%d %d %d", &to, &tag, &nrof))
694 * we obviously are not going to find a space after the third
695 * record. Perhaps we should just replace this with a
696 * sscanf?
697 */
698 for (i = 0; i < 2; i++)
699 { 722 {
700 vals[i] = atoi (buf);
701
702 if (!(buf = strchr (buf, ' ')))
703 {
704 LOG (llevError, "Incomplete move command: %s\n", buf); 723 LOG (llevError, "Incomplete move command: %s\n", buf);
705 return; 724 return;
706 }
707
708 buf++;
709 } 725 }
710 726
711 vals[2] = atoi (buf); 727 esrv_move_object (pl->ob, to, tag, nrof);
712
713/* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/
714 esrv_move_object (pl->ob, vals[0], vals[1], vals[2]);
715} 728}
716 729
717/****************************************************************************** 730/******************************************************************************
718 * 731 *
719 * Start of commands the server sends to the client. 732 * Start of commands the server sends to the client.
886 899
887/** 900/**
888 * Tells the client that here is a player it should start using. 901 * Tells the client that here is a player it should start using.
889 */ 902 */
890void 903void
891esrv_new_player (player *pl, uint32 weight) 904esrv_new_player (player *pl)
892{ 905{
906 sint32 weight = pl->ob->client_weight ();
907
893 packet sl ("player"); 908 packet sl ("player");
894 909
895 sl << uint32 (pl->ob->count) 910 sl << uint32 (pl->ob->count)
896 << uint32 (weight) 911 << uint32 (weight)
897 << uint32 (pl->ob->face) 912 << uint32 (pl->ob->face)
1031 1046
1032 /* If player is just joining the game, he isn't here yet, so the map 1047 /* If player is just joining the game, he isn't here yet, so the map
1033 * can get swapped out. If so, don't try to send them a map. All will 1048 * can get swapped out. If so, don't try to send them a map. All will
1034 * be OK once they really log in. 1049 * be OK once they really log in.
1035 */ 1050 */
1036 if (!plmap || plmap->in_memory != MAP_IN_MEMORY) 1051 if (!plmap || plmap->in_memory != MAP_ACTIVE)
1037 return; 1052 return;
1038 1053
1039 int x, y, ax, ay, startlen, max_x, max_y, oldlen; 1054 int x, y, ax, ay, startlen, max_x, max_y, oldlen;
1040 int estartlen, eoldlen; 1055 int estartlen, eoldlen;
1041 uint8 eentrysize; 1056 uint8 eentrysize;
1129 1144
1130 if (!m) 1145 if (!m)
1131 { 1146 {
1132 nx = x; ny = y; m = plmap; 1147 nx = x; ny = y; m = plmap;
1133 1148
1134 if (!xy_normalise (m, nx, ny)) 1149 if (xy_normalise (m, nx, ny))
1150 m->touch ();
1151 else
1135 m = 0; 1152 m = 0;
1136 } 1153 }
1137 1154
1138 int emask, mask; 1155 int emask, mask;
1139 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1156 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1156 } 1173 }
1157 1174
1158 continue; 1175 continue;
1159 } 1176 }
1160 1177
1161 m->touch ();
1162
1163 int d = pl->blocked_los[ax][ay]; 1178 int d = pl->blocked_los[ax][ay];
1164 1179
1165 if (d > 3) 1180 if (d > 3)
1166 { 1181 {
1167
1168 int need_send = 0, count; 1182 int need_send = 0, count;
1169 1183
1170 /* This block deals with spaces that are not visible for whatever 1184 /* This block deals with spaces that are not visible for whatever
1171 * reason. Still may need to send the head for this space. 1185 * reason. Still may need to send the head for this space.
1172 */ 1186 */
1178 if (lastcell.count != -1) 1192 if (lastcell.count != -1)
1179 need_send = 1; 1193 need_send = 1;
1180 1194
1181 count = -1; 1195 count = -1;
1182 1196
1183 /* properly clear a previously sent big face */
1184 if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2] 1197 if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2]
1185 || lastcell.stat_hp || lastcell.flags || lastcell.player) 1198 || lastcell.stat_hp || lastcell.flags || lastcell.player)
1186 need_send = 1; 1199 need_send = 1;
1187 1200
1201 /* properly clear a previously sent big face */
1188 map_clearcell (&lastcell, count); 1202 map_clearcell (&lastcell, count);
1189 1203
1190 if ((mask & 0xf) || need_send) 1204 if ((mask & 0xf) || need_send)
1191 sl[oldlen + 1] = mask & 0xff; 1205 sl[oldlen + 1] = mask & 0xff;
1192 else 1206 else
1242 uint8 flags = 0; 1256 uint8 flags = 0;
1243 tag_t player = 0; 1257 tag_t player = 0;
1244 1258
1245 // send hp information, if applicable 1259 // send hp information, if applicable
1246 if (object *op = ms.faces_obj [0]) 1260 if (object *op = ms.faces_obj [0])
1261 if (op->is_head () && !op->invisible)
1247 { 1262 {
1248 if (op->head || op->invisible) 1263 if (op->stats.maxhp > op->stats.hp
1249 ; // do not show 1264 && op->stats.maxhp > 0
1250 else if (op->type == PLAYER 1265 && (op->type == PLAYER
1266 || op->type == DOOR // does not work, have maxhp 0
1251 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)) 1267 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR)))
1252 {
1253 if (op->stats.maxhp > 0 && (unsigned) op->stats.maxhp > (unsigned) op->stats.hp)
1254 { 1268 {
1255 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1269 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1256 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge 1270 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1257 } 1271 }
1258 }
1259 1272
1260 if (op->msg && op->msg[0] == '@') 1273 if (op->msg && op->msg[0] == '@')
1261 flags |= 1; 1274 flags |= 1;
1262 1275
1263 if (op->type == PLAYER && op != ob) 1276 if (op->type == PLAYER)
1264 player = op->count; 1277 player = op->count;
1265 } 1278 }
1266 1279
1267 if (lastcell.stat_hp != stat_hp) 1280 if (lastcell.stat_hp != stat_hp)
1268 { 1281 {
1269 lastcell.stat_hp = stat_hp; 1282 lastcell.stat_hp = stat_hp;
1270 1283
1473 if (spell->type == SPELL) 1486 if (spell->type == SPELL)
1474 { 1487 {
1475 int flags = 0; 1488 int flags = 0;
1476 1489
1477 /* check if we need to update it */ 1490 /* check if we need to update it */
1478 if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) 1491 if (spell->cached_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA))
1479 { 1492 {
1480 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1493 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1481 flags |= UPD_SP_MANA; 1494 flags |= UPD_SP_MANA;
1482 } 1495 }
1483 1496
1484 if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) 1497 if (spell->cached_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE))
1485 { 1498 {
1486 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1499 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1487 flags |= UPD_SP_GRACE; 1500 flags |= UPD_SP_GRACE;
1488 } 1501 }
1489 1502
1490 if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) 1503 if (spell->cached_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell))
1491 { 1504 {
1492 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1505 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1493 flags |= UPD_SP_DAMAGE; 1506 flags |= UPD_SP_DAMAGE;
1494 } 1507 }
1495 1508
1496 if (flags) 1509 if (flags)
1497 { 1510 {
1499 1512
1500 sl << "updspell " 1513 sl << "updspell "
1501 << uint8 (flags) 1514 << uint8 (flags)
1502 << uint32 (spell->count); 1515 << uint32 (spell->count);
1503 1516
1504 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 1517 if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp);
1505 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 1518 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->cached_grace);
1506 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 1519 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->cached_eat);
1507 1520
1508 pl->ns->send_packet (sl); 1521 pl->ns->send_packet (sl);
1509 } 1522 }
1510 } 1523 }
1511 } 1524 }
1541 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1554 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1542 return; 1555 return;
1543 } 1556 }
1544 1557
1545 /* store costs and damage in the object struct, to compare to later */ 1558 /* store costs and damage in the object struct, to compare to later */
1546 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1559 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1547 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1560 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1548 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1561 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1549 1562
1550 /* figure out which skill it uses, if it uses one */ 1563 /* figure out which skill it uses, if it uses one */
1551 if (spell->skill) 1564 if (spell->skill)
1552 { 1565 {
1553 for (i = 1; i < NUM_SKILLS; i++) 1566 for (i = 1; i < NUM_SKILLS; i++)
1569 1582
1570 /* send the current values */ 1583 /* send the current values */
1571 sl << uint32 (spell->count) 1584 sl << uint32 (spell->count)
1572 << uint16 (spell->level) 1585 << uint16 (spell->level)
1573 << uint16 (spell->casting_time) 1586 << uint16 (spell->casting_time)
1574 << uint16 (spell->last_sp) 1587 << uint16 (spell->cached_sp)
1575 << uint16 (spell->last_grace) 1588 << uint16 (spell->cached_grace)
1576 << uint16 (spell->last_eat) 1589 << uint16 (spell->cached_eat)
1577 << uint8 (skill) 1590 << uint8 (skill)
1578 << uint32 (spell->path_attuned) 1591 << uint32 (spell->path_attuned)
1579 << uint32 (spell->face) 1592 << uint32 (spell->face)
1580 << data8 (spell->name) 1593 << data8 (spell->name)
1581 << data16 (spell->msg); 1594 << data16 (spell->msg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines