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.125 by root, Tue Apr 22 04:33:20 2008 UTC vs.
Revision 1.140 by root, Thu Oct 2 16:08:19 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra 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 * Deliantra 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
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
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.
820 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); 833 AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS);
821 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); 834 AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW);
822 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); 835 AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA);
823 836
824 for (int s = 0; s < NUM_SKILLS; s++) 837 for (int s = 0; s < NUM_SKILLS; s++)
825 if (object *skill = opl->last_skill_ob[s]) 838 if (object *skill = opl->last_skill_ob [s])
826 if (skill->stats.exp != ns->last_skill_exp [s]) 839 if (skill->stats.exp != ns->last_skill_exp [s])
827 { 840 {
828 ns->last_skill_exp [s] = skill->stats.exp; 841 ns->last_skill_exp [s] = skill->stats.exp;
829 842
830 /* Always send along the level if exp changes. This is only 843 /* Always send along the level if exp changes. This is only
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)
898 << data8 (pl->ob->name); 913 << data8 (pl->ob->name);
899 914
900 pl->ns->last_weight = weight; 915 pl->ns->last_weight = weight;
901 pl->ns->send_packet (sl); 916 pl->ns->send_packet (sl);
902 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
903} 917}
904 918
905/****************************************************************************** 919/******************************************************************************
906 * 920 *
907 * Start of map related commands. 921 * Start of map related commands.
1162 1176
1163 int d = pl->blocked_los[ax][ay]; 1177 int d = pl->blocked_los[ax][ay];
1164 1178
1165 if (d > 3) 1179 if (d > 3)
1166 { 1180 {
1167
1168 int need_send = 0, count; 1181 int need_send = 0, count;
1169 1182
1170 /* This block deals with spaces that are not visible for whatever 1183 /* This block deals with spaces that are not visible for whatever
1171 * reason. Still may need to send the head for this space. 1184 * reason. Still may need to send the head for this space.
1172 */ 1185 */
1178 if (lastcell.count != -1) 1191 if (lastcell.count != -1)
1179 need_send = 1; 1192 need_send = 1;
1180 1193
1181 count = -1; 1194 count = -1;
1182 1195
1183 /* properly clear a previously sent big face */
1184 if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2] 1196 if (lastcell.faces[0] || lastcell.faces[1] || lastcell.faces[2]
1185 || lastcell.stat_hp || lastcell.flags || lastcell.player) 1197 || lastcell.stat_hp || lastcell.flags || lastcell.player)
1186 need_send = 1; 1198 need_send = 1;
1187 1199
1200 /* properly clear a previously sent big face */
1188 map_clearcell (&lastcell, count); 1201 map_clearcell (&lastcell, count);
1189 1202
1190 if ((mask & 0xf) || need_send) 1203 if ((mask & 0xf) || need_send)
1191 sl[oldlen + 1] = mask & 0xff; 1204 sl[oldlen + 1] = mask & 0xff;
1192 else 1205 else
1248 { 1261 {
1249 if (op->stats.maxhp > op->stats.hp 1262 if (op->stats.maxhp > op->stats.hp
1250 && op->stats.maxhp > 0 1263 && op->stats.maxhp > 0
1251 && (op->type == PLAYER 1264 && (op->type == PLAYER
1252 || op->type == DOOR // does not work, have maxhp 0 1265 || op->type == DOOR // does not work, have maxhp 0
1253 || QUERY_FLAG (op, FLAG_MONSTER) || QUERY_FLAG (op, FLAG_ALIVE) || QUERY_FLAG (op, FLAG_GENERATOR))) 1266 || QUERY_FLAG (op, FLAG_MONSTER)
1267 || QUERY_FLAG (op, FLAG_ALIVE)
1268 || QUERY_FLAG (op, FLAG_GENERATOR)))
1254 { 1269 {
1255 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1270 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 1271 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1257 } 1272 }
1258 1273
1259 if (op->msg && op->msg[0] == '@') 1274 if (op->has_dialogue ())
1260 flags |= 1; 1275 flags |= 1;
1261 1276
1262 if (op->type == PLAYER && op != ob) 1277 if (op->type == PLAYER)
1263 player = op->count; 1278 player = op == ob ? pl->ob->count
1279 : op == pl->ob ? ob->count
1280 : op->count;
1264 } 1281 }
1265 1282
1266 if (lastcell.stat_hp != stat_hp) 1283 if (lastcell.stat_hp != stat_hp)
1267 { 1284 {
1268 lastcell.stat_hp = stat_hp; 1285 lastcell.stat_hp = stat_hp;
1311 1328
1312 /* Middle face */ 1329 /* Middle face */
1313 if (update_space (sl, socket, ms, lastcell, 1)) 1330 if (update_space (sl, socket, ms, lastcell, 1))
1314 mask |= 0x2; 1331 mask |= 0x2;
1315 1332
1333 if (ob->invisible
1334 && ob->invisible & (ob->invisible < 50 ? 1 : 7)
1316 if (ms.player () == ob 1335 && ms.player () == ob)
1317 && (ob->invisible & (ob->invisible < 50 ? 1 : 7)))
1318 { 1336 {
1319 // force player to be visible to himself if invisible 1337 // force player to be visible to himself if invisible
1320 if (lastcell.faces[0] != ob->face) 1338 if (lastcell.faces[0] != ob->face)
1321 { 1339 {
1322 lastcell.faces[0] = ob->face; 1340 lastcell.faces[0] = ob->face;
1418{ 1436{
1419 packet sl; 1437 packet sl;
1420 sl << "replyinfo skill_info\n"; 1438 sl << "replyinfo skill_info\n";
1421 1439
1422 for (int i = 1; i < NUM_SKILLS; i++) 1440 for (int i = 1; i < NUM_SKILLS; i++)
1423 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 1441 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]);
1424 1442
1425 if (sl.length () > MAXSOCKBUF) 1443 if (sl.length () > MAXSOCKBUF)
1426 { 1444 {
1427 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 1445 LOG (llevError, "Buffer overflow in send_skill_info!\n");
1428 fatal (0); 1446 fatal (0);
1472 if (spell->type == SPELL) 1490 if (spell->type == SPELL)
1473 { 1491 {
1474 int flags = 0; 1492 int flags = 0;
1475 1493
1476 /* check if we need to update it */ 1494 /* check if we need to update it */
1477 if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) 1495 if (spell->cached_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA))
1478 { 1496 {
1479 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1497 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1480 flags |= UPD_SP_MANA; 1498 flags |= UPD_SP_MANA;
1481 } 1499 }
1482 1500
1483 if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) 1501 if (spell->cached_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE))
1484 { 1502 {
1485 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1503 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1486 flags |= UPD_SP_GRACE; 1504 flags |= UPD_SP_GRACE;
1487 } 1505 }
1488 1506
1489 if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) 1507 if (spell->cached_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell))
1490 { 1508 {
1491 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1509 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1492 flags |= UPD_SP_DAMAGE; 1510 flags |= UPD_SP_DAMAGE;
1493 } 1511 }
1494 1512
1495 if (flags) 1513 if (flags)
1496 { 1514 {
1498 1516
1499 sl << "updspell " 1517 sl << "updspell "
1500 << uint8 (flags) 1518 << uint8 (flags)
1501 << uint32 (spell->count); 1519 << uint32 (spell->count);
1502 1520
1503 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 1521 if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp);
1504 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 1522 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->cached_grace);
1505 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 1523 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->cached_eat);
1506 1524
1507 pl->ns->send_packet (sl); 1525 pl->ns->send_packet (sl);
1508 } 1526 }
1509 } 1527 }
1510 } 1528 }
1540 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 1558 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
1541 return; 1559 return;
1542 } 1560 }
1543 1561
1544 /* store costs and damage in the object struct, to compare to later */ 1562 /* store costs and damage in the object struct, to compare to later */
1545 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 1563 spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
1546 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 1564 spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
1547 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 1565 spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
1548 1566
1549 /* figure out which skill it uses, if it uses one */ 1567 /* figure out which skill it uses, if it uses one */
1550 if (spell->skill) 1568 if (spell->skill)
1551 { 1569 if (object *tmp = pl->find_skill (spell->skill))
1552 for (i = 1; i < NUM_SKILLS; i++)
1553 if (!strcmp (spell->skill, skill_names[i]))
1554 {
1555 skill = i + CS_STAT_SKILLINFO; 1570 skill = tmp->subtype + CS_STAT_SKILLINFO;
1556 break;
1557 }
1558 }
1559 1571
1560 // spells better have a face 1572 // spells better have a face
1561 if (!spell->face) 1573 if (!spell->face)
1562 { 1574 {
1563 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); 1575 LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name);
1568 1580
1569 /* send the current values */ 1581 /* send the current values */
1570 sl << uint32 (spell->count) 1582 sl << uint32 (spell->count)
1571 << uint16 (spell->level) 1583 << uint16 (spell->level)
1572 << uint16 (spell->casting_time) 1584 << uint16 (spell->casting_time)
1573 << uint16 (spell->last_sp) 1585 << uint16 (spell->cached_sp)
1574 << uint16 (spell->last_grace) 1586 << uint16 (spell->cached_grace)
1575 << uint16 (spell->last_eat) 1587 << uint16 (spell->cached_eat)
1576 << uint8 (skill) 1588 << uint8 (skill)
1577 << uint32 (spell->path_attuned) 1589 << uint32 (spell->path_attuned)
1578 << uint32 (spell->face) 1590 << uint32 (spell->face)
1579 << data8 (spell->name) 1591 << data8 (spell->name)
1580 << data16 (spell->msg); 1592 << data16 (spell->msg);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines