1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_init_c = |
|
|
4 | * "$Id: request.C,v 1.17 2006/09/12 19:20:09 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2001 Mark Wedel |
4 | Copyright (C) 2001 Mark Wedel |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The author can be reached via e-mail to crossfire-devel@real-time.com |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | /** |
24 | /** |
31 | * \file |
25 | * \file |
32 | * Client handling. |
26 | * Client handling. |
… | |
… | |
50 | * operations |
44 | * operations |
51 | * |
45 | * |
52 | * esrv_map_doneredraw finishes the map update, and ships across the |
46 | * esrv_map_doneredraw finishes the map update, and ships across the |
53 | * map updates. |
47 | * map updates. |
54 | * |
48 | * |
55 | * esrv_map_scroll tells the client to scroll the map, and does similarily |
|
|
56 | * for the locally cached copy. |
|
|
57 | */ |
49 | */ |
58 | |
50 | |
59 | #include <global.h> |
51 | #include <global.h> |
60 | #include <sproto.h> |
52 | #include <sproto.h> |
61 | |
53 | |
… | |
… | |
266 | if (!strncmp (buf, "spatial ", 8)) |
258 | if (!strncmp (buf, "spatial ", 8)) |
267 | { |
259 | { |
268 | buf += 8; |
260 | buf += 8; |
269 | |
261 | |
270 | // initial map and its origin |
262 | // initial map and its origin |
271 | mapstruct *map = pl->ob->map; |
263 | maptile *map = pl->ob->map; |
272 | sint16 dx, dy; |
264 | sint16 dx, dy; |
273 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
265 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
274 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
266 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
275 | int max_distance = 8; // limit maximum path length to something generous |
267 | int max_distance = 8; // limit maximum path length to something generous |
276 | |
268 | |
… | |
… | |
1139 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1131 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1140 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1132 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1141 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1133 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1142 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1134 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1143 | } |
1135 | } |
|
|
1136 | |
1144 | if (pl->socket.exp64) |
1137 | if (pl->socket.exp64) |
1145 | { |
1138 | { |
1146 | uint8 s; |
1139 | uint8 s; |
1147 | |
1140 | |
1148 | for (s = 0; s < NUM_SKILLS; s++) |
1141 | for (s = 0; s < NUM_SKILLS; s++) |
… | |
… | |
1158 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1151 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1159 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1152 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1160 | } |
1153 | } |
1161 | } |
1154 | } |
1162 | } |
1155 | } |
|
|
1156 | |
1163 | if (pl->socket.exp64) |
1157 | if (pl->socket.exp64) |
1164 | { |
|
|
1165 | AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1158 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1166 | } |
|
|
1167 | else |
1159 | else |
1168 | { |
|
|
1169 | AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); |
1160 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1170 | } |
1161 | |
1171 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1162 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1172 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1163 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1173 | AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1164 | AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1174 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1165 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1175 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1166 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1176 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1167 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1177 | AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1168 | AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1178 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1169 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1179 | flags = 0; |
1170 | flags = 0; |
|
|
1171 | |
1180 | if (pl->fire_on) |
1172 | if (pl->fire_on) |
1181 | flags |= SF_FIREON; |
1173 | flags |= SF_FIREON; |
|
|
1174 | |
1182 | if (pl->run_on) |
1175 | if (pl->run_on) |
1183 | flags |= SF_RUNON; |
1176 | flags |= SF_RUNON; |
1184 | |
1177 | |
1185 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1178 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
|
|
1179 | |
1186 | if (pl->socket.sc_version < 1025) |
1180 | if (pl->socket.sc_version < 1025) |
1187 | { |
|
|
1188 | AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1181 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1189 | } |
|
|
1190 | else |
1182 | else |
1191 | { |
1183 | { |
1192 | int i; |
1184 | int i; |
1193 | |
1185 | |
1194 | for (i = 0; i < NROFATTACKS; i++) |
1186 | for (i = 0; i < NROFATTACKS; i++) |
1195 | { |
1187 | { |
1196 | /* Skip ones we won't send */ |
1188 | /* Skip ones we won't send */ |
1197 | if (atnr_cs_stat[i] == -1) |
1189 | if (atnr_cs_stat[i] == -1) |
1198 | continue; |
1190 | continue; |
|
|
1191 | |
1199 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1192 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1200 | } |
1193 | } |
1201 | } |
1194 | } |
|
|
1195 | |
1202 | if (pl->socket.monitor_spells) |
1196 | if (pl->socket.monitor_spells) |
1203 | { |
1197 | { |
1204 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1198 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1205 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1199 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1206 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1200 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1207 | } |
1201 | } |
|
|
1202 | |
1208 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1203 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1209 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1204 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1210 | set_title (pl->ob, buf); |
1205 | set_title (pl->ob, buf); |
1211 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1206 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1212 | |
1207 | |
… | |
… | |
1216 | #ifdef ESRV_DEBUG |
1211 | #ifdef ESRV_DEBUG |
1217 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1212 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1218 | #endif |
1213 | #endif |
1219 | Send_With_Handling (&pl->socket, &sl); |
1214 | Send_With_Handling (&pl->socket, &sl); |
1220 | } |
1215 | } |
|
|
1216 | |
1221 | free (sl.buf); |
1217 | free (sl.buf); |
1222 | } |
1218 | } |
1223 | |
|
|
1224 | |
1219 | |
1225 | /** |
1220 | /** |
1226 | * Tells the client that here is a player it should start using. |
1221 | * Tells the client that here is a player it should start using. |
1227 | */ |
1222 | */ |
1228 | void |
1223 | void |
… | |
… | |
1246 | |
1241 | |
1247 | Send_With_Handling (&pl->socket, &sl); |
1242 | Send_With_Handling (&pl->socket, &sl); |
1248 | free (sl.buf); |
1243 | free (sl.buf); |
1249 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1244 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1250 | } |
1245 | } |
1251 | |
|
|
1252 | |
1246 | |
1253 | /** |
1247 | /** |
1254 | * Need to send an animation sequence to the client. |
1248 | * Need to send an animation sequence to the client. |
1255 | * We will send appropriate face commands to the client if we haven't |
1249 | * We will send appropriate face commands to the client if we haven't |
1256 | * sent them the face yet (this can become quite costly in terms of |
1250 | * sent them the face yet (this can become quite costly in terms of |
… | |
… | |
1444 | |
1438 | |
1445 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1439 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1446 | { |
1440 | { |
1447 | /* All of this is just accounting stuff */ |
1441 | /* All of this is just accounting stuff */ |
1448 | if (tframes > 100) |
1442 | if (tframes > 100) |
1449 | { |
|
|
1450 | tframes = tbytes = 0; |
1443 | tframes = tbytes = 0; |
1451 | } |
1444 | |
1452 | tframes++; |
1445 | tframes++; |
1453 | frames++; |
1446 | frames++; |
1454 | tbytes += sl.len; |
1447 | tbytes += sl.len; |
1455 | bytes += sl.len; |
1448 | bytes += sl.len; |
1456 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1449 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1457 | Send_With_Handling (ns, &sl); |
1450 | Send_With_Handling (ns, &sl); |
1458 | ns->sent_scroll = 0; |
1451 | ns->sent_scroll = 0; |
1459 | } |
1452 | } |
|
|
1453 | |
1460 | free (sl.buf); |
1454 | free (sl.buf); |
1461 | } |
1455 | } |
1462 | |
1456 | |
1463 | |
1457 | |
1464 | /** Clears a map cell */ |
1458 | /** Clears a map cell */ |
… | |
… | |
1549 | * the case, it seems to make more sense to have these layer values |
1543 | * the case, it seems to make more sense to have these layer values |
1550 | * actually match. |
1544 | * actually match. |
1551 | */ |
1545 | */ |
1552 | |
1546 | |
1553 | static int |
1547 | static int |
1554 | update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1548 | update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1555 | { |
1549 | { |
1556 | object *ob, *head; |
1550 | object *ob, *head; |
1557 | uint16 face_num; |
1551 | uint16 face_num; |
1558 | int bx, by, i; |
1552 | int bx, by, i; |
1559 | |
1553 | |
… | |
… | |
1773 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1767 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1774 | * take. |
1768 | * take. |
1775 | */ |
1769 | */ |
1776 | |
1770 | |
1777 | static inline int |
1771 | static inline int |
1778 | update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1772 | update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1779 | { |
1773 | { |
1780 | object *ob; |
1774 | object *ob; |
1781 | int smoothlevel; /* old face_num; */ |
1775 | int smoothlevel; /* old face_num; */ |
1782 | |
1776 | |
1783 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1777 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1861 | SockList esl; /*For extended Map info */ |
1855 | SockList esl; /*For extended Map info */ |
1862 | uint16 mask, emask; |
1856 | uint16 mask, emask; |
1863 | uint8 eentrysize; |
1857 | uint8 eentrysize; |
1864 | uint16 ewhatstart, ewhatflag; |
1858 | uint16 ewhatstart, ewhatflag; |
1865 | uint8 extendedinfos; |
1859 | uint8 extendedinfos; |
1866 | mapstruct *m; |
1860 | maptile *m; |
1867 | |
1861 | |
1868 | NewSocket & socket = pl->contr->socket; |
1862 | NewSocket & socket = pl->contr->socket; |
1869 | |
1863 | |
1870 | check_map_change (pl->contr); |
1864 | check_map_change (pl->contr); |
1871 | |
1865 | |
… | |
… | |
2094 | |
2088 | |
2095 | if (socket.extmap) |
2089 | if (socket.extmap) |
2096 | { |
2090 | { |
2097 | uint8 stat_hp = 0; |
2091 | uint8 stat_hp = 0; |
2098 | uint8 stat_width = 0; |
2092 | uint8 stat_width = 0; |
|
|
2093 | uint8 flags = 0; |
2099 | tag_t player = 0; |
2094 | tag_t player = 0; |
2100 | |
2095 | |
2101 | // send hp information, if applicable |
2096 | // send hp information, if applicable |
2102 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2097 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2103 | { |
2098 | { |
… | |
… | |
2111 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2106 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2112 | stat_width = op->arch->tail_x; |
2107 | stat_width = op->arch->tail_x; |
2113 | } |
2108 | } |
2114 | } |
2109 | } |
2115 | |
2110 | |
|
|
2111 | if (op->msg && op->msg[0] == '@') |
|
|
2112 | flags |= 1; |
|
|
2113 | |
2116 | if (op->type == PLAYER && op != pl) |
2114 | if (op->type == PLAYER && op != pl) |
2117 | player = op->count; |
2115 | player = op->count; |
2118 | } |
2116 | } |
2119 | |
2117 | |
2120 | if (lastcell.stat_hp != stat_hp) |
2118 | if (lastcell.stat_hp != stat_hp) |
… | |
… | |
2134 | SockList_AddChar (&sl, 6); |
2132 | SockList_AddChar (&sl, 6); |
2135 | SockList_AddChar (&sl, stat_width); |
2133 | SockList_AddChar (&sl, stat_width); |
2136 | } |
2134 | } |
2137 | } |
2135 | } |
2138 | |
2136 | |
2139 | if (lastcell.player !=player) |
2137 | if (lastcell.player != player) |
2140 | { |
2138 | { |
2141 | lastcell.player = player; |
2139 | lastcell.player = player; |
2142 | |
2140 | |
2143 | mask |= 0x8; |
2141 | mask |= 0x8; |
2144 | *last_ext |= 0x80; |
2142 | *last_ext |= 0x80; |
2145 | last_ext = sl.buf + sl.len; |
2143 | last_ext = sl.buf + sl.len; |
2146 | SockList_AddChar (&sl, 0x47); |
2144 | SockList_AddChar (&sl, 0x47); |
2147 | SockList_AddChar (&sl, 4); |
2145 | SockList_AddChar (&sl, 4); |
2148 | SockList_AddInt (&sl, player); |
2146 | SockList_AddInt (&sl, player); |
|
|
2147 | } |
|
|
2148 | |
|
|
2149 | if (lastcell.flags != flags) |
|
|
2150 | { |
|
|
2151 | lastcell.flags = flags; |
|
|
2152 | |
|
|
2153 | mask |= 0x8; |
|
|
2154 | *last_ext |= 0x80; |
|
|
2155 | last_ext = sl.buf + sl.len; |
|
|
2156 | SockList_AddChar (&sl, 8); |
|
|
2157 | SockList_AddChar (&sl, flags); |
2149 | } |
2158 | } |
2150 | } |
2159 | } |
2151 | |
2160 | |
2152 | /* Floor face */ |
2161 | /* Floor face */ |
2153 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2162 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
… | |
… | |
2221 | * it doesn't need draw! |
2230 | * it doesn't need draw! |
2222 | */ |
2231 | */ |
2223 | ewhatflag &= (~EMI_NOREDRAW); |
2232 | ewhatflag &= (~EMI_NOREDRAW); |
2224 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2233 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2225 | } |
2234 | } |
|
|
2235 | |
2226 | if (esl.len > estartlen) |
2236 | if (esl.len > estartlen) |
2227 | { |
|
|
2228 | Send_With_Handling (&socket, &esl); |
2237 | Send_With_Handling (&socket, &esl); |
2229 | } |
2238 | |
2230 | free (esl.buf); |
2239 | free (esl.buf); |
2231 | } |
2240 | } |
|
|
2241 | |
2232 | if (sl.len > startlen || socket.sent_scroll) |
2242 | if (sl.len > startlen || socket.sent_scroll) |
2233 | { |
2243 | { |
2234 | Send_With_Handling (&socket, &sl); |
2244 | Send_With_Handling (&socket, &sl); |
2235 | socket.sent_scroll = 0; |
2245 | socket.sent_scroll = 0; |
2236 | } |
2246 | } |
|
|
2247 | |
2237 | free (sl.buf); |
2248 | free (sl.buf); |
2238 | } |
2249 | } |
2239 | |
2250 | |
2240 | /** |
2251 | /** |
2241 | * Draws client map. |
2252 | * Draws client map. |
… | |
… | |
2247 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2258 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2248 | New_Face *face, *floor; |
2259 | New_Face *face, *floor; |
2249 | New_Face *floor2; |
2260 | New_Face *floor2; |
2250 | int d, mflags; |
2261 | int d, mflags; |
2251 | struct Map newmap; |
2262 | struct Map newmap; |
2252 | mapstruct *m, *pm; |
2263 | maptile *m, *pm; |
2253 | |
2264 | |
2254 | if (pl->type != PLAYER) |
2265 | if (pl->type != PLAYER) |
2255 | { |
2266 | { |
2256 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2267 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2257 | return; |
2268 | return; |