1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_init_c = |
|
|
4 | * "$Id: request.C,v 1.18 2006/09/14 19:08:41 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. |
… | |
… | |
63 | #include <commands.h> |
57 | #include <commands.h> |
64 | |
58 | |
65 | /* 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, |
66 | * it should work here. |
60 | * it should work here. |
67 | */ |
61 | */ |
68 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
|
|
69 | # include <sys/types.h> |
62 | #include <sys/types.h> |
70 | # include <sys/time.h> |
63 | #include <sys/time.h> |
71 | # include <sys/socket.h> |
64 | #include <sys/socket.h> |
72 | # include <netinet/in.h> |
65 | #include <netinet/in.h> |
73 | # include <netdb.h> |
66 | #include <netdb.h> |
74 | #endif /* win32 */ |
|
|
75 | |
67 | |
76 | #ifdef HAVE_UNISTD_H |
68 | #ifdef HAVE_UNISTD_H |
77 | # include <unistd.h> |
69 | # include <unistd.h> |
78 | #endif |
70 | #endif |
79 | |
71 | |
… | |
… | |
143 | for (x = 0; x < mx; x++) |
135 | for (x = 0; x < mx; x++) |
144 | { |
136 | { |
145 | for (y = 0; y < my; y++) |
137 | for (y = 0; y < my; y++) |
146 | { |
138 | { |
147 | if (x >= ns->mapx || y >= ns->mapy) |
139 | if (x >= ns->mapx || y >= ns->mapy) |
148 | { |
|
|
149 | /* clear cells outside the viewable area */ |
140 | /* clear cells outside the viewable area */ |
150 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
141 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
151 | } |
|
|
152 | 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) |
153 | { |
|
|
154 | /* clear newly visible tiles within the viewable area */ |
143 | /* clear newly visible tiles within the viewable area */ |
155 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
144 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
156 | } |
|
|
157 | else |
145 | else |
158 | { |
|
|
159 | 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)); |
160 | } |
|
|
161 | } |
147 | } |
162 | } |
148 | } |
163 | |
149 | |
164 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
150 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
165 | |
151 | |
… | |
… | |
264 | if (!strncmp (buf, "spatial ", 8)) |
250 | if (!strncmp (buf, "spatial ", 8)) |
265 | { |
251 | { |
266 | buf += 8; |
252 | buf += 8; |
267 | |
253 | |
268 | // initial map and its origin |
254 | // initial map and its origin |
269 | mapstruct *map = pl->ob->map; |
255 | maptile *map = pl->ob->map; |
270 | sint16 dx, dy; |
256 | sint16 dx, dy; |
271 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
257 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
272 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
258 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
273 | int max_distance = 8; // limit maximum path length to something generous |
259 | int max_distance = 8; // limit maximum path length to something generous |
274 | |
260 | |
… | |
… | |
1137 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1123 | AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); |
1138 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1124 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1139 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1125 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1140 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1126 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1141 | } |
1127 | } |
|
|
1128 | |
1142 | if (pl->socket.exp64) |
1129 | if (pl->socket.exp64) |
1143 | { |
1130 | { |
1144 | uint8 s; |
1131 | uint8 s; |
1145 | |
1132 | |
1146 | for (s = 0; s < NUM_SKILLS; s++) |
1133 | for (s = 0; s < NUM_SKILLS; s++) |
… | |
… | |
1156 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1143 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1157 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1144 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1158 | } |
1145 | } |
1159 | } |
1146 | } |
1160 | } |
1147 | } |
|
|
1148 | |
1161 | if (pl->socket.exp64) |
1149 | if (pl->socket.exp64) |
1162 | { |
|
|
1163 | AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1150 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1164 | } |
|
|
1165 | else |
1151 | else |
1166 | { |
|
|
1167 | AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP); |
1152 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1168 | } |
1153 | |
1169 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1154 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1170 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1155 | AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1171 | AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1156 | AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1172 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1157 | AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1173 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1158 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1174 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1159 | AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); |
1175 | AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1160 | AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); |
1176 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1161 | AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); |
1177 | flags = 0; |
1162 | flags = 0; |
|
|
1163 | |
1178 | if (pl->fire_on) |
1164 | if (pl->fire_on) |
1179 | flags |= SF_FIREON; |
1165 | flags |= SF_FIREON; |
|
|
1166 | |
1180 | if (pl->run_on) |
1167 | if (pl->run_on) |
1181 | flags |= SF_RUNON; |
1168 | flags |= SF_RUNON; |
1182 | |
1169 | |
1183 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1170 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
|
|
1171 | |
1184 | if (pl->socket.sc_version < 1025) |
1172 | if (pl->socket.sc_version < 1025) |
1185 | { |
|
|
1186 | AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1173 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1187 | } |
|
|
1188 | else |
1174 | else |
1189 | { |
1175 | { |
1190 | int i; |
1176 | int i; |
1191 | |
1177 | |
1192 | for (i = 0; i < NROFATTACKS; i++) |
1178 | for (i = 0; i < NROFATTACKS; i++) |
1193 | { |
1179 | { |
1194 | /* Skip ones we won't send */ |
1180 | /* Skip ones we won't send */ |
1195 | if (atnr_cs_stat[i] == -1) |
1181 | if (atnr_cs_stat[i] == -1) |
1196 | continue; |
1182 | continue; |
|
|
1183 | |
1197 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1184 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1198 | } |
1185 | } |
1199 | } |
1186 | } |
|
|
1187 | |
1200 | if (pl->socket.monitor_spells) |
1188 | if (pl->socket.monitor_spells) |
1201 | { |
1189 | { |
1202 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1190 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1203 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1191 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1204 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1192 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1205 | } |
1193 | } |
|
|
1194 | |
1206 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1195 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1207 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1196 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1208 | set_title (pl->ob, buf); |
1197 | set_title (pl->ob, buf); |
1209 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1198 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1210 | |
1199 | |
… | |
… | |
1214 | #ifdef ESRV_DEBUG |
1203 | #ifdef ESRV_DEBUG |
1215 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1204 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1216 | #endif |
1205 | #endif |
1217 | Send_With_Handling (&pl->socket, &sl); |
1206 | Send_With_Handling (&pl->socket, &sl); |
1218 | } |
1207 | } |
|
|
1208 | |
1219 | free (sl.buf); |
1209 | free (sl.buf); |
1220 | } |
1210 | } |
1221 | |
|
|
1222 | |
1211 | |
1223 | /** |
1212 | /** |
1224 | * Tells the client that here is a player it should start using. |
1213 | * Tells the client that here is a player it should start using. |
1225 | */ |
1214 | */ |
1226 | void |
1215 | void |
… | |
… | |
1244 | |
1233 | |
1245 | Send_With_Handling (&pl->socket, &sl); |
1234 | Send_With_Handling (&pl->socket, &sl); |
1246 | free (sl.buf); |
1235 | free (sl.buf); |
1247 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1236 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1248 | } |
1237 | } |
1249 | |
|
|
1250 | |
1238 | |
1251 | /** |
1239 | /** |
1252 | * Need to send an animation sequence to the client. |
1240 | * Need to send an animation sequence to the client. |
1253 | * We will send appropriate face commands to the client if we haven't |
1241 | * We will send appropriate face commands to the client if we haven't |
1254 | * sent them the face yet (this can become quite costly in terms of |
1242 | * sent them the face yet (this can become quite costly in terms of |
… | |
… | |
1464 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1452 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1465 | { |
1453 | { |
1466 | cell->faces[0] = face0; |
1454 | cell->faces[0] = face0; |
1467 | cell->faces[1] = face1; |
1455 | cell->faces[1] = face1; |
1468 | cell->faces[2] = face2; |
1456 | cell->faces[2] = face2; |
1469 | cell->count = count; |
1457 | cell->count = count; |
1470 | cell->stat_hp = 0; |
1458 | cell->stat_hp = 0; |
|
|
1459 | cell->flags = 0; |
1471 | cell->player = 0; |
1460 | cell->player = 0; |
1472 | } |
1461 | } |
1473 | |
1462 | |
1474 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1463 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1475 | #define MAX_LAYERS 3 |
1464 | #define MAX_LAYERS 3 |
1476 | |
1465 | |
… | |
… | |
1547 | * the case, it seems to make more sense to have these layer values |
1536 | * the case, it seems to make more sense to have these layer values |
1548 | * actually match. |
1537 | * actually match. |
1549 | */ |
1538 | */ |
1550 | |
1539 | |
1551 | static int |
1540 | static int |
1552 | update_space (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1541 | update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1553 | { |
1542 | { |
1554 | object *ob, *head; |
1543 | object *ob, *head; |
1555 | uint16 face_num; |
1544 | uint16 face_num; |
1556 | int bx, by, i; |
1545 | int bx, by, i; |
1557 | |
1546 | |
… | |
… | |
1771 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1760 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1772 | * take. |
1761 | * take. |
1773 | */ |
1762 | */ |
1774 | |
1763 | |
1775 | static inline int |
1764 | static inline int |
1776 | update_smooth (SockList * sl, NewSocket * ns, mapstruct *mp, int mx, int my, int sx, int sy, int layer) |
1765 | update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1777 | { |
1766 | { |
1778 | object *ob; |
1767 | object *ob; |
1779 | int smoothlevel; /* old face_num; */ |
1768 | int smoothlevel; /* old face_num; */ |
1780 | |
1769 | |
1781 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1770 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1859 | SockList esl; /*For extended Map info */ |
1848 | SockList esl; /*For extended Map info */ |
1860 | uint16 mask, emask; |
1849 | uint16 mask, emask; |
1861 | uint8 eentrysize; |
1850 | uint8 eentrysize; |
1862 | uint16 ewhatstart, ewhatflag; |
1851 | uint16 ewhatstart, ewhatflag; |
1863 | uint8 extendedinfos; |
1852 | uint8 extendedinfos; |
1864 | mapstruct *m; |
1853 | maptile *m; |
1865 | |
1854 | |
1866 | NewSocket & socket = pl->contr->socket; |
1855 | NewSocket & socket = pl->contr->socket; |
1867 | |
1856 | |
1868 | check_map_change (pl->contr); |
1857 | check_map_change (pl->contr); |
1869 | |
1858 | |
… | |
… | |
1872 | strcpy ((char *) sl.buf, "map1 "); |
1861 | strcpy ((char *) sl.buf, "map1 "); |
1873 | else |
1862 | else |
1874 | strcpy ((char *) sl.buf, "map1a "); |
1863 | strcpy ((char *) sl.buf, "map1a "); |
1875 | sl.len = strlen ((char *) sl.buf); |
1864 | sl.len = strlen ((char *) sl.buf); |
1876 | startlen = sl.len; |
1865 | startlen = sl.len; |
|
|
1866 | |
1877 | /*Extendedmapinfo structure initialisation */ |
1867 | /*Extendedmapinfo structure initialisation */ |
1878 | if (socket.ext_mapinfos) |
1868 | if (socket.ext_mapinfos) |
1879 | { |
1869 | { |
1880 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1870 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1881 | strcpy ((char *) esl.buf, "mapextended "); |
1871 | strcpy ((char *) esl.buf, "mapextended "); |
1882 | esl.len = strlen ((char *) esl.buf); |
1872 | esl.len = strlen ((char *) esl.buf); |
1883 | extendedinfos = EMI_NOREDRAW; |
1873 | extendedinfos = EMI_NOREDRAW; |
|
|
1874 | |
1884 | if (socket.EMI_smooth) |
1875 | if (socket.EMI_smooth) |
1885 | extendedinfos |= EMI_SMOOTH; |
1876 | extendedinfos |= EMI_SMOOTH; |
|
|
1877 | |
1886 | ewhatstart = esl.len; |
1878 | ewhatstart = esl.len; |
1887 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1879 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1888 | could need to be taken away */ |
1880 | could need to be taken away */ |
1889 | SockList_AddChar (&esl, extendedinfos); |
1881 | SockList_AddChar (&esl, extendedinfos); |
1890 | eentrysize = getExtendedMapInfoSize (&socket); |
1882 | eentrysize = getExtendedMapInfoSize (&socket); |
… | |
… | |
1896 | /* suppress compiler warnings */ |
1888 | /* suppress compiler warnings */ |
1897 | ewhatstart = 0; |
1889 | ewhatstart = 0; |
1898 | ewhatflag = 0; |
1890 | ewhatflag = 0; |
1899 | estartlen = 0; |
1891 | estartlen = 0; |
1900 | } |
1892 | } |
|
|
1893 | |
1901 | /* Init data to zero */ |
1894 | /* Init data to zero */ |
1902 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1895 | memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); |
1903 | |
1896 | |
1904 | /* x,y are the real map locations. ax, ay are viewport relative |
1897 | /* x,y are the real map locations. ax, ay are viewport relative |
1905 | * locations. |
1898 | * locations. |
… | |
… | |
1909 | /* We could do this logic as conditionals in the if statement, |
1902 | /* We could do this logic as conditionals in the if statement, |
1910 | * but that started to get a bit messy to look at. |
1903 | * but that started to get a bit messy to look at. |
1911 | */ |
1904 | */ |
1912 | max_x = pl->x + (socket.mapx + 1) / 2; |
1905 | max_x = pl->x + (socket.mapx + 1) / 2; |
1913 | max_y = pl->y + (socket.mapy + 1) / 2; |
1906 | max_y = pl->y + (socket.mapy + 1) / 2; |
|
|
1907 | |
1914 | if (socket.mapmode == Map1aCmd) |
1908 | if (socket.mapmode == Map1aCmd) |
1915 | { |
1909 | { |
1916 | max_x += MAX_HEAD_OFFSET; |
1910 | max_x += MAX_HEAD_OFFSET; |
1917 | max_y += MAX_HEAD_OFFSET; |
1911 | max_y += MAX_HEAD_OFFSET; |
1918 | } |
1912 | } |
… | |
… | |
1951 | * with no faces tells the client to blank out the |
1945 | * with no faces tells the client to blank out the |
1952 | * space. |
1946 | * space. |
1953 | */ |
1947 | */ |
1954 | got_one = 0; |
1948 | got_one = 0; |
1955 | for (i = oldlen + 2; i < sl.len; i++) |
1949 | for (i = oldlen + 2; i < sl.len; i++) |
1956 | { |
|
|
1957 | if (sl.buf[i]) |
1950 | if (sl.buf[i]) |
1958 | got_one = 1; |
1951 | got_one = 1; |
1959 | } |
|
|
1960 | |
1952 | |
1961 | if (got_one && (mask & 0xf)) |
1953 | if (got_one && (mask & 0xf)) |
1962 | { |
|
|
1963 | sl.buf[oldlen + 1] = mask & 0xff; |
1954 | sl.buf[oldlen + 1] = mask & 0xff; |
1964 | } |
|
|
1965 | else |
1955 | else |
1966 | { /*either all faces blank, either no face at all */ |
1956 | { /*either all faces blank, either no face at all */ |
1967 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1957 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1968 | sl.len = oldlen + 2; |
1958 | sl.len = oldlen + 2; |
1969 | else |
1959 | else |
1970 | sl.len = oldlen; |
1960 | sl.len = oldlen; |
1971 | } |
1961 | } |
|
|
1962 | |
1972 | /*What concerns extendinfos, nothing to be done for now |
1963 | /*What concerns extendinfos, nothing to be done for now |
1973 | * (perhaps effects layer later) |
1964 | * (perhaps effects layer later) |
1974 | */ |
1965 | */ |
1975 | continue; /* don't do processing below */ |
1966 | continue; /* don't do processing below */ |
1976 | } |
1967 | } |
1977 | |
1968 | |
1978 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1969 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1979 | |
1970 | |
1980 | d = pl->contr->blocked_los[ax][ay]; |
1971 | d = pl->contr->blocked_los[ax][ay]; |
1981 | |
1972 | |
1982 | /* If the coordinates are not valid, or it is too dark to see, |
1973 | /* If the coordinates are not valid, or it is too dark to see, |
1983 | * we tell the client as such |
1974 | * we tell the client as such |
1984 | */ |
1975 | */ |
1985 | nx = x; |
1976 | nx = x; |
1986 | ny = y; |
1977 | ny = y; |
1987 | m = get_map_from_coord (pl->map, &nx, &ny); |
1978 | m = get_map_from_coord (pl->map, &nx, &ny); |
|
|
1979 | |
1988 | if (!m) |
1980 | if (!m) |
1989 | { |
1981 | { |
1990 | /* space is out of map. Update space and clear values |
1982 | /* space is out of map. Update space and clear values |
1991 | * if this hasn't already been done. If the space is out |
1983 | * if this hasn't already been done. If the space is out |
1992 | * of the map, it shouldn't have a head |
1984 | * of the map, it shouldn't have a head |
… | |
… | |
2006 | */ |
1998 | */ |
2007 | |
1999 | |
2008 | oldlen = sl.len; |
2000 | oldlen = sl.len; |
2009 | |
2001 | |
2010 | SockList_AddShort (&sl, mask); |
2002 | SockList_AddShort (&sl, mask); |
|
|
2003 | |
2011 | if (lastcell.count != -1) |
2004 | if (lastcell.count != -1) |
2012 | need_send = 1; |
2005 | need_send = 1; |
|
|
2006 | |
2013 | count = -1; |
2007 | count = -1; |
2014 | |
2008 | |
2015 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2009 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2016 | { |
2010 | { |
2017 | /* Now check to see if any heads need to be sent */ |
2011 | /* Now check to see if any heads need to be sent */ |
… | |
… | |
2022 | mask |= 0x2; |
2016 | mask |= 0x2; |
2023 | if (check_head (sl, socket, ax, ay, 0)) |
2017 | if (check_head (sl, socket, ax, ay, 0)) |
2024 | mask |= 0x1; |
2018 | mask |= 0x1; |
2025 | |
2019 | |
2026 | lastcell.count = count; |
2020 | lastcell.count = count; |
2027 | |
|
|
2028 | } |
2021 | } |
2029 | else |
2022 | else |
2030 | { |
2023 | { |
2031 | struct MapCell *cell = &lastcell; |
|
|
2032 | |
|
|
2033 | /* properly clear a previously sent big face */ |
2024 | /* properly clear a previously sent big face */ |
2034 | if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) |
2025 | if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0 |
|
|
2026 | || lastcell.stat_hp || lastcell.flags || lastcell.player) |
2035 | need_send = 1; |
2027 | need_send = 1; |
|
|
2028 | |
2036 | map_clearcell (&lastcell, 0, 0, 0, count); |
2029 | map_clearcell (&lastcell, 0, 0, 0, count); |
2037 | } |
2030 | } |
2038 | |
2031 | |
2039 | if ((mask & 0xf) || need_send) |
2032 | if ((mask & 0xf) || need_send) |
2040 | { |
|
|
2041 | sl.buf[oldlen + 1] = mask & 0xff; |
2033 | sl.buf[oldlen + 1] = mask & 0xff; |
2042 | } |
|
|
2043 | else |
2034 | else |
2044 | { |
|
|
2045 | sl.len = oldlen; |
2035 | sl.len = oldlen; |
2046 | } |
|
|
2047 | } |
2036 | } |
2048 | else |
2037 | else |
2049 | { |
2038 | { |
2050 | /* In this block, the space is visible or there are head objects |
2039 | /* In this block, the space is visible or there are head objects |
2051 | * we need to send. |
2040 | * we need to send. |
… | |
… | |
2092 | |
2081 | |
2093 | if (socket.extmap) |
2082 | if (socket.extmap) |
2094 | { |
2083 | { |
2095 | uint8 stat_hp = 0; |
2084 | uint8 stat_hp = 0; |
2096 | uint8 stat_width = 0; |
2085 | uint8 stat_width = 0; |
|
|
2086 | uint8 flags = 0; |
2097 | tag_t player = 0; |
2087 | tag_t player = 0; |
2098 | |
2088 | |
2099 | // send hp information, if applicable |
2089 | // send hp information, if applicable |
2100 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2090 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2101 | { |
2091 | { |
… | |
… | |
2109 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2099 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2110 | stat_width = op->arch->tail_x; |
2100 | stat_width = op->arch->tail_x; |
2111 | } |
2101 | } |
2112 | } |
2102 | } |
2113 | |
2103 | |
|
|
2104 | if (op->msg && op->msg[0] == '@') |
|
|
2105 | flags |= 1; |
|
|
2106 | |
2114 | if (op->type == PLAYER && op != pl) |
2107 | if (op->type == PLAYER && op != pl) |
2115 | player = op->count; |
2108 | player = op->count; |
2116 | } |
2109 | } |
2117 | |
2110 | |
2118 | if (lastcell.stat_hp != stat_hp) |
2111 | if (lastcell.stat_hp != stat_hp) |
… | |
… | |
2132 | SockList_AddChar (&sl, 6); |
2125 | SockList_AddChar (&sl, 6); |
2133 | SockList_AddChar (&sl, stat_width); |
2126 | SockList_AddChar (&sl, stat_width); |
2134 | } |
2127 | } |
2135 | } |
2128 | } |
2136 | |
2129 | |
2137 | if (lastcell.player !=player) |
2130 | if (lastcell.player != player) |
2138 | { |
2131 | { |
2139 | lastcell.player = player; |
2132 | lastcell.player = player; |
2140 | |
2133 | |
2141 | mask |= 0x8; |
2134 | mask |= 0x8; |
2142 | *last_ext |= 0x80; |
2135 | *last_ext |= 0x80; |
2143 | last_ext = sl.buf + sl.len; |
2136 | last_ext = sl.buf + sl.len; |
2144 | SockList_AddChar (&sl, 0x47); |
2137 | SockList_AddChar (&sl, 0x47); |
2145 | SockList_AddChar (&sl, 4); |
2138 | SockList_AddChar (&sl, 4); |
2146 | SockList_AddInt (&sl, player); |
2139 | SockList_AddInt (&sl, player); |
2147 | } |
2140 | } |
|
|
2141 | |
|
|
2142 | if (lastcell.flags != flags) |
|
|
2143 | { |
|
|
2144 | lastcell.flags = flags; |
|
|
2145 | |
|
|
2146 | mask |= 0x8; |
|
|
2147 | *last_ext |= 0x80; |
|
|
2148 | last_ext = sl.buf + sl.len; |
|
|
2149 | SockList_AddChar (&sl, 8); |
|
|
2150 | SockList_AddChar (&sl, flags); |
|
|
2151 | } |
2148 | } |
2152 | } |
2149 | |
2153 | |
2150 | /* Floor face */ |
2154 | /* Floor face */ |
2151 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2155 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2152 | mask |= 0x4; |
2156 | mask |= 0x4; |
… | |
… | |
2167 | { |
2171 | { |
2168 | if (lastcell.faces[0] != pl->face->number) |
2172 | if (lastcell.faces[0] != pl->face->number) |
2169 | { |
2173 | { |
2170 | lastcell.faces[0] = pl->face->number; |
2174 | lastcell.faces[0] = pl->face->number; |
2171 | mask |= 0x1; |
2175 | mask |= 0x1; |
|
|
2176 | |
2172 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2177 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2173 | esrv_send_face (&socket, pl->face->number, 0); |
2178 | esrv_send_face (&socket, pl->face->number, 0); |
|
|
2179 | |
2174 | SockList_AddShort (&sl, pl->face->number); |
2180 | SockList_AddShort (&sl, pl->face->number); |
2175 | } |
2181 | } |
2176 | } |
2182 | } |
2177 | /* Top face */ |
|
|
2178 | else |
2183 | else |
2179 | { |
2184 | { |
|
|
2185 | /* Top face */ |
2180 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2186 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2181 | mask |= 0x1; |
2187 | mask |= 0x1; |
|
|
2188 | |
2182 | if (socket.EMI_smooth) |
2189 | if (socket.EMI_smooth) |
2183 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2190 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2184 | { |
|
|
2185 | emask |= 0x1; |
2191 | emask |= 0x1; |
2186 | } |
|
|
2187 | } |
2192 | } |
|
|
2193 | |
2188 | /* Check to see if we are in fact sending anything for this |
2194 | /* Check to see if we are in fact sending anything for this |
2189 | * space by checking the mask. If so, update the mask. |
2195 | * space by checking the mask. If so, update the mask. |
2190 | * if not, reset the len to that from before adding the mask |
2196 | * if not, reset the len to that from before adding the mask |
2191 | * value, so we don't send those bits. |
2197 | * value, so we don't send those bits. |
2192 | */ |
2198 | */ |
2193 | if (mask & 0xf) |
2199 | if (mask & 0xf) |
2194 | { |
|
|
2195 | sl.buf[oldlen + 1] = mask & 0xff; |
2200 | sl.buf[oldlen + 1] = mask & 0xff; |
2196 | } |
|
|
2197 | else |
2201 | else |
2198 | { |
|
|
2199 | sl.len = oldlen; |
2202 | sl.len = oldlen; |
2200 | } |
2203 | |
2201 | if (emask & 0xf) |
2204 | if (emask & 0xf) |
2202 | { |
|
|
2203 | esl.buf[eoldlen + 1] = emask & 0xff; |
2205 | esl.buf[eoldlen + 1] = emask & 0xff; |
2204 | } |
|
|
2205 | else |
2206 | else |
2206 | { |
|
|
2207 | esl.len = eoldlen; |
2207 | esl.len = eoldlen; |
2208 | } |
|
|
2209 | } /* else this is a viewable space */ |
2208 | } /* else this is a viewable space */ |
2210 | } /* for x loop */ |
2209 | } /* for x loop */ |
2211 | } /* for y loop */ |
2210 | } /* for y loop */ |
2212 | |
2211 | |
2213 | /* Verify that we in fact do need to send this */ |
2212 | /* Verify that we in fact do need to send this */ |
… | |
… | |
2247 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2246 | sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ |
2248 | New_Face *face, *floor; |
2247 | New_Face *face, *floor; |
2249 | New_Face *floor2; |
2248 | New_Face *floor2; |
2250 | int d, mflags; |
2249 | int d, mflags; |
2251 | struct Map newmap; |
2250 | struct Map newmap; |
2252 | mapstruct *m, *pm; |
2251 | maptile *m, *pm; |
2253 | |
2252 | |
2254 | if (pl->type != PLAYER) |
2253 | if (pl->type != PLAYER) |
2255 | { |
2254 | { |
2256 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2255 | LOG (llevError, "draw_client_map called with non player/non eric-server\n"); |
2257 | return; |
2256 | return; |