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 | |
… | |
… | |
65 | #include <commands.h> |
57 | #include <commands.h> |
66 | |
58 | |
67 | /* This block is basically taken from socket.c - I assume if it works there, |
59 | /* This block is basically taken from socket.c - I assume if it works there, |
68 | * it should work here. |
60 | * it should work here. |
69 | */ |
61 | */ |
70 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
|
|
71 | # include <sys/types.h> |
62 | #include <sys/types.h> |
72 | # include <sys/time.h> |
63 | #include <sys/time.h> |
73 | # include <sys/socket.h> |
64 | #include <sys/socket.h> |
74 | # include <netinet/in.h> |
65 | #include <netinet/in.h> |
75 | # include <netdb.h> |
66 | #include <netdb.h> |
76 | #endif /* win32 */ |
|
|
77 | |
67 | |
78 | #ifdef HAVE_UNISTD_H |
68 | #ifdef HAVE_UNISTD_H |
79 | # include <unistd.h> |
69 | # include <unistd.h> |
80 | #endif |
70 | #endif |
81 | |
71 | |
… | |
… | |
145 | for (x = 0; x < mx; x++) |
135 | for (x = 0; x < mx; x++) |
146 | { |
136 | { |
147 | for (y = 0; y < my; y++) |
137 | for (y = 0; y < my; y++) |
148 | { |
138 | { |
149 | if (x >= ns->mapx || y >= ns->mapy) |
139 | if (x >= ns->mapx || y >= ns->mapy) |
150 | { |
|
|
151 | /* clear cells outside the viewable area */ |
140 | /* clear cells outside the viewable area */ |
152 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
141 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
153 | } |
|
|
154 | else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) |
142 | else if ((x + dx) < 0 || (x + dx) >= ns->mapx || (y + dy) < 0 || (y + dy) >= ns->mapy) |
155 | { |
|
|
156 | /* clear newly visible tiles within the viewable area */ |
143 | /* clear newly visible tiles within the viewable area */ |
157 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
144 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
158 | } |
|
|
159 | else |
145 | else |
160 | { |
|
|
161 | memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); |
146 | memcpy (&(newmap.cells[x][y]), &(ns->lastmap.cells[x + dx][y + dy]), sizeof (struct MapCell)); |
162 | } |
|
|
163 | } |
147 | } |
164 | } |
148 | } |
165 | |
149 | |
166 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
150 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
167 | |
151 | |
… | |
… | |
266 | if (!strncmp (buf, "spatial ", 8)) |
250 | if (!strncmp (buf, "spatial ", 8)) |
267 | { |
251 | { |
268 | buf += 8; |
252 | buf += 8; |
269 | |
253 | |
270 | // initial map and its origin |
254 | // initial map and its origin |
271 | mapstruct *map = pl->ob->map; |
255 | maptile *map = pl->ob->map; |
272 | sint16 dx, dy; |
256 | sint16 dx, dy; |
273 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
257 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
274 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
258 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
275 | int max_distance = 8; // limit maximum path length to something generous |
259 | int max_distance = 8; // limit maximum path length to something generous |
276 | |
260 | |
… | |
… | |
720 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
704 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
721 | |
705 | |
722 | sl.buf = reply; |
706 | sl.buf = reply; |
723 | strcpy ((char *) sl.buf, "smooth "); |
707 | strcpy ((char *) sl.buf, "smooth "); |
724 | sl.len = strlen ((char *) sl.buf); |
708 | sl.len = strlen ((char *) sl.buf); |
725 | SockList_AddShort (&sl, face); |
709 | |
726 | SockList_AddShort (&sl, smoothface); |
710 | sl << uint16 (face) << uint16 (smoothface); |
|
|
711 | |
727 | Send_With_Handling (ns, &sl); |
712 | Send_With_Handling (ns, &sl); |
728 | } |
713 | } |
729 | |
714 | |
730 | /** |
715 | /** |
731 | * Tells client the picture it has to use |
716 | * Tells client the picture it has to use |
… | |
… | |
856 | |
841 | |
857 | /* Send confirmation of command execution now */ |
842 | /* Send confirmation of command execution now */ |
858 | sl.buf = command; |
843 | sl.buf = command; |
859 | strcpy ((char *) sl.buf, "comc "); |
844 | strcpy ((char *) sl.buf, "comc "); |
860 | sl.len = 5; |
845 | sl.len = 5; |
861 | SockList_AddShort (&sl, packet); |
846 | |
862 | if (FABS (pl->ob->speed) < 0.001) |
847 | if (FABS (pl->ob->speed) < 0.001) |
863 | time = MAX_TIME * 100; |
848 | time = MAX_TIME * 100; |
864 | else |
849 | else |
865 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
850 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
866 | SockList_AddInt (&sl, time); |
851 | |
|
|
852 | sl << uint16 (packet) << uint32 (time); |
|
|
853 | |
867 | Send_With_Handling (&pl->socket, &sl); |
854 | Send_With_Handling (&pl->socket, &sl); |
868 | } |
855 | } |
869 | |
856 | |
870 | |
857 | |
871 | /** This is a reply to a previous query. */ |
858 | /** This is a reply to a previous query. */ |
… | |
… | |
1139 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1126 | 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); |
1127 | 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); |
1128 | 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); |
1129 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1143 | } |
1130 | } |
|
|
1131 | |
1144 | if (pl->socket.exp64) |
1132 | if (pl->socket.exp64) |
1145 | { |
1133 | { |
1146 | uint8 s; |
1134 | uint8 s; |
1147 | |
1135 | |
1148 | for (s = 0; s < NUM_SKILLS; s++) |
1136 | for (s = 0; s < NUM_SKILLS; s++) |
… | |
… | |
1158 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1146 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1159 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1147 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1160 | } |
1148 | } |
1161 | } |
1149 | } |
1162 | } |
1150 | } |
|
|
1151 | |
1163 | if (pl->socket.exp64) |
1152 | if (pl->socket.exp64) |
1164 | { |
|
|
1165 | AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1153 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1166 | } |
|
|
1167 | else |
1154 | else |
1168 | { |
|
|
1169 | AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); |
1155 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1170 | } |
1156 | |
1171 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1157 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1172 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1158 | 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); |
1159 | 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); |
1160 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1175 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1161 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1176 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1162 | 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); |
1163 | 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); |
1164 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1179 | flags = 0; |
1165 | flags = 0; |
|
|
1166 | |
1180 | if (pl->fire_on) |
1167 | if (pl->fire_on) |
1181 | flags |= SF_FIREON; |
1168 | flags |= SF_FIREON; |
|
|
1169 | |
1182 | if (pl->run_on) |
1170 | if (pl->run_on) |
1183 | flags |= SF_RUNON; |
1171 | flags |= SF_RUNON; |
1184 | |
1172 | |
1185 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1173 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
|
|
1174 | |
1186 | if (pl->socket.sc_version < 1025) |
1175 | if (pl->socket.sc_version < 1025) |
1187 | { |
|
|
1188 | AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1176 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1189 | } |
|
|
1190 | else |
1177 | else |
1191 | { |
1178 | { |
1192 | int i; |
1179 | int i; |
1193 | |
1180 | |
1194 | for (i = 0; i < NROFATTACKS; i++) |
1181 | for (i = 0; i < NROFATTACKS; i++) |
1195 | { |
1182 | { |
1196 | /* Skip ones we won't send */ |
1183 | /* Skip ones we won't send */ |
1197 | if (atnr_cs_stat[i] == -1) |
1184 | if (atnr_cs_stat[i] == -1) |
1198 | continue; |
1185 | continue; |
|
|
1186 | |
1199 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1187 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1200 | } |
1188 | } |
1201 | } |
1189 | } |
|
|
1190 | |
1202 | if (pl->socket.monitor_spells) |
1191 | if (pl->socket.monitor_spells) |
1203 | { |
1192 | { |
1204 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1193 | 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); |
1194 | 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); |
1195 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1207 | } |
1196 | } |
|
|
1197 | |
1208 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1198 | 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); |
1199 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1210 | set_title (pl->ob, buf); |
1200 | set_title (pl->ob, buf); |
1211 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1201 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1212 | |
1202 | |
… | |
… | |
1216 | #ifdef ESRV_DEBUG |
1206 | #ifdef ESRV_DEBUG |
1217 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1207 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1218 | #endif |
1208 | #endif |
1219 | Send_With_Handling (&pl->socket, &sl); |
1209 | Send_With_Handling (&pl->socket, &sl); |
1220 | } |
1210 | } |
|
|
1211 | |
1221 | free (sl.buf); |
1212 | free (sl.buf); |
1222 | } |
1213 | } |
1223 | |
|
|
1224 | |
1214 | |
1225 | /** |
1215 | /** |
1226 | * Tells the client that here is a player it should start using. |
1216 | * Tells the client that here is a player it should start using. |
1227 | */ |
1217 | */ |
1228 | void |
1218 | void |
… | |
… | |
1246 | |
1236 | |
1247 | Send_With_Handling (&pl->socket, &sl); |
1237 | Send_With_Handling (&pl->socket, &sl); |
1248 | free (sl.buf); |
1238 | free (sl.buf); |
1249 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1239 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1250 | } |
1240 | } |
1251 | |
|
|
1252 | |
1241 | |
1253 | /** |
1242 | /** |
1254 | * Need to send an animation sequence to the client. |
1243 | * Need to send an animation sequence to the client. |
1255 | * We will send appropriate face commands to the client if we haven't |
1244 | * 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 |
1245 | * sent them the face yet (this can become quite costly in terms of |
… | |
… | |
1444 | |
1433 | |
1445 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1434 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
1446 | { |
1435 | { |
1447 | /* All of this is just accounting stuff */ |
1436 | /* All of this is just accounting stuff */ |
1448 | if (tframes > 100) |
1437 | if (tframes > 100) |
1449 | { |
|
|
1450 | tframes = tbytes = 0; |
1438 | tframes = tbytes = 0; |
1451 | } |
1439 | |
1452 | tframes++; |
1440 | tframes++; |
1453 | frames++; |
1441 | frames++; |
1454 | tbytes += sl.len; |
1442 | tbytes += sl.len; |
1455 | bytes += sl.len; |
1443 | bytes += sl.len; |
1456 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1444 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1457 | Send_With_Handling (ns, &sl); |
1445 | Send_With_Handling (ns, &sl); |
1458 | ns->sent_scroll = 0; |
1446 | ns->sent_scroll = 0; |
1459 | } |
1447 | } |
|
|
1448 | |
1460 | free (sl.buf); |
1449 | free (sl.buf); |
1461 | } |
1450 | } |
1462 | |
1451 | |
1463 | |
1452 | |
1464 | /** Clears a map cell */ |
1453 | /** Clears a map cell */ |
… | |
… | |
1466 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1455 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1467 | { |
1456 | { |
1468 | cell->faces[0] = face0; |
1457 | cell->faces[0] = face0; |
1469 | cell->faces[1] = face1; |
1458 | cell->faces[1] = face1; |
1470 | cell->faces[2] = face2; |
1459 | cell->faces[2] = face2; |
1471 | cell->count = count; |
1460 | cell->count = count; |
1472 | cell->stat_hp = 0; |
1461 | cell->stat_hp = 0; |
|
|
1462 | cell->flags = 0; |
1473 | cell->player = 0; |
1463 | cell->player = 0; |
1474 | } |
1464 | } |
1475 | |
1465 | |
1476 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1466 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1477 | #define MAX_LAYERS 3 |
1467 | #define MAX_LAYERS 3 |
1478 | |
1468 | |
… | |
… | |
1549 | * the case, it seems to make more sense to have these layer values |
1539 | * the case, it seems to make more sense to have these layer values |
1550 | * actually match. |
1540 | * actually match. |
1551 | */ |
1541 | */ |
1552 | |
1542 | |
1553 | static int |
1543 | static int |
1554 | update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1544 | update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1555 | { |
1545 | { |
1556 | object *ob, *head; |
1546 | object *ob, *head; |
1557 | uint16 face_num; |
1547 | uint16 face_num; |
1558 | int bx, by, i; |
1548 | int bx, by, i; |
1559 | |
1549 | |
… | |
… | |
1773 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1763 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1774 | * take. |
1764 | * take. |
1775 | */ |
1765 | */ |
1776 | |
1766 | |
1777 | static inline int |
1767 | static inline int |
1778 | update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1768 | update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1779 | { |
1769 | { |
1780 | object *ob; |
1770 | object *ob; |
1781 | int smoothlevel; /* old face_num; */ |
1771 | int smoothlevel; /* old face_num; */ |
1782 | |
1772 | |
1783 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1773 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1861 | SockList esl; /*For extended Map info */ |
1851 | SockList esl; /*For extended Map info */ |
1862 | uint16 mask, emask; |
1852 | uint16 mask, emask; |
1863 | uint8 eentrysize; |
1853 | uint8 eentrysize; |
1864 | uint16 ewhatstart, ewhatflag; |
1854 | uint16 ewhatstart, ewhatflag; |
1865 | uint8 extendedinfos; |
1855 | uint8 extendedinfos; |
1866 | mapstruct *m; |
1856 | maptile *m; |
1867 | |
1857 | |
1868 | NewSocket & socket = pl->contr->socket; |
1858 | NewSocket & socket = pl->contr->socket; |
1869 | |
1859 | |
1870 | check_map_change (pl->contr); |
1860 | check_map_change (pl->contr); |
1871 | |
1861 | |
… | |
… | |
1874 | strcpy ((char *) sl.buf, "map1 "); |
1864 | strcpy ((char *) sl.buf, "map1 "); |
1875 | else |
1865 | else |
1876 | strcpy ((char *) sl.buf, "map1a "); |
1866 | strcpy ((char *) sl.buf, "map1a "); |
1877 | sl.len = strlen ((char *) sl.buf); |
1867 | sl.len = strlen ((char *) sl.buf); |
1878 | startlen = sl.len; |
1868 | startlen = sl.len; |
|
|
1869 | |
1879 | /*Extendedmapinfo structure initialisation */ |
1870 | /*Extendedmapinfo structure initialisation */ |
1880 | if (socket.ext_mapinfos) |
1871 | if (socket.ext_mapinfos) |
1881 | { |
1872 | { |
1882 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1873 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1883 | strcpy ((char *) esl.buf, "mapextended "); |
1874 | strcpy ((char *) esl.buf, "mapextended "); |
1884 | esl.len = strlen ((char *) esl.buf); |
1875 | esl.len = strlen ((char *) esl.buf); |
1885 | extendedinfos = EMI_NOREDRAW; |
1876 | extendedinfos = EMI_NOREDRAW; |
|
|
1877 | |
1886 | if (socket.EMI_smooth) |
1878 | if (socket.EMI_smooth) |
1887 | extendedinfos |= EMI_SMOOTH; |
1879 | extendedinfos |= EMI_SMOOTH; |
|
|
1880 | |
1888 | ewhatstart = esl.len; |
1881 | ewhatstart = esl.len; |
1889 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1882 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1890 | could need to be taken away */ |
1883 | could need to be taken away */ |
1891 | SockList_AddChar (&esl, extendedinfos); |
1884 | SockList_AddChar (&esl, extendedinfos); |
1892 | eentrysize = getExtendedMapInfoSize (&socket); |
1885 | eentrysize = getExtendedMapInfoSize (&socket); |
… | |
… | |
1898 | /* suppress compiler warnings */ |
1891 | /* suppress compiler warnings */ |
1899 | ewhatstart = 0; |
1892 | ewhatstart = 0; |
1900 | ewhatflag = 0; |
1893 | ewhatflag = 0; |
1901 | estartlen = 0; |
1894 | estartlen = 0; |
1902 | } |
1895 | } |
|
|
1896 | |
1903 | /* Init data to zero */ |
1897 | /* Init data to zero */ |
1904 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1898 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1905 | |
1899 | |
1906 | /* x,y are the real map locations. ax, ay are viewport relative |
1900 | /* x,y are the real map locations. ax, ay are viewport relative |
1907 | * locations. |
1901 | * locations. |
… | |
… | |
1911 | /* We could do this logic as conditionals in the if statement, |
1905 | /* We could do this logic as conditionals in the if statement, |
1912 | * but that started to get a bit messy to look at. |
1906 | * but that started to get a bit messy to look at. |
1913 | */ |
1907 | */ |
1914 | max_x = pl->x + (socket.mapx + 1) / 2; |
1908 | max_x = pl->x + (socket.mapx + 1) / 2; |
1915 | max_y = pl->y + (socket.mapy + 1) / 2; |
1909 | max_y = pl->y + (socket.mapy + 1) / 2; |
|
|
1910 | |
1916 | if (socket.mapmode == Map1aCmd) |
1911 | if (socket.mapmode == Map1aCmd) |
1917 | { |
1912 | { |
1918 | max_x += MAX_HEAD_OFFSET; |
1913 | max_x += MAX_HEAD_OFFSET; |
1919 | max_y += MAX_HEAD_OFFSET; |
1914 | max_y += MAX_HEAD_OFFSET; |
1920 | } |
1915 | } |
… | |
… | |
1953 | * with no faces tells the client to blank out the |
1948 | * with no faces tells the client to blank out the |
1954 | * space. |
1949 | * space. |
1955 | */ |
1950 | */ |
1956 | got_one = 0; |
1951 | got_one = 0; |
1957 | for (i = oldlen + 2; i < sl.len; i++) |
1952 | for (i = oldlen + 2; i < sl.len; i++) |
1958 | { |
|
|
1959 | if (sl.buf[i]) |
1953 | if (sl.buf[i]) |
1960 | got_one = 1; |
1954 | got_one = 1; |
1961 | } |
|
|
1962 | |
1955 | |
1963 | if (got_one && (mask & 0xf)) |
1956 | if (got_one && (mask & 0xf)) |
1964 | { |
|
|
1965 | sl.buf[oldlen + 1] = mask & 0xff; |
1957 | sl.buf[oldlen + 1] = mask & 0xff; |
1966 | } |
|
|
1967 | else |
1958 | else |
1968 | { /*either all faces blank, either no face at all */ |
1959 | { /*either all faces blank, either no face at all */ |
1969 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1960 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1970 | sl.len = oldlen + 2; |
1961 | sl.len = oldlen + 2; |
1971 | else |
1962 | else |
1972 | sl.len = oldlen; |
1963 | sl.len = oldlen; |
1973 | } |
1964 | } |
|
|
1965 | |
1974 | /*What concerns extendinfos, nothing to be done for now |
1966 | /*What concerns extendinfos, nothing to be done for now |
1975 | * (perhaps effects layer later) |
1967 | * (perhaps effects layer later) |
1976 | */ |
1968 | */ |
1977 | continue; /* don't do processing below */ |
1969 | continue; /* don't do processing below */ |
1978 | } |
1970 | } |
1979 | |
1971 | |
1980 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1972 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1981 | |
1973 | |
1982 | d = pl->contr->blocked_los[ax][ay]; |
1974 | d = pl->contr->blocked_los[ax][ay]; |
1983 | |
1975 | |
1984 | /* If the coordinates are not valid, or it is too dark to see, |
1976 | /* If the coordinates are not valid, or it is too dark to see, |
1985 | * we tell the client as such |
1977 | * we tell the client as such |
1986 | */ |
1978 | */ |
1987 | nx = x; |
1979 | nx = x; |
1988 | ny = y; |
1980 | ny = y; |
1989 | m = get_map_from_coord (pl->map, &nx, &ny); |
1981 | m = get_map_from_coord (pl->map, &nx, &ny); |
|
|
1982 | |
1990 | if (!m) |
1983 | if (!m) |
1991 | { |
1984 | { |
1992 | /* space is out of map. Update space and clear values |
1985 | /* space is out of map. Update space and clear values |
1993 | * if this hasn't already been done. If the space is out |
1986 | * if this hasn't already been done. If the space is out |
1994 | * of the map, it shouldn't have a head |
1987 | * of the map, it shouldn't have a head |
… | |
… | |
2008 | */ |
2001 | */ |
2009 | |
2002 | |
2010 | oldlen = sl.len; |
2003 | oldlen = sl.len; |
2011 | |
2004 | |
2012 | SockList_AddShort (&sl, mask); |
2005 | SockList_AddShort (&sl, mask); |
|
|
2006 | |
2013 | if (lastcell.count != -1) |
2007 | if (lastcell.count != -1) |
2014 | need_send = 1; |
2008 | need_send = 1; |
|
|
2009 | |
2015 | count = -1; |
2010 | count = -1; |
2016 | |
2011 | |
2017 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2018 | { |
2013 | { |
2019 | /* Now check to see if any heads need to be sent */ |
2014 | /* Now check to see if any heads need to be sent */ |
… | |
… | |
2024 | mask |= 0x2; |
2019 | mask |= 0x2; |
2025 | if (check_head (sl, socket, ax, ay, 0)) |
2020 | if (check_head (sl, socket, ax, ay, 0)) |
2026 | mask |= 0x1; |
2021 | mask |= 0x1; |
2027 | |
2022 | |
2028 | lastcell.count = count; |
2023 | lastcell.count = count; |
2029 | |
|
|
2030 | } |
2024 | } |
2031 | else |
2025 | else |
2032 | { |
2026 | { |
2033 | struct MapCell *cell = &lastcell; |
|
|
2034 | |
|
|
2035 | /* properly clear a previously sent big face */ |
2027 | /* properly clear a previously sent big face */ |
2036 | if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) |
2028 | if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0 |
|
|
2029 | || lastcell.stat_hp || lastcell.flags || lastcell.player) |
2037 | need_send = 1; |
2030 | need_send = 1; |
|
|
2031 | |
2038 | map_clearcell (&lastcell, 0, 0, 0, count); |
2032 | map_clearcell (&lastcell, 0, 0, 0, count); |
2039 | } |
2033 | } |
2040 | |
2034 | |
2041 | if ((mask & 0xf) || need_send) |
2035 | if ((mask & 0xf) || need_send) |
2042 | { |
|
|
2043 | sl.buf[oldlen + 1] = mask & 0xff; |
2036 | sl.buf[oldlen + 1] = mask & 0xff; |
2044 | } |
|
|
2045 | else |
2037 | else |
2046 | { |
|
|
2047 | sl.len = oldlen; |
2038 | sl.len = oldlen; |
2048 | } |
|
|
2049 | } |
2039 | } |
2050 | else |
2040 | else |
2051 | { |
2041 | { |
2052 | /* In this block, the space is visible or there are head objects |
2042 | /* In this block, the space is visible or there are head objects |
2053 | * we need to send. |
2043 | * we need to send. |
… | |
… | |
2094 | |
2084 | |
2095 | if (socket.extmap) |
2085 | if (socket.extmap) |
2096 | { |
2086 | { |
2097 | uint8 stat_hp = 0; |
2087 | uint8 stat_hp = 0; |
2098 | uint8 stat_width = 0; |
2088 | uint8 stat_width = 0; |
|
|
2089 | uint8 flags = 0; |
2099 | tag_t player = 0; |
2090 | UUID player = 0; |
2100 | |
2091 | |
2101 | // send hp information, if applicable |
2092 | // send hp information, if applicable |
2102 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2093 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2103 | { |
2094 | { |
2104 | if (op->head || op->invisible) |
2095 | if (op->head || op->invisible) |
… | |
… | |
2111 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2102 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2112 | stat_width = op->arch->tail_x; |
2103 | stat_width = op->arch->tail_x; |
2113 | } |
2104 | } |
2114 | } |
2105 | } |
2115 | |
2106 | |
|
|
2107 | if (op->msg && op->msg[0] == '@') |
|
|
2108 | flags |= 1; |
|
|
2109 | |
2116 | if (op->type == PLAYER && op != pl) |
2110 | if (op->type == PLAYER && op != pl) |
2117 | player = op->count; |
2111 | player = op->count; |
2118 | } |
2112 | } |
2119 | |
2113 | |
2120 | if (lastcell.stat_hp != stat_hp) |
2114 | if (lastcell.stat_hp != stat_hp) |
… | |
… | |
2122 | lastcell.stat_hp = stat_hp; |
2116 | lastcell.stat_hp = stat_hp; |
2123 | |
2117 | |
2124 | mask |= 0x8; |
2118 | mask |= 0x8; |
2125 | *last_ext |= 0x80; |
2119 | *last_ext |= 0x80; |
2126 | last_ext = sl.buf + sl.len; |
2120 | last_ext = sl.buf + sl.len; |
2127 | SockList_AddChar (&sl, 5); |
2121 | |
2128 | SockList_AddChar (&sl, stat_hp); |
2122 | sl << uint8 (5) << uint8 (stat_hp); |
2129 | |
2123 | |
2130 | if (stat_width > 1) |
2124 | if (stat_width > 1) |
2131 | { |
2125 | { |
2132 | *last_ext |= 0x80; |
2126 | *last_ext |= 0x80; |
2133 | last_ext = sl.buf + sl.len; |
2127 | last_ext = sl.buf + sl.len; |
2134 | SockList_AddChar (&sl, 6); |
2128 | |
2135 | SockList_AddChar (&sl, stat_width); |
2129 | sl << uint8 (6) << uint8 (stat_width); |
2136 | } |
2130 | } |
2137 | } |
2131 | } |
2138 | |
2132 | |
2139 | if (lastcell.player !=player) |
2133 | if (lastcell.player != player) |
2140 | { |
2134 | { |
2141 | lastcell.player = player; |
2135 | lastcell.player = player; |
2142 | |
2136 | |
2143 | mask |= 0x8; |
2137 | mask |= 0x8; |
2144 | *last_ext |= 0x80; |
2138 | *last_ext |= 0x80; |
2145 | last_ext = sl.buf + sl.len; |
2139 | last_ext = sl.buf + sl.len; |
2146 | SockList_AddChar (&sl, 0x47); |
2140 | |
2147 | SockList_AddChar (&sl, 4); |
2141 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2148 | SockList_AddInt (&sl, player); |
2142 | } |
|
|
2143 | |
|
|
2144 | if (lastcell.flags != flags) |
|
|
2145 | { |
|
|
2146 | lastcell.flags = flags; |
|
|
2147 | |
|
|
2148 | mask |= 0x8; |
|
|
2149 | *last_ext |= 0x80; |
|
|
2150 | last_ext = sl.buf + sl.len; |
|
|
2151 | |
|
|
2152 | sl << uint8 (8) << uint8 (flags); |
2149 | } |
2153 | } |
2150 | } |
2154 | } |
2151 | |
2155 | |
2152 | /* Floor face */ |
2156 | /* Floor face */ |
2153 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2157 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
… | |
… | |
2169 | { |
2173 | { |
2170 | if (lastcell.faces[0] != pl->face->number) |
2174 | if (lastcell.faces[0] != pl->face->number) |
2171 | { |
2175 | { |
2172 | lastcell.faces[0] = pl->face->number; |
2176 | lastcell.faces[0] = pl->face->number; |
2173 | mask |= 0x1; |
2177 | mask |= 0x1; |
|
|
2178 | |
2174 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2179 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2175 | esrv_send_face (&socket, pl->face->number, 0); |
2180 | esrv_send_face (&socket, pl->face->number, 0); |
2176 | SockList_AddShort (&sl, pl->face->number); |
2181 | |
|
|
2182 | sl << uint16 (pl->face->number); |
2177 | } |
2183 | } |
2178 | } |
2184 | } |
2179 | /* Top face */ |
|
|
2180 | else |
2185 | else |
2181 | { |
2186 | { |
|
|
2187 | /* Top face */ |
2182 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2188 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2183 | mask |= 0x1; |
2189 | mask |= 0x1; |
|
|
2190 | |
2184 | if (socket.EMI_smooth) |
2191 | if (socket.EMI_smooth) |
2185 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2192 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2186 | { |
|
|
2187 | emask |= 0x1; |
2193 | emask |= 0x1; |
2188 | } |
|
|
2189 | } |
2194 | } |
|
|
2195 | |
2190 | /* Check to see if we are in fact sending anything for this |
2196 | /* Check to see if we are in fact sending anything for this |
2191 | * space by checking the mask. If so, update the mask. |
2197 | * space by checking the mask. If so, update the mask. |
2192 | * if not, reset the len to that from before adding the mask |
2198 | * if not, reset the len to that from before adding the mask |
2193 | * value, so we don't send those bits. |
2199 | * value, so we don't send those bits. |
2194 | */ |
2200 | */ |
2195 | if (mask & 0xf) |
2201 | if (mask & 0xf) |
2196 | { |
|
|
2197 | sl.buf[oldlen + 1] = mask & 0xff; |
2202 | sl.buf[oldlen + 1] = mask & 0xff; |
2198 | } |
|
|
2199 | else |
2203 | else |
2200 | { |
|
|
2201 | sl.len = oldlen; |
2204 | sl.len = oldlen; |
2202 | } |
2205 | |
2203 | if (emask & 0xf) |
2206 | if (emask & 0xf) |
2204 | { |
|
|
2205 | esl.buf[eoldlen + 1] = emask & 0xff; |
2207 | esl.buf[eoldlen + 1] = emask & 0xff; |
2206 | } |
|
|
2207 | else |
2208 | else |
2208 | { |
|
|
2209 | esl.len = eoldlen; |
2209 | esl.len = eoldlen; |
2210 | } |
|
|
2211 | } /* else this is a viewable space */ |
2210 | } /* else this is a viewable space */ |
2212 | } /* for x loop */ |
2211 | } /* for x loop */ |
2213 | } /* for y loop */ |
2212 | } /* for y loop */ |
2214 | |
2213 | |
2215 | /* Verify that we in fact do need to send this */ |
2214 | /* Verify that we in fact do need to send this */ |
… | |
… | |
2221 | * it doesn't need draw! |
2220 | * it doesn't need draw! |
2222 | */ |
2221 | */ |
2223 | ewhatflag &= (~EMI_NOREDRAW); |
2222 | ewhatflag &= (~EMI_NOREDRAW); |
2224 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2223 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2225 | } |
2224 | } |
|
|
2225 | |
2226 | if (esl.len > estartlen) |
2226 | if (esl.len > estartlen) |
2227 | { |
|
|
2228 | Send_With_Handling (&socket, &esl); |
2227 | Send_With_Handling (&socket, &esl); |
2229 | } |
2228 | |
2230 | free (esl.buf); |
2229 | free (esl.buf); |
2231 | } |
2230 | } |
|
|
2231 | |
2232 | if (sl.len > startlen || socket.sent_scroll) |
2232 | if (sl.len > startlen || socket.sent_scroll) |
2233 | { |
2233 | { |
2234 | Send_With_Handling (&socket, &sl); |
2234 | Send_With_Handling (&socket, &sl); |
2235 | socket.sent_scroll = 0; |
2235 | socket.sent_scroll = 0; |
2236 | } |
2236 | } |
|
|
2237 | |
2237 | free (sl.buf); |
2238 | free (sl.buf); |
2238 | } |
2239 | } |
2239 | |
2240 | |
2240 | /** |
2241 | /** |
2241 | * Draws client map. |
2242 | * Draws client map. |
… | |
… | |
2247 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2248 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2248 | New_Face *face, *floor; |
2249 | New_Face *face, *floor; |
2249 | New_Face *floor2; |
2250 | New_Face *floor2; |
2250 | int d, mflags; |
2251 | int d, mflags; |
2251 | struct Map newmap; |
2252 | struct Map newmap; |
2252 | mapstruct *m, *pm; |
2253 | maptile *m, *pm; |
2253 | |
2254 | |
2254 | if (pl->type != PLAYER) |
2255 | if (pl->type != PLAYER) |
2255 | { |
2256 | { |
2256 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2257 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2257 | return; |
2258 | return; |
… | |
… | |
2465 | if (flags != 0) |
2466 | if (flags != 0) |
2466 | { |
2467 | { |
2467 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2468 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2468 | strcpy ((char *) sl.buf, "updspell "); |
2469 | strcpy ((char *) sl.buf, "updspell "); |
2469 | sl.len = strlen ((char *) sl.buf); |
2470 | sl.len = strlen ((char *) sl.buf); |
2470 | SockList_AddChar (&sl, flags); |
2471 | |
2471 | SockList_AddInt (&sl, spell->count); |
2472 | sl << uint8 (flags) << uint32 (spell->count); |
2472 | if (flags & UPD_SP_MANA) |
2473 | |
2473 | SockList_AddShort (&sl, spell->last_sp); |
2474 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2474 | if (flags & UPD_SP_GRACE) |
2475 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2475 | SockList_AddShort (&sl, spell->last_grace); |
2476 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2476 | if (flags & UPD_SP_DAMAGE) |
2477 | |
2477 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2478 | flags = 0; |
2478 | flags = 0; |
2479 | Send_With_Handling (&pl->socket, &sl); |
2479 | Send_With_Handling (&pl->socket, &sl); |
2480 | free (sl.buf); |
2480 | free (sl.buf); |
2481 | } |
2481 | } |
2482 | } |
2482 | } |
… | |
… | |
2496 | return; |
2496 | return; |
2497 | } |
2497 | } |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2499 | strcpy ((char *) sl.buf, "delspell "); |
2499 | strcpy ((char *) sl.buf, "delspell "); |
2500 | sl.len = strlen ((char *) sl.buf); |
2500 | sl.len = strlen ((char *) sl.buf); |
2501 | SockList_AddInt (&sl, spell->count); |
2501 | |
|
|
2502 | sl << uint32 (spell->count); |
|
|
2503 | |
2502 | Send_With_Handling (&pl->socket, &sl); |
2504 | Send_With_Handling (&pl->socket, &sl); |
2503 | free (sl.buf); |
2505 | free (sl.buf); |
2504 | } |
2506 | } |
2505 | |
2507 | |
2506 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2508 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2507 | static void |
2509 | static void |
2508 | append_spell (player *pl, SockList * sl, object *spell) |
2510 | append_spell (player *pl, SockList &sl, object *spell) |
2509 | { |
2511 | { |
2510 | int len, i, skill = 0; |
2512 | int len, i, skill = 0; |
2511 | |
2513 | |
2512 | if (!(spell->name)) |
2514 | if (!(spell->name)) |
2513 | { |
2515 | { |
2514 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2516 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2515 | return; |
2517 | return; |
2516 | } |
2518 | } |
2517 | SockList_AddInt (sl, spell->count); |
2519 | |
2518 | SockList_AddShort (sl, spell->level); |
|
|
2519 | SockList_AddShort (sl, spell->casting_time); |
|
|
2520 | /* store costs and damage in the object struct, to compare to later */ |
2520 | /* store costs and damage in the object struct, to compare to later */ |
2521 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2521 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2522 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2522 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2523 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2523 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2524 | /* send the current values */ |
|
|
2525 | SockList_AddShort (sl, spell->last_sp); |
|
|
2526 | SockList_AddShort (sl, spell->last_grace); |
|
|
2527 | SockList_AddShort (sl, spell->last_eat); |
|
|
2528 | |
2524 | |
2529 | /* figure out which skill it uses, if it uses one */ |
2525 | /* figure out which skill it uses, if it uses one */ |
2530 | if (spell->skill) |
2526 | if (spell->skill) |
2531 | { |
2527 | { |
2532 | for (i = 1; i < NUM_SKILLS; i++) |
2528 | for (i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2534 | { |
2530 | { |
2535 | skill = i + CS_STAT_SKILLINFO; |
2531 | skill = i + CS_STAT_SKILLINFO; |
2536 | break; |
2532 | break; |
2537 | } |
2533 | } |
2538 | } |
2534 | } |
2539 | SockList_AddChar (sl, skill); |
|
|
2540 | |
2535 | |
2541 | SockList_AddInt (sl, spell->path_attuned); |
2536 | /* send the current values */ |
|
|
2537 | sl << uint32 (spell->count) |
|
|
2538 | << uint16 (spell->level) |
|
|
2539 | << uint16 (spell->casting_time) |
|
|
2540 | << uint16 (spell->last_sp) |
|
|
2541 | << uint16 (spell->last_grace) |
|
|
2542 | << uint16 (spell->last_eat) |
|
|
2543 | << uint8 (skill) |
|
|
2544 | << uint32 (spell->path_attuned) |
2542 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2545 | << uint32 (spell->face ? spell->face->number : 0) |
2543 | |
2546 | << data8 (spell->name) |
2544 | len = strlen (spell->name); |
2547 | << data16 (spell->msg); |
2545 | SockList_AddChar (sl, (char) len); |
|
|
2546 | memcpy (sl->buf + sl->len, spell->name, len); |
|
|
2547 | sl->len += len; |
|
|
2548 | |
|
|
2549 | if (!spell->msg) |
|
|
2550 | { |
|
|
2551 | SockList_AddShort (sl, 0); |
|
|
2552 | } |
|
|
2553 | else |
|
|
2554 | { |
|
|
2555 | len = strlen (spell->msg); |
|
|
2556 | SockList_AddShort (sl, len); |
|
|
2557 | memcpy (sl->buf + sl->len, spell->msg, len); |
|
|
2558 | sl->len += len; |
|
|
2559 | } |
|
|
2560 | } |
2548 | } |
2561 | |
2549 | |
2562 | /** |
2550 | /** |
2563 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2551 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2564 | * all spells in the player's inventory. |
2552 | * all spells in the player's inventory. |
… | |
… | |
2595 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2583 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2596 | * like it will fix this |
2584 | * like it will fix this |
2597 | */ |
2585 | */ |
2598 | if (spell->type != SPELL) |
2586 | if (spell->type != SPELL) |
2599 | continue; |
2587 | continue; |
|
|
2588 | |
2600 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2589 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2601 | { |
2590 | { |
2602 | Send_With_Handling (&pl->socket, &sl); |
2591 | Send_With_Handling (&pl->socket, &sl); |
2603 | strcpy ((char *) sl.buf, "addspell "); |
2592 | strcpy ((char *) sl.buf, "addspell "); |
2604 | sl.len = strlen ((char *) sl.buf); |
2593 | sl.len = strlen ((char *) sl.buf); |
2605 | } |
2594 | } |
|
|
2595 | |
2606 | append_spell (pl, &sl, spell); |
2596 | append_spell (pl, sl, spell); |
2607 | } |
2597 | } |
2608 | } |
2598 | } |
2609 | else if (spell->type != SPELL) |
2599 | else if (spell->type != SPELL) |
2610 | { |
2600 | { |
2611 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2601 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2612 | return; |
2602 | return; |
2613 | } |
2603 | } |
2614 | else |
2604 | else |
2615 | append_spell (pl, &sl, spell); |
2605 | append_spell (pl, sl, spell); |
|
|
2606 | |
2616 | if (sl.len >= MAXSOCKBUF) |
2607 | if (sl.len >= MAXSOCKBUF) |
2617 | { |
2608 | { |
2618 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2609 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2619 | fatal (0); |
2610 | fatal (0); |
2620 | } |
2611 | } |
|
|
2612 | |
2621 | /* finally, we can send the packet */ |
2613 | /* finally, we can send the packet */ |
2622 | Send_With_Handling (&pl->socket, &sl); |
2614 | Send_With_Handling (&pl->socket, &sl); |
2623 | free (sl.buf); |
2615 | free (sl.buf); |
2624 | } |
2616 | } |