… | |
… | |
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. */ |
… | |
… | |
1460 | 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) |
1461 | { |
1456 | { |
1462 | cell->faces[0] = face0; |
1457 | cell->faces[0] = face0; |
1463 | cell->faces[1] = face1; |
1458 | cell->faces[1] = face1; |
1464 | cell->faces[2] = face2; |
1459 | cell->faces[2] = face2; |
1465 | cell->count = count; |
1460 | cell->count = count; |
1466 | cell->stat_hp = 0; |
1461 | cell->stat_hp = 0; |
|
|
1462 | cell->flags = 0; |
1467 | cell->player = 0; |
1463 | cell->player = 0; |
1468 | } |
1464 | } |
1469 | |
1465 | |
1470 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1466 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1471 | #define MAX_LAYERS 3 |
1467 | #define MAX_LAYERS 3 |
1472 | |
1468 | |
… | |
… | |
1868 | strcpy ((char *) sl.buf, "map1 "); |
1864 | strcpy ((char *) sl.buf, "map1 "); |
1869 | else |
1865 | else |
1870 | strcpy ((char *) sl.buf, "map1a "); |
1866 | strcpy ((char *) sl.buf, "map1a "); |
1871 | sl.len = strlen ((char *) sl.buf); |
1867 | sl.len = strlen ((char *) sl.buf); |
1872 | startlen = sl.len; |
1868 | startlen = sl.len; |
|
|
1869 | |
1873 | /*Extendedmapinfo structure initialisation */ |
1870 | /*Extendedmapinfo structure initialisation */ |
1874 | if (socket.ext_mapinfos) |
1871 | if (socket.ext_mapinfos) |
1875 | { |
1872 | { |
1876 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1873 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1877 | strcpy ((char *) esl.buf, "mapextended "); |
1874 | strcpy ((char *) esl.buf, "mapextended "); |
1878 | esl.len = strlen ((char *) esl.buf); |
1875 | esl.len = strlen ((char *) esl.buf); |
1879 | extendedinfos = EMI_NOREDRAW; |
1876 | extendedinfos = EMI_NOREDRAW; |
|
|
1877 | |
1880 | if (socket.EMI_smooth) |
1878 | if (socket.EMI_smooth) |
1881 | extendedinfos |= EMI_SMOOTH; |
1879 | extendedinfos |= EMI_SMOOTH; |
|
|
1880 | |
1882 | ewhatstart = esl.len; |
1881 | ewhatstart = esl.len; |
1883 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1882 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1884 | could need to be taken away */ |
1883 | could need to be taken away */ |
1885 | SockList_AddChar (&esl, extendedinfos); |
1884 | SockList_AddChar (&esl, extendedinfos); |
1886 | eentrysize = getExtendedMapInfoSize (&socket); |
1885 | eentrysize = getExtendedMapInfoSize (&socket); |
… | |
… | |
1892 | /* suppress compiler warnings */ |
1891 | /* suppress compiler warnings */ |
1893 | ewhatstart = 0; |
1892 | ewhatstart = 0; |
1894 | ewhatflag = 0; |
1893 | ewhatflag = 0; |
1895 | estartlen = 0; |
1894 | estartlen = 0; |
1896 | } |
1895 | } |
|
|
1896 | |
1897 | /* Init data to zero */ |
1897 | /* Init data to zero */ |
1898 | 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); |
1899 | |
1899 | |
1900 | /* 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 |
1901 | * locations. |
1901 | * locations. |
… | |
… | |
1905 | /* We could do this logic as conditionals in the if statement, |
1905 | /* We could do this logic as conditionals in the if statement, |
1906 | * but that started to get a bit messy to look at. |
1906 | * but that started to get a bit messy to look at. |
1907 | */ |
1907 | */ |
1908 | max_x = pl->x + (socket.mapx + 1) / 2; |
1908 | max_x = pl->x + (socket.mapx + 1) / 2; |
1909 | max_y = pl->y + (socket.mapy + 1) / 2; |
1909 | max_y = pl->y + (socket.mapy + 1) / 2; |
|
|
1910 | |
1910 | if (socket.mapmode == Map1aCmd) |
1911 | if (socket.mapmode == Map1aCmd) |
1911 | { |
1912 | { |
1912 | max_x += MAX_HEAD_OFFSET; |
1913 | max_x += MAX_HEAD_OFFSET; |
1913 | max_y += MAX_HEAD_OFFSET; |
1914 | max_y += MAX_HEAD_OFFSET; |
1914 | } |
1915 | } |
… | |
… | |
1947 | * with no faces tells the client to blank out the |
1948 | * with no faces tells the client to blank out the |
1948 | * space. |
1949 | * space. |
1949 | */ |
1950 | */ |
1950 | got_one = 0; |
1951 | got_one = 0; |
1951 | for (i = oldlen + 2; i < sl.len; i++) |
1952 | for (i = oldlen + 2; i < sl.len; i++) |
1952 | { |
|
|
1953 | if (sl.buf[i]) |
1953 | if (sl.buf[i]) |
1954 | got_one = 1; |
1954 | got_one = 1; |
1955 | } |
|
|
1956 | |
1955 | |
1957 | if (got_one && (mask & 0xf)) |
1956 | if (got_one && (mask & 0xf)) |
1958 | { |
|
|
1959 | sl.buf[oldlen + 1] = mask & 0xff; |
1957 | sl.buf[oldlen + 1] = mask & 0xff; |
1960 | } |
|
|
1961 | else |
1958 | else |
1962 | { /*either all faces blank, either no face at all */ |
1959 | { /*either all faces blank, either no face at all */ |
1963 | 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 */ |
1964 | sl.len = oldlen + 2; |
1961 | sl.len = oldlen + 2; |
1965 | else |
1962 | else |
1966 | sl.len = oldlen; |
1963 | sl.len = oldlen; |
1967 | } |
1964 | } |
|
|
1965 | |
1968 | /*What concerns extendinfos, nothing to be done for now |
1966 | /*What concerns extendinfos, nothing to be done for now |
1969 | * (perhaps effects layer later) |
1967 | * (perhaps effects layer later) |
1970 | */ |
1968 | */ |
1971 | continue; /* don't do processing below */ |
1969 | continue; /* don't do processing below */ |
1972 | } |
1970 | } |
1973 | |
1971 | |
1974 | MapCell & lastcell = socket.lastmap.cells[ax][ay]; |
1972 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1975 | |
1973 | |
1976 | d = pl->contr->blocked_los[ax][ay]; |
1974 | d = pl->contr->blocked_los[ax][ay]; |
1977 | |
1975 | |
1978 | /* 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, |
1979 | * we tell the client as such |
1977 | * we tell the client as such |
1980 | */ |
1978 | */ |
1981 | nx = x; |
1979 | nx = x; |
1982 | ny = y; |
1980 | ny = y; |
1983 | m = get_map_from_coord (pl->map, &nx, &ny); |
1981 | m = get_map_from_coord (pl->map, &nx, &ny); |
|
|
1982 | |
1984 | if (!m) |
1983 | if (!m) |
1985 | { |
1984 | { |
1986 | /* space is out of map. Update space and clear values |
1985 | /* space is out of map. Update space and clear values |
1987 | * 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 |
1988 | * of the map, it shouldn't have a head |
1987 | * of the map, it shouldn't have a head |
… | |
… | |
2002 | */ |
2001 | */ |
2003 | |
2002 | |
2004 | oldlen = sl.len; |
2003 | oldlen = sl.len; |
2005 | |
2004 | |
2006 | SockList_AddShort (&sl, mask); |
2005 | SockList_AddShort (&sl, mask); |
|
|
2006 | |
2007 | if (lastcell.count != -1) |
2007 | if (lastcell.count != -1) |
2008 | need_send = 1; |
2008 | need_send = 1; |
|
|
2009 | |
2009 | count = -1; |
2010 | count = -1; |
2010 | |
2011 | |
2011 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | { |
2013 | { |
2013 | /* Now check to see if any heads need to be sent */ |
2014 | /* Now check to see if any heads need to be sent */ |
… | |
… | |
2018 | mask |= 0x2; |
2019 | mask |= 0x2; |
2019 | if (check_head (sl, socket, ax, ay, 0)) |
2020 | if (check_head (sl, socket, ax, ay, 0)) |
2020 | mask |= 0x1; |
2021 | mask |= 0x1; |
2021 | |
2022 | |
2022 | lastcell.count = count; |
2023 | lastcell.count = count; |
2023 | |
|
|
2024 | } |
2024 | } |
2025 | else |
2025 | else |
2026 | { |
2026 | { |
2027 | struct MapCell *cell = &lastcell; |
|
|
2028 | |
|
|
2029 | /* properly clear a previously sent big face */ |
2027 | /* properly clear a previously sent big face */ |
2030 | 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) |
2031 | need_send = 1; |
2030 | need_send = 1; |
|
|
2031 | |
2032 | map_clearcell (&lastcell, 0, 0, 0, count); |
2032 | map_clearcell (&lastcell, 0, 0, 0, count); |
2033 | } |
2033 | } |
2034 | |
2034 | |
2035 | if ((mask & 0xf) || need_send) |
2035 | if ((mask & 0xf) || need_send) |
2036 | { |
|
|
2037 | sl.buf[oldlen + 1] = mask & 0xff; |
2036 | sl.buf[oldlen + 1] = mask & 0xff; |
2038 | } |
|
|
2039 | else |
2037 | else |
2040 | { |
|
|
2041 | sl.len = oldlen; |
2038 | sl.len = oldlen; |
2042 | } |
|
|
2043 | } |
2039 | } |
2044 | else |
2040 | else |
2045 | { |
2041 | { |
2046 | /* 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 |
2047 | * we need to send. |
2043 | * we need to send. |
… | |
… | |
2089 | if (socket.extmap) |
2085 | if (socket.extmap) |
2090 | { |
2086 | { |
2091 | uint8 stat_hp = 0; |
2087 | uint8 stat_hp = 0; |
2092 | uint8 stat_width = 0; |
2088 | uint8 stat_width = 0; |
2093 | uint8 flags = 0; |
2089 | uint8 flags = 0; |
2094 | tag_t player = 0; |
2090 | UUID player = 0; |
2095 | |
2091 | |
2096 | // send hp information, if applicable |
2092 | // send hp information, if applicable |
2097 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2093 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2098 | { |
2094 | { |
2099 | if (op->head || op->invisible) |
2095 | if (op->head || op->invisible) |
… | |
… | |
2120 | lastcell.stat_hp = stat_hp; |
2116 | lastcell.stat_hp = stat_hp; |
2121 | |
2117 | |
2122 | mask |= 0x8; |
2118 | mask |= 0x8; |
2123 | *last_ext |= 0x80; |
2119 | *last_ext |= 0x80; |
2124 | last_ext = sl.buf + sl.len; |
2120 | last_ext = sl.buf + sl.len; |
2125 | SockList_AddChar (&sl, 5); |
2121 | |
2126 | SockList_AddChar (&sl, stat_hp); |
2122 | sl << uint8 (5) << uint8 (stat_hp); |
2127 | |
2123 | |
2128 | if (stat_width > 1) |
2124 | if (stat_width > 1) |
2129 | { |
2125 | { |
2130 | *last_ext |= 0x80; |
2126 | *last_ext |= 0x80; |
2131 | last_ext = sl.buf + sl.len; |
2127 | last_ext = sl.buf + sl.len; |
2132 | SockList_AddChar (&sl, 6); |
2128 | |
2133 | SockList_AddChar (&sl, stat_width); |
2129 | sl << uint8 (6) << uint8 (stat_width); |
2134 | } |
2130 | } |
2135 | } |
2131 | } |
2136 | |
2132 | |
2137 | if (lastcell.player != player) |
2133 | if (lastcell.player != player) |
2138 | { |
2134 | { |
2139 | lastcell.player = player; |
2135 | lastcell.player = player; |
2140 | |
2136 | |
2141 | mask |= 0x8; |
2137 | mask |= 0x8; |
2142 | *last_ext |= 0x80; |
2138 | *last_ext |= 0x80; |
2143 | last_ext = sl.buf + sl.len; |
2139 | last_ext = sl.buf + sl.len; |
2144 | SockList_AddChar (&sl, 0x47); |
2140 | |
2145 | SockList_AddChar (&sl, 4); |
2141 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2146 | SockList_AddInt (&sl, player); |
|
|
2147 | } |
2142 | } |
2148 | |
2143 | |
2149 | if (lastcell.flags != flags) |
2144 | if (lastcell.flags != flags) |
2150 | { |
2145 | { |
2151 | lastcell.flags = flags; |
2146 | lastcell.flags = flags; |
2152 | |
2147 | |
2153 | mask |= 0x8; |
2148 | mask |= 0x8; |
2154 | *last_ext |= 0x80; |
2149 | *last_ext |= 0x80; |
2155 | last_ext = sl.buf + sl.len; |
2150 | last_ext = sl.buf + sl.len; |
2156 | SockList_AddChar (&sl, 8); |
2151 | |
2157 | SockList_AddChar (&sl, flags); |
2152 | sl << uint8 (8) << uint8 (flags); |
2158 | } |
2153 | } |
2159 | } |
2154 | } |
2160 | |
2155 | |
2161 | /* Floor face */ |
2156 | /* Floor face */ |
2162 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2157 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
… | |
… | |
2178 | { |
2173 | { |
2179 | if (lastcell.faces[0] != pl->face->number) |
2174 | if (lastcell.faces[0] != pl->face->number) |
2180 | { |
2175 | { |
2181 | lastcell.faces[0] = pl->face->number; |
2176 | lastcell.faces[0] = pl->face->number; |
2182 | mask |= 0x1; |
2177 | mask |= 0x1; |
|
|
2178 | |
2183 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2179 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2184 | esrv_send_face (&socket, pl->face->number, 0); |
2180 | esrv_send_face (&socket, pl->face->number, 0); |
2185 | SockList_AddShort (&sl, pl->face->number); |
2181 | |
|
|
2182 | sl << uint16 (pl->face->number); |
2186 | } |
2183 | } |
2187 | } |
2184 | } |
2188 | /* Top face */ |
|
|
2189 | else |
2185 | else |
2190 | { |
2186 | { |
|
|
2187 | /* Top face */ |
2191 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2188 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2192 | mask |= 0x1; |
2189 | mask |= 0x1; |
|
|
2190 | |
2193 | if (socket.EMI_smooth) |
2191 | if (socket.EMI_smooth) |
2194 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2192 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2195 | { |
|
|
2196 | emask |= 0x1; |
2193 | emask |= 0x1; |
2197 | } |
|
|
2198 | } |
2194 | } |
|
|
2195 | |
2199 | /* 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 |
2200 | * space by checking the mask. If so, update the mask. |
2197 | * space by checking the mask. If so, update the mask. |
2201 | * 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 |
2202 | * value, so we don't send those bits. |
2199 | * value, so we don't send those bits. |
2203 | */ |
2200 | */ |
2204 | if (mask & 0xf) |
2201 | if (mask & 0xf) |
2205 | { |
|
|
2206 | sl.buf[oldlen + 1] = mask & 0xff; |
2202 | sl.buf[oldlen + 1] = mask & 0xff; |
2207 | } |
|
|
2208 | else |
2203 | else |
2209 | { |
|
|
2210 | sl.len = oldlen; |
2204 | sl.len = oldlen; |
2211 | } |
2205 | |
2212 | if (emask & 0xf) |
2206 | if (emask & 0xf) |
2213 | { |
|
|
2214 | esl.buf[eoldlen + 1] = emask & 0xff; |
2207 | esl.buf[eoldlen + 1] = emask & 0xff; |
2215 | } |
|
|
2216 | else |
2208 | else |
2217 | { |
|
|
2218 | esl.len = eoldlen; |
2209 | esl.len = eoldlen; |
2219 | } |
|
|
2220 | } /* else this is a viewable space */ |
2210 | } /* else this is a viewable space */ |
2221 | } /* for x loop */ |
2211 | } /* for x loop */ |
2222 | } /* for y loop */ |
2212 | } /* for y loop */ |
2223 | |
2213 | |
2224 | /* Verify that we in fact do need to send this */ |
2214 | /* Verify that we in fact do need to send this */ |
… | |
… | |
2476 | if (flags != 0) |
2466 | if (flags != 0) |
2477 | { |
2467 | { |
2478 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2468 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2479 | strcpy ((char *) sl.buf, "updspell "); |
2469 | strcpy ((char *) sl.buf, "updspell "); |
2480 | sl.len = strlen ((char *) sl.buf); |
2470 | sl.len = strlen ((char *) sl.buf); |
2481 | SockList_AddChar (&sl, flags); |
2471 | |
2482 | SockList_AddInt (&sl, spell->count); |
2472 | sl << uint8 (flags) << uint32 (spell->count); |
2483 | if (flags & UPD_SP_MANA) |
2473 | |
2484 | SockList_AddShort (&sl, spell->last_sp); |
2474 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2485 | if (flags & UPD_SP_GRACE) |
2475 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2486 | SockList_AddShort (&sl, spell->last_grace); |
2476 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2487 | if (flags & UPD_SP_DAMAGE) |
2477 | |
2488 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2489 | flags = 0; |
2478 | flags = 0; |
2490 | Send_With_Handling (&pl->socket, &sl); |
2479 | Send_With_Handling (&pl->socket, &sl); |
2491 | free (sl.buf); |
2480 | free (sl.buf); |
2492 | } |
2481 | } |
2493 | } |
2482 | } |
… | |
… | |
2507 | return; |
2496 | return; |
2508 | } |
2497 | } |
2509 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2510 | strcpy ((char *) sl.buf, "delspell "); |
2499 | strcpy ((char *) sl.buf, "delspell "); |
2511 | sl.len = strlen ((char *) sl.buf); |
2500 | sl.len = strlen ((char *) sl.buf); |
2512 | SockList_AddInt (&sl, spell->count); |
2501 | |
|
|
2502 | sl << uint32 (spell->count); |
|
|
2503 | |
2513 | Send_With_Handling (&pl->socket, &sl); |
2504 | Send_With_Handling (&pl->socket, &sl); |
2514 | free (sl.buf); |
2505 | free (sl.buf); |
2515 | } |
2506 | } |
2516 | |
2507 | |
2517 | /* 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. */ |
2518 | static void |
2509 | static void |
2519 | append_spell (player *pl, SockList * sl, object *spell) |
2510 | append_spell (player *pl, SockList &sl, object *spell) |
2520 | { |
2511 | { |
2521 | int len, i, skill = 0; |
2512 | int len, i, skill = 0; |
2522 | |
2513 | |
2523 | if (!(spell->name)) |
2514 | if (!(spell->name)) |
2524 | { |
2515 | { |
2525 | 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); |
2526 | return; |
2517 | return; |
2527 | } |
2518 | } |
2528 | SockList_AddInt (sl, spell->count); |
2519 | |
2529 | SockList_AddShort (sl, spell->level); |
|
|
2530 | SockList_AddShort (sl, spell->casting_time); |
|
|
2531 | /* 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 */ |
2532 | 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); |
2533 | 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); |
2534 | 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); |
2535 | /* send the current values */ |
|
|
2536 | SockList_AddShort (sl, spell->last_sp); |
|
|
2537 | SockList_AddShort (sl, spell->last_grace); |
|
|
2538 | SockList_AddShort (sl, spell->last_eat); |
|
|
2539 | |
2524 | |
2540 | /* figure out which skill it uses, if it uses one */ |
2525 | /* figure out which skill it uses, if it uses one */ |
2541 | if (spell->skill) |
2526 | if (spell->skill) |
2542 | { |
2527 | { |
2543 | for (i = 1; i < NUM_SKILLS; i++) |
2528 | for (i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2545 | { |
2530 | { |
2546 | skill = i + CS_STAT_SKILLINFO; |
2531 | skill = i + CS_STAT_SKILLINFO; |
2547 | break; |
2532 | break; |
2548 | } |
2533 | } |
2549 | } |
2534 | } |
2550 | SockList_AddChar (sl, skill); |
|
|
2551 | |
2535 | |
2552 | 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) |
2553 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2545 | << uint32 (spell->face ? spell->face->number : 0) |
2554 | |
2546 | << data8 (spell->name) |
2555 | len = strlen (spell->name); |
2547 | << data16 (spell->msg); |
2556 | SockList_AddChar (sl, (char) len); |
|
|
2557 | memcpy (sl->buf + sl->len, spell->name, len); |
|
|
2558 | sl->len += len; |
|
|
2559 | |
|
|
2560 | if (!spell->msg) |
|
|
2561 | { |
|
|
2562 | SockList_AddShort (sl, 0); |
|
|
2563 | } |
|
|
2564 | else |
|
|
2565 | { |
|
|
2566 | len = strlen (spell->msg); |
|
|
2567 | SockList_AddShort (sl, len); |
|
|
2568 | memcpy (sl->buf + sl->len, spell->msg, len); |
|
|
2569 | sl->len += len; |
|
|
2570 | } |
|
|
2571 | } |
2548 | } |
2572 | |
2549 | |
2573 | /** |
2550 | /** |
2574 | * 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 |
2575 | * all spells in the player's inventory. |
2552 | * all spells in the player's inventory. |
… | |
… | |
2606 | * 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 |
2607 | * like it will fix this |
2584 | * like it will fix this |
2608 | */ |
2585 | */ |
2609 | if (spell->type != SPELL) |
2586 | if (spell->type != SPELL) |
2610 | continue; |
2587 | continue; |
|
|
2588 | |
2611 | 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)))) |
2612 | { |
2590 | { |
2613 | Send_With_Handling (&pl->socket, &sl); |
2591 | Send_With_Handling (&pl->socket, &sl); |
2614 | strcpy ((char *) sl.buf, "addspell "); |
2592 | strcpy ((char *) sl.buf, "addspell "); |
2615 | sl.len = strlen ((char *) sl.buf); |
2593 | sl.len = strlen ((char *) sl.buf); |
2616 | } |
2594 | } |
|
|
2595 | |
2617 | append_spell (pl, &sl, spell); |
2596 | append_spell (pl, sl, spell); |
2618 | } |
2597 | } |
2619 | } |
2598 | } |
2620 | else if (spell->type != SPELL) |
2599 | else if (spell->type != SPELL) |
2621 | { |
2600 | { |
2622 | 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"); |
2623 | return; |
2602 | return; |
2624 | } |
2603 | } |
2625 | else |
2604 | else |
2626 | append_spell (pl, &sl, spell); |
2605 | append_spell (pl, sl, spell); |
|
|
2606 | |
2627 | if (sl.len >= MAXSOCKBUF) |
2607 | if (sl.len >= MAXSOCKBUF) |
2628 | { |
2608 | { |
2629 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2609 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2630 | fatal (0); |
2610 | fatal (0); |
2631 | } |
2611 | } |
|
|
2612 | |
2632 | /* finally, we can send the packet */ |
2613 | /* finally, we can send the packet */ |
2633 | Send_With_Handling (&pl->socket, &sl); |
2614 | Send_With_Handling (&pl->socket, &sl); |
2634 | free (sl.buf); |
2615 | free (sl.buf); |
2635 | } |
2616 | } |