… | |
… | |
57 | #include <commands.h> |
57 | #include <commands.h> |
58 | |
58 | |
59 | /* 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, |
60 | * it should work here. |
60 | * it should work here. |
61 | */ |
61 | */ |
62 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
|
|
63 | # include <sys/types.h> |
62 | #include <sys/types.h> |
64 | # include <sys/time.h> |
63 | #include <sys/time.h> |
65 | # include <sys/socket.h> |
64 | #include <sys/socket.h> |
66 | # include <netinet/in.h> |
65 | #include <netinet/in.h> |
67 | # include <netdb.h> |
66 | #include <netdb.h> |
68 | #endif /* win32 */ |
|
|
69 | |
67 | |
70 | #ifdef HAVE_UNISTD_H |
68 | #ifdef HAVE_UNISTD_H |
71 | # include <unistd.h> |
69 | # include <unistd.h> |
72 | #endif |
70 | #endif |
73 | |
71 | |
… | |
… | |
137 | for (x = 0; x < mx; x++) |
135 | for (x = 0; x < mx; x++) |
138 | { |
136 | { |
139 | for (y = 0; y < my; y++) |
137 | for (y = 0; y < my; y++) |
140 | { |
138 | { |
141 | if (x >= ns->mapx || y >= ns->mapy) |
139 | if (x >= ns->mapx || y >= ns->mapy) |
142 | { |
|
|
143 | /* clear cells outside the viewable area */ |
140 | /* clear cells outside the viewable area */ |
144 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
141 | memset (&newmap.cells[x][y], 0, sizeof (struct MapCell)); |
145 | } |
|
|
146 | 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) |
147 | { |
|
|
148 | /* clear newly visible tiles within the viewable area */ |
143 | /* clear newly visible tiles within the viewable area */ |
149 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
144 | memset (&(newmap.cells[x][y]), 0, sizeof (struct MapCell)); |
150 | } |
|
|
151 | else |
145 | else |
152 | { |
|
|
153 | 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)); |
154 | } |
|
|
155 | } |
147 | } |
156 | } |
148 | } |
157 | |
149 | |
158 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
150 | memcpy (&(ns->lastmap), &newmap, sizeof (struct Map)); |
159 | |
151 | |
… | |
… | |
712 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
704 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
713 | |
705 | |
714 | sl.buf = reply; |
706 | sl.buf = reply; |
715 | strcpy ((char *) sl.buf, "smooth "); |
707 | strcpy ((char *) sl.buf, "smooth "); |
716 | sl.len = strlen ((char *) sl.buf); |
708 | sl.len = strlen ((char *) sl.buf); |
717 | SockList_AddShort (&sl, face); |
709 | |
718 | SockList_AddShort (&sl, smoothface); |
710 | sl << uint16 (face) << uint16 (smoothface); |
|
|
711 | |
719 | Send_With_Handling (ns, &sl); |
712 | Send_With_Handling (ns, &sl); |
720 | } |
713 | } |
721 | |
714 | |
722 | /** |
715 | /** |
723 | * Tells client the picture it has to use |
716 | * Tells client the picture it has to use |
… | |
… | |
848 | |
841 | |
849 | /* Send confirmation of command execution now */ |
842 | /* Send confirmation of command execution now */ |
850 | sl.buf = command; |
843 | sl.buf = command; |
851 | strcpy ((char *) sl.buf, "comc "); |
844 | strcpy ((char *) sl.buf, "comc "); |
852 | sl.len = 5; |
845 | sl.len = 5; |
853 | SockList_AddShort (&sl, packet); |
846 | |
854 | if (FABS (pl->ob->speed) < 0.001) |
847 | if (FABS (pl->ob->speed) < 0.001) |
855 | time = MAX_TIME * 100; |
848 | time = MAX_TIME * 100; |
856 | else |
849 | else |
857 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
850 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
858 | SockList_AddInt (&sl, time); |
851 | |
|
|
852 | sl << uint16 (packet) << uint32 (time); |
|
|
853 | |
859 | Send_With_Handling (&pl->socket, &sl); |
854 | Send_With_Handling (&pl->socket, &sl); |
860 | } |
855 | } |
861 | |
856 | |
862 | |
857 | |
863 | /** This is a reply to a previous query. */ |
858 | /** This is a reply to a previous query. */ |
… | |
… | |
1131 | 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); |
1132 | 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); |
1133 | 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); |
1134 | 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); |
1135 | } |
1130 | } |
|
|
1131 | |
1136 | if (pl->socket.exp64) |
1132 | if (pl->socket.exp64) |
1137 | { |
1133 | { |
1138 | uint8 s; |
1134 | uint8 s; |
1139 | |
1135 | |
1140 | for (s = 0; s < NUM_SKILLS; s++) |
1136 | for (s = 0; s < NUM_SKILLS; s++) |
… | |
… | |
1150 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1146 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1151 | 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; |
1152 | } |
1148 | } |
1153 | } |
1149 | } |
1154 | } |
1150 | } |
|
|
1151 | |
1155 | if (pl->socket.exp64) |
1152 | if (pl->socket.exp64) |
1156 | { |
|
|
1157 | 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) } |
1158 | } |
|
|
1159 | else |
1154 | else |
1160 | { |
|
|
1161 | 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) } |
1162 | } |
1156 | |
1163 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1157 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1164 | 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); |
1165 | 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); |
1166 | 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); |
1167 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1161 | AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); |
1168 | 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); |
1169 | 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); |
1170 | 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); |
1171 | flags = 0; |
1165 | flags = 0; |
|
|
1166 | |
1172 | if (pl->fire_on) |
1167 | if (pl->fire_on) |
1173 | flags |= SF_FIREON; |
1168 | flags |= SF_FIREON; |
|
|
1169 | |
1174 | if (pl->run_on) |
1170 | if (pl->run_on) |
1175 | flags |= SF_RUNON; |
1171 | flags |= SF_RUNON; |
1176 | |
1172 | |
1177 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1173 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
|
|
1174 | |
1178 | if (pl->socket.sc_version < 1025) |
1175 | if (pl->socket.sc_version < 1025) |
1179 | { |
|
|
1180 | 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) } |
1181 | } |
|
|
1182 | else |
1177 | else |
1183 | { |
1178 | { |
1184 | int i; |
1179 | int i; |
1185 | |
1180 | |
1186 | for (i = 0; i < NROFATTACKS; i++) |
1181 | for (i = 0; i < NROFATTACKS; i++) |
1187 | { |
1182 | { |
1188 | /* Skip ones we won't send */ |
1183 | /* Skip ones we won't send */ |
1189 | if (atnr_cs_stat[i] == -1) |
1184 | if (atnr_cs_stat[i] == -1) |
1190 | continue; |
1185 | continue; |
|
|
1186 | |
1191 | 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]); |
1192 | } |
1188 | } |
1193 | } |
1189 | } |
|
|
1190 | |
1194 | if (pl->socket.monitor_spells) |
1191 | if (pl->socket.monitor_spells) |
1195 | { |
1192 | { |
1196 | 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); |
1197 | 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); |
1198 | 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); |
1199 | } |
1196 | } |
|
|
1197 | |
1200 | 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 */ |
1201 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1199 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1202 | set_title (pl->ob, buf); |
1200 | set_title (pl->ob, buf); |
1203 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1201 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1204 | |
1202 | |
… | |
… | |
1208 | #ifdef ESRV_DEBUG |
1206 | #ifdef ESRV_DEBUG |
1209 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1207 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1210 | #endif |
1208 | #endif |
1211 | Send_With_Handling (&pl->socket, &sl); |
1209 | Send_With_Handling (&pl->socket, &sl); |
1212 | } |
1210 | } |
|
|
1211 | |
1213 | free (sl.buf); |
1212 | free (sl.buf); |
1214 | } |
1213 | } |
1215 | |
|
|
1216 | |
1214 | |
1217 | /** |
1215 | /** |
1218 | * 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. |
1219 | */ |
1217 | */ |
1220 | void |
1218 | void |
… | |
… | |
1238 | |
1236 | |
1239 | Send_With_Handling (&pl->socket, &sl); |
1237 | Send_With_Handling (&pl->socket, &sl); |
1240 | free (sl.buf); |
1238 | free (sl.buf); |
1241 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1239 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1242 | } |
1240 | } |
1243 | |
|
|
1244 | |
1241 | |
1245 | /** |
1242 | /** |
1246 | * Need to send an animation sequence to the client. |
1243 | * Need to send an animation sequence to the client. |
1247 | * 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 |
1248 | * 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 |
… | |
… | |
1458 | 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) |
1459 | { |
1456 | { |
1460 | cell->faces[0] = face0; |
1457 | cell->faces[0] = face0; |
1461 | cell->faces[1] = face1; |
1458 | cell->faces[1] = face1; |
1462 | cell->faces[2] = face2; |
1459 | cell->faces[2] = face2; |
1463 | cell->count = count; |
1460 | cell->count = count; |
1464 | cell->stat_hp = 0; |
1461 | cell->stat_hp = 0; |
|
|
1462 | cell->flags = 0; |
1465 | cell->player = 0; |
1463 | cell->player = 0; |
1466 | } |
1464 | } |
1467 | |
1465 | |
1468 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1466 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1469 | #define MAX_LAYERS 3 |
1467 | #define MAX_LAYERS 3 |
1470 | |
1468 | |
… | |
… | |
1866 | strcpy ((char *) sl.buf, "map1 "); |
1864 | strcpy ((char *) sl.buf, "map1 "); |
1867 | else |
1865 | else |
1868 | strcpy ((char *) sl.buf, "map1a "); |
1866 | strcpy ((char *) sl.buf, "map1a "); |
1869 | sl.len = strlen ((char *) sl.buf); |
1867 | sl.len = strlen ((char *) sl.buf); |
1870 | startlen = sl.len; |
1868 | startlen = sl.len; |
|
|
1869 | |
1871 | /*Extendedmapinfo structure initialisation */ |
1870 | /*Extendedmapinfo structure initialisation */ |
1872 | if (socket.ext_mapinfos) |
1871 | if (socket.ext_mapinfos) |
1873 | { |
1872 | { |
1874 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1873 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1875 | strcpy ((char *) esl.buf, "mapextended "); |
1874 | strcpy ((char *) esl.buf, "mapextended "); |
1876 | esl.len = strlen ((char *) esl.buf); |
1875 | esl.len = strlen ((char *) esl.buf); |
1877 | extendedinfos = EMI_NOREDRAW; |
1876 | extendedinfos = EMI_NOREDRAW; |
|
|
1877 | |
1878 | if (socket.EMI_smooth) |
1878 | if (socket.EMI_smooth) |
1879 | extendedinfos |= EMI_SMOOTH; |
1879 | extendedinfos |= EMI_SMOOTH; |
|
|
1880 | |
1880 | ewhatstart = esl.len; |
1881 | ewhatstart = esl.len; |
1881 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1882 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1882 | could need to be taken away */ |
1883 | could need to be taken away */ |
1883 | SockList_AddChar (&esl, extendedinfos); |
1884 | SockList_AddChar (&esl, extendedinfos); |
1884 | eentrysize = getExtendedMapInfoSize (&socket); |
1885 | eentrysize = getExtendedMapInfoSize (&socket); |
… | |
… | |
1890 | /* suppress compiler warnings */ |
1891 | /* suppress compiler warnings */ |
1891 | ewhatstart = 0; |
1892 | ewhatstart = 0; |
1892 | ewhatflag = 0; |
1893 | ewhatflag = 0; |
1893 | estartlen = 0; |
1894 | estartlen = 0; |
1894 | } |
1895 | } |
|
|
1896 | |
1895 | /* Init data to zero */ |
1897 | /* Init data to zero */ |
1896 | 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); |
1897 | |
1899 | |
1898 | /* 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 |
1899 | * locations. |
1901 | * locations. |
… | |
… | |
1903 | /* We could do this logic as conditionals in the if statement, |
1905 | /* We could do this logic as conditionals in the if statement, |
1904 | * but that started to get a bit messy to look at. |
1906 | * but that started to get a bit messy to look at. |
1905 | */ |
1907 | */ |
1906 | max_x = pl->x + (socket.mapx + 1) / 2; |
1908 | max_x = pl->x + (socket.mapx + 1) / 2; |
1907 | max_y = pl->y + (socket.mapy + 1) / 2; |
1909 | max_y = pl->y + (socket.mapy + 1) / 2; |
|
|
1910 | |
1908 | if (socket.mapmode == Map1aCmd) |
1911 | if (socket.mapmode == Map1aCmd) |
1909 | { |
1912 | { |
1910 | max_x += MAX_HEAD_OFFSET; |
1913 | max_x += MAX_HEAD_OFFSET; |
1911 | max_y += MAX_HEAD_OFFSET; |
1914 | max_y += MAX_HEAD_OFFSET; |
1912 | } |
1915 | } |
… | |
… | |
1945 | * with no faces tells the client to blank out the |
1948 | * with no faces tells the client to blank out the |
1946 | * space. |
1949 | * space. |
1947 | */ |
1950 | */ |
1948 | got_one = 0; |
1951 | got_one = 0; |
1949 | for (i = oldlen + 2; i < sl.len; i++) |
1952 | for (i = oldlen + 2; i < sl.len; i++) |
1950 | { |
|
|
1951 | if (sl.buf[i]) |
1953 | if (sl.buf[i]) |
1952 | got_one = 1; |
1954 | got_one = 1; |
1953 | } |
|
|
1954 | |
1955 | |
1955 | if (got_one && (mask & 0xf)) |
1956 | if (got_one && (mask & 0xf)) |
1956 | { |
|
|
1957 | sl.buf[oldlen + 1] = mask & 0xff; |
1957 | sl.buf[oldlen + 1] = mask & 0xff; |
1958 | } |
|
|
1959 | else |
1958 | else |
1960 | { /*either all faces blank, either no face at all */ |
1959 | { /*either all faces blank, either no face at all */ |
1961 | 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 */ |
1962 | sl.len = oldlen + 2; |
1961 | sl.len = oldlen + 2; |
1963 | else |
1962 | else |
1964 | sl.len = oldlen; |
1963 | sl.len = oldlen; |
1965 | } |
1964 | } |
|
|
1965 | |
1966 | /*What concerns extendinfos, nothing to be done for now |
1966 | /*What concerns extendinfos, nothing to be done for now |
1967 | * (perhaps effects layer later) |
1967 | * (perhaps effects layer later) |
1968 | */ |
1968 | */ |
1969 | continue; /* don't do processing below */ |
1969 | continue; /* don't do processing below */ |
1970 | } |
1970 | } |
1971 | |
1971 | |
1972 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1972 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1973 | |
1973 | |
1974 | d = pl->contr->blocked_los[ax][ay]; |
1974 | d = pl->contr->blocked_los[ax][ay]; |
1975 | |
1975 | |
1976 | /* 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, |
1977 | * we tell the client as such |
1977 | * we tell the client as such |
1978 | */ |
1978 | */ |
1979 | nx = x; |
1979 | nx = x; |
1980 | ny = y; |
1980 | ny = y; |
1981 | m = get_map_from_coord (pl->map, &nx, &ny); |
1981 | m = get_map_from_coord (pl->map, &nx, &ny); |
|
|
1982 | |
1982 | if (!m) |
1983 | if (!m) |
1983 | { |
1984 | { |
1984 | /* space is out of map. Update space and clear values |
1985 | /* space is out of map. Update space and clear values |
1985 | * 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 |
1986 | * of the map, it shouldn't have a head |
1987 | * of the map, it shouldn't have a head |
… | |
… | |
2000 | */ |
2001 | */ |
2001 | |
2002 | |
2002 | oldlen = sl.len; |
2003 | oldlen = sl.len; |
2003 | |
2004 | |
2004 | SockList_AddShort (&sl, mask); |
2005 | SockList_AddShort (&sl, mask); |
|
|
2006 | |
2005 | if (lastcell.count != -1) |
2007 | if (lastcell.count != -1) |
2006 | need_send = 1; |
2008 | need_send = 1; |
|
|
2009 | |
2007 | count = -1; |
2010 | count = -1; |
2008 | |
2011 | |
2009 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2010 | { |
2013 | { |
2011 | /* Now check to see if any heads need to be sent */ |
2014 | /* Now check to see if any heads need to be sent */ |
… | |
… | |
2016 | mask |= 0x2; |
2019 | mask |= 0x2; |
2017 | if (check_head (sl, socket, ax, ay, 0)) |
2020 | if (check_head (sl, socket, ax, ay, 0)) |
2018 | mask |= 0x1; |
2021 | mask |= 0x1; |
2019 | |
2022 | |
2020 | lastcell.count = count; |
2023 | lastcell.count = count; |
2021 | |
|
|
2022 | } |
2024 | } |
2023 | else |
2025 | else |
2024 | { |
2026 | { |
2025 | struct MapCell *cell = &lastcell; |
|
|
2026 | |
|
|
2027 | /* properly clear a previously sent big face */ |
2027 | /* properly clear a previously sent big face */ |
2028 | 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) |
2029 | need_send = 1; |
2030 | need_send = 1; |
|
|
2031 | |
2030 | map_clearcell (&lastcell, 0, 0, 0, count); |
2032 | map_clearcell (&lastcell, 0, 0, 0, count); |
2031 | } |
2033 | } |
2032 | |
2034 | |
2033 | if ((mask & 0xf) || need_send) |
2035 | if ((mask & 0xf) || need_send) |
2034 | { |
|
|
2035 | sl.buf[oldlen + 1] = mask & 0xff; |
2036 | sl.buf[oldlen + 1] = mask & 0xff; |
2036 | } |
|
|
2037 | else |
2037 | else |
2038 | { |
|
|
2039 | sl.len = oldlen; |
2038 | sl.len = oldlen; |
2040 | } |
|
|
2041 | } |
2039 | } |
2042 | else |
2040 | else |
2043 | { |
2041 | { |
2044 | /* 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 |
2045 | * we need to send. |
2043 | * we need to send. |
… | |
… | |
2086 | |
2084 | |
2087 | if (socket.extmap) |
2085 | if (socket.extmap) |
2088 | { |
2086 | { |
2089 | uint8 stat_hp = 0; |
2087 | uint8 stat_hp = 0; |
2090 | uint8 stat_width = 0; |
2088 | uint8 stat_width = 0; |
|
|
2089 | uint8 flags = 0; |
2091 | tag_t player = 0; |
2090 | UUID player = 0; |
2092 | |
2091 | |
2093 | // send hp information, if applicable |
2092 | // send hp information, if applicable |
2094 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2093 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2095 | { |
2094 | { |
2096 | if (op->head || op->invisible) |
2095 | if (op->head || op->invisible) |
… | |
… | |
2103 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2102 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
2104 | stat_width = op->arch->tail_x; |
2103 | stat_width = op->arch->tail_x; |
2105 | } |
2104 | } |
2106 | } |
2105 | } |
2107 | |
2106 | |
|
|
2107 | if (op->msg && op->msg[0] == '@') |
|
|
2108 | flags |= 1; |
|
|
2109 | |
2108 | if (op->type == PLAYER && op != pl) |
2110 | if (op->type == PLAYER && op != pl) |
2109 | player = op->count; |
2111 | player = op->count; |
2110 | } |
2112 | } |
2111 | |
2113 | |
2112 | if (lastcell.stat_hp != stat_hp) |
2114 | if (lastcell.stat_hp != stat_hp) |
… | |
… | |
2114 | lastcell.stat_hp = stat_hp; |
2116 | lastcell.stat_hp = stat_hp; |
2115 | |
2117 | |
2116 | mask |= 0x8; |
2118 | mask |= 0x8; |
2117 | *last_ext |= 0x80; |
2119 | *last_ext |= 0x80; |
2118 | last_ext = sl.buf + sl.len; |
2120 | last_ext = sl.buf + sl.len; |
2119 | SockList_AddChar (&sl, 5); |
2121 | |
2120 | SockList_AddChar (&sl, stat_hp); |
2122 | sl << uint8 (5) << uint8 (stat_hp); |
2121 | |
2123 | |
2122 | if (stat_width > 1) |
2124 | if (stat_width > 1) |
2123 | { |
2125 | { |
2124 | *last_ext |= 0x80; |
2126 | *last_ext |= 0x80; |
2125 | last_ext = sl.buf + sl.len; |
2127 | last_ext = sl.buf + sl.len; |
2126 | SockList_AddChar (&sl, 6); |
2128 | |
2127 | SockList_AddChar (&sl, stat_width); |
2129 | sl << uint8 (6) << uint8 (stat_width); |
2128 | } |
2130 | } |
2129 | } |
2131 | } |
2130 | |
2132 | |
2131 | if (lastcell.player != player) |
2133 | if (lastcell.player != player) |
2132 | { |
2134 | { |
2133 | lastcell.player = player; |
2135 | lastcell.player = player; |
2134 | |
2136 | |
2135 | mask |= 0x8; |
2137 | mask |= 0x8; |
2136 | *last_ext |= 0x80; |
2138 | *last_ext |= 0x80; |
2137 | last_ext = sl.buf + sl.len; |
2139 | last_ext = sl.buf + sl.len; |
2138 | SockList_AddChar (&sl, 0x47); |
2140 | |
2139 | SockList_AddChar (&sl, 4); |
2141 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2140 | 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); |
2141 | } |
2153 | } |
2142 | } |
2154 | } |
2143 | |
2155 | |
2144 | /* Floor face */ |
2156 | /* Floor face */ |
2145 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2157 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
… | |
… | |
2161 | { |
2173 | { |
2162 | if (lastcell.faces[0] != pl->face->number) |
2174 | if (lastcell.faces[0] != pl->face->number) |
2163 | { |
2175 | { |
2164 | lastcell.faces[0] = pl->face->number; |
2176 | lastcell.faces[0] = pl->face->number; |
2165 | mask |= 0x1; |
2177 | mask |= 0x1; |
|
|
2178 | |
2166 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2179 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2167 | esrv_send_face (&socket, pl->face->number, 0); |
2180 | esrv_send_face (&socket, pl->face->number, 0); |
2168 | SockList_AddShort (&sl, pl->face->number); |
2181 | |
|
|
2182 | sl << uint16 (pl->face->number); |
2169 | } |
2183 | } |
2170 | } |
2184 | } |
2171 | /* Top face */ |
|
|
2172 | else |
2185 | else |
2173 | { |
2186 | { |
|
|
2187 | /* Top face */ |
2174 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2188 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2175 | mask |= 0x1; |
2189 | mask |= 0x1; |
|
|
2190 | |
2176 | if (socket.EMI_smooth) |
2191 | if (socket.EMI_smooth) |
2177 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2192 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2178 | { |
|
|
2179 | emask |= 0x1; |
2193 | emask |= 0x1; |
2180 | } |
|
|
2181 | } |
2194 | } |
|
|
2195 | |
2182 | /* 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 |
2183 | * space by checking the mask. If so, update the mask. |
2197 | * space by checking the mask. If so, update the mask. |
2184 | * 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 |
2185 | * value, so we don't send those bits. |
2199 | * value, so we don't send those bits. |
2186 | */ |
2200 | */ |
2187 | if (mask & 0xf) |
2201 | if (mask & 0xf) |
2188 | { |
|
|
2189 | sl.buf[oldlen + 1] = mask & 0xff; |
2202 | sl.buf[oldlen + 1] = mask & 0xff; |
2190 | } |
|
|
2191 | else |
2203 | else |
2192 | { |
|
|
2193 | sl.len = oldlen; |
2204 | sl.len = oldlen; |
2194 | } |
2205 | |
2195 | if (emask & 0xf) |
2206 | if (emask & 0xf) |
2196 | { |
|
|
2197 | esl.buf[eoldlen + 1] = emask & 0xff; |
2207 | esl.buf[eoldlen + 1] = emask & 0xff; |
2198 | } |
|
|
2199 | else |
2208 | else |
2200 | { |
|
|
2201 | esl.len = eoldlen; |
2209 | esl.len = eoldlen; |
2202 | } |
|
|
2203 | } /* else this is a viewable space */ |
2210 | } /* else this is a viewable space */ |
2204 | } /* for x loop */ |
2211 | } /* for x loop */ |
2205 | } /* for y loop */ |
2212 | } /* for y loop */ |
2206 | |
2213 | |
2207 | /* Verify that we in fact do need to send this */ |
2214 | /* Verify that we in fact do need to send this */ |
… | |
… | |
2459 | if (flags != 0) |
2466 | if (flags != 0) |
2460 | { |
2467 | { |
2461 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2468 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2462 | strcpy ((char *) sl.buf, "updspell "); |
2469 | strcpy ((char *) sl.buf, "updspell "); |
2463 | sl.len = strlen ((char *) sl.buf); |
2470 | sl.len = strlen ((char *) sl.buf); |
2464 | SockList_AddChar (&sl, flags); |
2471 | |
2465 | SockList_AddInt (&sl, spell->count); |
2472 | sl << uint8 (flags) << uint32 (spell->count); |
2466 | if (flags & UPD_SP_MANA) |
2473 | |
2467 | SockList_AddShort (&sl, spell->last_sp); |
2474 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2468 | if (flags & UPD_SP_GRACE) |
2475 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2469 | SockList_AddShort (&sl, spell->last_grace); |
2476 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2470 | if (flags & UPD_SP_DAMAGE) |
2477 | |
2471 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2472 | flags = 0; |
2478 | flags = 0; |
2473 | Send_With_Handling (&pl->socket, &sl); |
2479 | Send_With_Handling (&pl->socket, &sl); |
2474 | free (sl.buf); |
2480 | free (sl.buf); |
2475 | } |
2481 | } |
2476 | } |
2482 | } |
… | |
… | |
2490 | return; |
2496 | return; |
2491 | } |
2497 | } |
2492 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2493 | strcpy ((char *) sl.buf, "delspell "); |
2499 | strcpy ((char *) sl.buf, "delspell "); |
2494 | sl.len = strlen ((char *) sl.buf); |
2500 | sl.len = strlen ((char *) sl.buf); |
2495 | SockList_AddInt (&sl, spell->count); |
2501 | |
|
|
2502 | sl << uint32 (spell->count); |
|
|
2503 | |
2496 | Send_With_Handling (&pl->socket, &sl); |
2504 | Send_With_Handling (&pl->socket, &sl); |
2497 | free (sl.buf); |
2505 | free (sl.buf); |
2498 | } |
2506 | } |
2499 | |
2507 | |
2500 | /* 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. */ |
2501 | static void |
2509 | static void |
2502 | append_spell (player *pl, SockList * sl, object *spell) |
2510 | append_spell (player *pl, SockList &sl, object *spell) |
2503 | { |
2511 | { |
2504 | int len, i, skill = 0; |
2512 | int len, i, skill = 0; |
2505 | |
2513 | |
2506 | if (!(spell->name)) |
2514 | if (!(spell->name)) |
2507 | { |
2515 | { |
2508 | 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); |
2509 | return; |
2517 | return; |
2510 | } |
2518 | } |
2511 | SockList_AddInt (sl, spell->count); |
2519 | |
2512 | SockList_AddShort (sl, spell->level); |
|
|
2513 | SockList_AddShort (sl, spell->casting_time); |
|
|
2514 | /* 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 */ |
2515 | 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); |
2516 | 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); |
2517 | 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); |
2518 | /* send the current values */ |
|
|
2519 | SockList_AddShort (sl, spell->last_sp); |
|
|
2520 | SockList_AddShort (sl, spell->last_grace); |
|
|
2521 | SockList_AddShort (sl, spell->last_eat); |
|
|
2522 | |
2524 | |
2523 | /* figure out which skill it uses, if it uses one */ |
2525 | /* figure out which skill it uses, if it uses one */ |
2524 | if (spell->skill) |
2526 | if (spell->skill) |
2525 | { |
2527 | { |
2526 | for (i = 1; i < NUM_SKILLS; i++) |
2528 | for (i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2528 | { |
2530 | { |
2529 | skill = i + CS_STAT_SKILLINFO; |
2531 | skill = i + CS_STAT_SKILLINFO; |
2530 | break; |
2532 | break; |
2531 | } |
2533 | } |
2532 | } |
2534 | } |
2533 | SockList_AddChar (sl, skill); |
|
|
2534 | |
2535 | |
2535 | 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) |
2536 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2545 | << uint32 (spell->face ? spell->face->number : 0) |
2537 | |
2546 | << data8 (spell->name) |
2538 | len = strlen (spell->name); |
2547 | << data16 (spell->msg); |
2539 | SockList_AddChar (sl, (char) len); |
|
|
2540 | memcpy (sl->buf + sl->len, spell->name, len); |
|
|
2541 | sl->len += len; |
|
|
2542 | |
|
|
2543 | if (!spell->msg) |
|
|
2544 | { |
|
|
2545 | SockList_AddShort (sl, 0); |
|
|
2546 | } |
|
|
2547 | else |
|
|
2548 | { |
|
|
2549 | len = strlen (spell->msg); |
|
|
2550 | SockList_AddShort (sl, len); |
|
|
2551 | memcpy (sl->buf + sl->len, spell->msg, len); |
|
|
2552 | sl->len += len; |
|
|
2553 | } |
|
|
2554 | } |
2548 | } |
2555 | |
2549 | |
2556 | /** |
2550 | /** |
2557 | * 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 |
2558 | * all spells in the player's inventory. |
2552 | * all spells in the player's inventory. |
… | |
… | |
2589 | * 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 |
2590 | * like it will fix this |
2584 | * like it will fix this |
2591 | */ |
2585 | */ |
2592 | if (spell->type != SPELL) |
2586 | if (spell->type != SPELL) |
2593 | continue; |
2587 | continue; |
|
|
2588 | |
2594 | 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)))) |
2595 | { |
2590 | { |
2596 | Send_With_Handling (&pl->socket, &sl); |
2591 | Send_With_Handling (&pl->socket, &sl); |
2597 | strcpy ((char *) sl.buf, "addspell "); |
2592 | strcpy ((char *) sl.buf, "addspell "); |
2598 | sl.len = strlen ((char *) sl.buf); |
2593 | sl.len = strlen ((char *) sl.buf); |
2599 | } |
2594 | } |
|
|
2595 | |
2600 | append_spell (pl, &sl, spell); |
2596 | append_spell (pl, sl, spell); |
2601 | } |
2597 | } |
2602 | } |
2598 | } |
2603 | else if (spell->type != SPELL) |
2599 | else if (spell->type != SPELL) |
2604 | { |
2600 | { |
2605 | 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"); |
2606 | return; |
2602 | return; |
2607 | } |
2603 | } |
2608 | else |
2604 | else |
2609 | append_spell (pl, &sl, spell); |
2605 | append_spell (pl, sl, spell); |
|
|
2606 | |
2610 | if (sl.len >= MAXSOCKBUF) |
2607 | if (sl.len >= MAXSOCKBUF) |
2611 | { |
2608 | { |
2612 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2609 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2613 | fatal (0); |
2610 | fatal (0); |
2614 | } |
2611 | } |
|
|
2612 | |
2615 | /* finally, we can send the packet */ |
2613 | /* finally, we can send the packet */ |
2616 | Send_With_Handling (&pl->socket, &sl); |
2614 | Send_With_Handling (&pl->socket, &sl); |
2617 | free (sl.buf); |
2615 | free (sl.buf); |
2618 | } |
2616 | } |