… | |
… | |
60 | #include <sys/time.h> |
60 | #include <sys/time.h> |
61 | #include <sys/socket.h> |
61 | #include <sys/socket.h> |
62 | #include <netinet/in.h> |
62 | #include <netinet/in.h> |
63 | #include <netdb.h> |
63 | #include <netdb.h> |
64 | |
64 | |
65 | #ifdef HAVE_UNISTD_H |
|
|
66 | # include <unistd.h> |
65 | #include <unistd.h> |
67 | #endif |
|
|
68 | |
|
|
69 | #ifdef HAVE_SYS_TIME_H |
|
|
70 | # include <sys/time.h> |
66 | #include <sys/time.h> |
71 | #endif |
|
|
72 | |
67 | |
73 | #include "sounds.h" |
68 | #include "sounds.h" |
74 | |
69 | |
75 | /** |
70 | /** |
76 | * This table translates the attack numbers as used within the |
71 | * This table translates the attack numbers as used within the |
… | |
… | |
219 | } |
214 | } |
220 | } |
215 | } |
221 | |
216 | |
222 | socket.current_x = ob->x; |
217 | socket.current_x = ob->x; |
223 | socket.current_y = ob->y; |
218 | socket.current_y = ob->y; |
|
|
219 | } |
|
|
220 | |
|
|
221 | /** |
|
|
222 | * RequestInfo is sort of a meta command. There is some specific |
|
|
223 | * request of information, but we call other functions to provide |
|
|
224 | * that information. |
|
|
225 | */ |
|
|
226 | void |
|
|
227 | RequestInfo (char *buf, int len, client_socket * ns) |
|
|
228 | { |
|
|
229 | char *params = NULL, *cp; |
|
|
230 | |
|
|
231 | /* No match */ |
|
|
232 | char bigbuf[MAX_BUF]; |
|
|
233 | int slen; |
|
|
234 | |
|
|
235 | /* Set up replyinfo before we modify any of the buffers - this is used |
|
|
236 | * if we don't find a match. |
|
|
237 | */ |
|
|
238 | strcpy (bigbuf, "replyinfo "); |
|
|
239 | slen = strlen (bigbuf); |
|
|
240 | safe_strcat (bigbuf, buf, &slen, MAX_BUF); |
|
|
241 | |
|
|
242 | /* find the first space, make it null, and update the |
|
|
243 | * params pointer. |
|
|
244 | */ |
|
|
245 | for (cp = buf; *cp != '\0'; cp++) |
|
|
246 | if (*cp == ' ') |
|
|
247 | { |
|
|
248 | *cp = '\0'; |
|
|
249 | params = cp + 1; |
|
|
250 | break; |
|
|
251 | } |
|
|
252 | |
|
|
253 | if (!strcmp (buf, "image_info")) |
|
|
254 | send_image_info (ns, params); |
|
|
255 | else if (!strcmp (buf, "image_sums")) |
|
|
256 | send_image_sums (ns, params); |
|
|
257 | else if (!strcmp (buf, "skill_info")) |
|
|
258 | send_skill_info (ns, params); |
|
|
259 | else if (!strcmp (buf, "spell_paths")) |
|
|
260 | send_spell_paths (ns, params); |
|
|
261 | else |
|
|
262 | ns->send_packet (bigbuf, len); |
224 | } |
263 | } |
225 | |
264 | |
226 | void |
265 | void |
227 | ExtCmd (char *buf, int len, player *pl) |
266 | ExtCmd (char *buf, int len, player *pl) |
228 | { |
267 | { |
… | |
… | |
699 | |
738 | |
700 | sl << "smooth " |
739 | sl << "smooth " |
701 | << uint16 (face) |
740 | << uint16 (face) |
702 | << uint16 (smoothface); |
741 | << uint16 (smoothface); |
703 | |
742 | |
704 | Send_With_Handling (ns, &sl); |
743 | ns->send_packet (sl); |
705 | } |
744 | } |
706 | |
745 | |
707 | /** |
746 | /** |
708 | * Tells client the picture it has to use |
747 | * Tells client the picture it has to use |
709 | * to smooth a picture number given as argument. |
748 | * to smooth a picture number given as argument. |
… | |
… | |
774 | * etc.). It is a lot like PlayerCmd above, but is called with the |
813 | * etc.). It is a lot like PlayerCmd above, but is called with the |
775 | * 'ncom' method which gives more information back to the client so it |
814 | * 'ncom' method which gives more information back to the client so it |
776 | * can throttle. |
815 | * can throttle. |
777 | */ |
816 | */ |
778 | void |
817 | void |
779 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
818 | NewPlayerCmd (char *buf, int len, player *pl) |
780 | { |
819 | { |
781 | int time, repeat; |
820 | int time, repeat; |
782 | char command[MAX_BUF]; |
821 | char command[MAX_BUF]; |
783 | int pktlen; |
822 | int pktlen; |
784 | |
823 | |
… | |
… | |
786 | { |
825 | { |
787 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
826 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
788 | return; |
827 | return; |
789 | } |
828 | } |
790 | |
829 | |
791 | pktlen = net_uint16 (buf); |
830 | pktlen = net_uint16 ((uint8 *)buf); |
792 | repeat = net_uint32 (buf + 2); |
831 | repeat = net_uint32 ((uint8 *)buf + 2); |
793 | |
832 | |
794 | /* -1 is special - no repeat, but don't update */ |
833 | /* -1 is special - no repeat, but don't update */ |
795 | if (repeat != -1) |
834 | if (repeat != -1) |
796 | pl->count = repeat; |
835 | pl->count = repeat; |
797 | |
836 | |
798 | if ((len - 4) >= MAX_BUF) |
837 | if ((len - 4) >= MAX_BUF) |
799 | len = MAX_BUF - 5; |
838 | len = MAX_BUF - 5; |
800 | |
839 | |
801 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
840 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
802 | command[len - 4] = '\0'; |
841 | command[len - 4] = 0; |
803 | |
|
|
804 | /* The following should never happen with a proper or honest client. |
|
|
805 | * Therefore, the error message doesn't have to be too clear - if |
|
|
806 | * someone is playing with a hacked/non working client, this gives them |
|
|
807 | * an idea of the problem, but they deserve what they get |
|
|
808 | */ |
|
|
809 | if (pl->state != ST_PLAYING) |
|
|
810 | { |
|
|
811 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
812 | return; |
|
|
813 | } |
|
|
814 | |
842 | |
815 | /* This should not happen anymore. */ |
843 | /* This should not happen anymore. */ |
816 | if (pl->ob->speed_left < -1.0) |
844 | if (pl->ob->speed_left < -1.0) |
817 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
845 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
818 | |
846 | |
… | |
… | |
832 | |
860 | |
833 | /* Send confirmation of command execution now */ |
861 | /* Send confirmation of command execution now */ |
834 | |
862 | |
835 | packet sl; |
863 | packet sl; |
836 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
864 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
837 | Send_With_Handling (pl->socket, &sl); |
865 | pl->socket->send_packet (sl); |
838 | } |
866 | } |
839 | |
867 | |
840 | |
868 | |
841 | /** This is a reply to a previous query. */ |
869 | /** This is a reply to a previous query. */ |
842 | void |
870 | void |
… | |
… | |
1173 | set_title (pl->ob, buf); |
1201 | set_title (pl->ob, buf); |
1174 | AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); |
1202 | AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); |
1175 | |
1203 | |
1176 | /* Only send it away if we have some actual data */ |
1204 | /* Only send it away if we have some actual data */ |
1177 | if (sl.length () > 6) |
1205 | if (sl.length () > 6) |
1178 | Send_With_Handling (pl->socket, &sl); |
1206 | pl->socket->send_packet (sl); |
1179 | } |
1207 | } |
1180 | |
1208 | |
1181 | /** |
1209 | /** |
1182 | * Tells the client that here is a player it should start using. |
1210 | * Tells the client that here is a player it should start using. |
1183 | */ |
1211 | */ |
… | |
… | |
1192 | sl << uint32 (pl->ob->count) |
1220 | sl << uint32 (pl->ob->count) |
1193 | << uint32 (weight) |
1221 | << uint32 (weight) |
1194 | << uint32 (pl->ob->face->number) |
1222 | << uint32 (pl->ob->face->number) |
1195 | << data8 (pl->ob->name); |
1223 | << data8 (pl->ob->name); |
1196 | |
1224 | |
1197 | Send_With_Handling (pl->socket, &sl); |
1225 | pl->socket->send_packet (sl); |
1198 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1226 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1199 | } |
1227 | } |
1200 | |
1228 | |
1201 | /** |
1229 | /** |
1202 | * Need to send an animation sequence to the client. |
1230 | * Need to send an animation sequence to the client. |
… | |
… | |
1234 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1262 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1235 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1263 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1236 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1264 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1237 | } |
1265 | } |
1238 | |
1266 | |
1239 | Send_With_Handling (ns, &sl); |
1267 | ns->send_packet (sl); |
1240 | |
1268 | |
1241 | ns->anims_sent[anim_num] = 1; |
1269 | ns->anims_sent[anim_num] = 1; |
1242 | } |
1270 | } |
1243 | |
1271 | |
1244 | |
1272 | |
… | |
… | |
1868 | * with no faces tells the client to blank out the |
1896 | * with no faces tells the client to blank out the |
1869 | * space. |
1897 | * space. |
1870 | */ |
1898 | */ |
1871 | got_one = 0; |
1899 | got_one = 0; |
1872 | for (i = oldlen + 2; i < sl.length (); i++) |
1900 | for (i = oldlen + 2; i < sl.length (); i++) |
1873 | if (sl.buf[i]) |
1901 | if (sl[i]) |
1874 | got_one = 1; |
1902 | got_one = 1; |
1875 | |
1903 | |
1876 | if (got_one && (mask & 0xf)) |
1904 | if (got_one && (mask & 0xf)) |
1877 | sl.buf[oldlen + 1] = mask & 0xff; |
1905 | sl[oldlen + 1] = mask & 0xff; |
1878 | else |
1906 | else |
1879 | { /*either all faces blank, either no face at all */ |
1907 | { /*either all faces blank, either no face at all */ |
1880 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1908 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1881 | sl.reset (oldlen + 2); |
1909 | sl.reset (oldlen + 2); |
1882 | else |
1910 | else |
… | |
… | |
1948 | |
1976 | |
1949 | map_clearcell (&lastcell, 0, 0, 0, count); |
1977 | map_clearcell (&lastcell, 0, 0, 0, count); |
1950 | } |
1978 | } |
1951 | |
1979 | |
1952 | if ((mask & 0xf) || need_send) |
1980 | if ((mask & 0xf) || need_send) |
1953 | sl.buf[oldlen + 1] = mask & 0xff; |
1981 | sl[oldlen + 1] = mask & 0xff; |
1954 | else |
1982 | else |
1955 | sl.reset (oldlen); |
1983 | sl.reset (oldlen); |
1956 | } |
1984 | } |
1957 | else |
1985 | else |
1958 | { |
1986 | { |
… | |
… | |
1988 | mask |= 0x8; |
2016 | mask |= 0x8; |
1989 | |
2017 | |
1990 | if (socket.extmap) |
2018 | if (socket.extmap) |
1991 | { |
2019 | { |
1992 | *last_ext |= 0x80; |
2020 | *last_ext |= 0x80; |
1993 | last_ext = sl.buf + sl.length (); |
2021 | last_ext = &sl[sl.length ()]; |
1994 | sl << uint8 (d); |
2022 | sl << uint8 (d); |
1995 | } |
2023 | } |
1996 | else |
2024 | else |
1997 | sl << uint8 (255 - 64 * d); |
2025 | sl << uint8 (255 - 64 * d); |
1998 | } |
2026 | } |
… | |
… | |
2032 | { |
2060 | { |
2033 | lastcell.stat_hp = stat_hp; |
2061 | lastcell.stat_hp = stat_hp; |
2034 | |
2062 | |
2035 | mask |= 0x8; |
2063 | mask |= 0x8; |
2036 | *last_ext |= 0x80; |
2064 | *last_ext |= 0x80; |
2037 | last_ext = sl.buf + sl.length (); |
2065 | last_ext = &sl[sl.length ()]; |
2038 | |
2066 | |
2039 | sl << uint8 (5) << uint8 (stat_hp); |
2067 | sl << uint8 (5) << uint8 (stat_hp); |
2040 | |
2068 | |
2041 | if (stat_width > 1) |
2069 | if (stat_width > 1) |
2042 | { |
2070 | { |
2043 | *last_ext |= 0x80; |
2071 | *last_ext |= 0x80; |
2044 | last_ext = sl.buf + sl.length (); |
2072 | last_ext = &sl[sl.length ()]; |
2045 | |
2073 | |
2046 | sl << uint8 (6) << uint8 (stat_width); |
2074 | sl << uint8 (6) << uint8 (stat_width); |
2047 | } |
2075 | } |
2048 | } |
2076 | } |
2049 | |
2077 | |
… | |
… | |
2051 | { |
2079 | { |
2052 | lastcell.player = player; |
2080 | lastcell.player = player; |
2053 | |
2081 | |
2054 | mask |= 0x8; |
2082 | mask |= 0x8; |
2055 | *last_ext |= 0x80; |
2083 | *last_ext |= 0x80; |
2056 | last_ext = sl.buf + sl.length (); |
2084 | last_ext = &sl[sl.length ()]; |
2057 | |
2085 | |
2058 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2086 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2059 | } |
2087 | } |
2060 | |
2088 | |
2061 | if (lastcell.flags != flags) |
2089 | if (lastcell.flags != flags) |
2062 | { |
2090 | { |
2063 | lastcell.flags = flags; |
2091 | lastcell.flags = flags; |
2064 | |
2092 | |
2065 | mask |= 0x8; |
2093 | mask |= 0x8; |
2066 | *last_ext |= 0x80; |
2094 | *last_ext |= 0x80; |
2067 | last_ext = sl.buf + sl.length (); |
2095 | last_ext = &sl[sl.length ()]; |
2068 | |
2096 | |
2069 | sl << uint8 (8) << uint8 (flags); |
2097 | sl << uint8 (8) << uint8 (flags); |
2070 | } |
2098 | } |
2071 | } |
2099 | } |
2072 | |
2100 | |
… | |
… | |
2114 | * space by checking the mask. If so, update the mask. |
2142 | * space by checking the mask. If so, update the mask. |
2115 | * if not, reset the len to that from before adding the mask |
2143 | * if not, reset the len to that from before adding the mask |
2116 | * value, so we don't send those bits. |
2144 | * value, so we don't send those bits. |
2117 | */ |
2145 | */ |
2118 | if (mask & 0xf) |
2146 | if (mask & 0xf) |
2119 | sl.buf[oldlen + 1] = mask & 0xff; |
2147 | sl[oldlen + 1] = mask & 0xff; |
2120 | else |
2148 | else |
2121 | sl.reset (oldlen); |
2149 | sl.reset (oldlen); |
2122 | |
2150 | |
2123 | if (emask & 0xf) |
2151 | if (emask & 0xf) |
2124 | esl.buf[eoldlen + 1] = emask & 0xff; |
2152 | esl[eoldlen + 1] = emask & 0xff; |
2125 | else |
2153 | else |
2126 | esl.reset (eoldlen); |
2154 | esl.reset (eoldlen); |
2127 | } /* else this is a viewable space */ |
2155 | } /* else this is a viewable space */ |
2128 | } /* for x loop */ |
2156 | } /* for x loop */ |
2129 | } /* for y loop */ |
2157 | } /* for y loop */ |
… | |
… | |
2135 | { |
2163 | { |
2136 | /* No map data will follow, so don't say the client |
2164 | /* No map data will follow, so don't say the client |
2137 | * it doesn't need draw! |
2165 | * it doesn't need draw! |
2138 | */ |
2166 | */ |
2139 | ewhatflag &= (~EMI_NOREDRAW); |
2167 | ewhatflag &= (~EMI_NOREDRAW); |
2140 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2168 | esl[ewhatstart + 1] = ewhatflag & 0xff; |
2141 | } |
2169 | } |
2142 | |
2170 | |
2143 | if (esl.length () > estartlen) |
2171 | if (esl.length () > estartlen) |
2144 | Send_With_Handling (&socket, &esl); |
2172 | socket.send_packet (esl); |
2145 | } |
2173 | } |
2146 | |
2174 | |
2147 | if (sl.length () > startlen || socket.sent_scroll) |
2175 | if (sl.length () > startlen || socket.sent_scroll) |
2148 | { |
2176 | { |
2149 | Send_With_Handling (&socket, &sl); |
2177 | socket.send_packet (sl); |
2150 | socket.sent_scroll = 0; |
2178 | socket.sent_scroll = 0; |
2151 | } |
2179 | } |
2152 | } |
2180 | } |
2153 | |
2181 | |
2154 | /** |
2182 | /** |
… | |
… | |
2246 | { |
2274 | { |
2247 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2275 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2248 | fatal (0); |
2276 | fatal (0); |
2249 | } |
2277 | } |
2250 | |
2278 | |
2251 | Send_With_Handling (ns, &sl); |
2279 | ns->send_packet (sl); |
2252 | } |
2280 | } |
2253 | |
2281 | |
2254 | /** |
2282 | /** |
2255 | * This sends the spell path to name mapping. We ignore |
2283 | * This sends the spell path to name mapping. We ignore |
2256 | * the params - we always send the same info no matter what. |
2284 | * the params - we always send the same info no matter what. |
… | |
… | |
2269 | { |
2297 | { |
2270 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2298 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2271 | fatal (0); |
2299 | fatal (0); |
2272 | } |
2300 | } |
2273 | |
2301 | |
2274 | Send_With_Handling (ns, &sl); |
2302 | ns->send_packet (sl); |
2275 | } |
2303 | } |
2276 | |
2304 | |
2277 | /** |
2305 | /** |
2278 | * This looks for any spells the player may have that have changed their stats. |
2306 | * This looks for any spells the player may have that have changed their stats. |
2279 | * it then sends an updspell packet for each spell that has changed in this way |
2307 | * it then sends an updspell packet for each spell that has changed in this way |
… | |
… | |
2319 | |
2347 | |
2320 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2348 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2321 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2349 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2322 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2350 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2323 | |
2351 | |
2324 | Send_With_Handling (pl->socket, &sl); |
2352 | pl->socket->send_packet (sl); |
2325 | } |
2353 | } |
2326 | } |
2354 | } |
2327 | } |
2355 | } |
2328 | } |
2356 | } |
2329 | |
2357 | |
… | |
… | |
2342 | packet sl; |
2370 | packet sl; |
2343 | |
2371 | |
2344 | sl << "delspell " |
2372 | sl << "delspell " |
2345 | << uint32 (spell->count); |
2373 | << uint32 (spell->count); |
2346 | |
2374 | |
2347 | Send_With_Handling (pl->socket, &sl); |
2375 | pl->socket->send_packet (sl); |
2348 | } |
2376 | } |
2349 | |
2377 | |
2350 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2378 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2351 | static void |
2379 | static void |
2352 | append_spell (player *pl, packet &sl, object *spell) |
2380 | append_spell (player *pl, packet &sl, object *spell) |
… | |
… | |
2429 | if (spell->type != SPELL) |
2457 | if (spell->type != SPELL) |
2430 | continue; |
2458 | continue; |
2431 | |
2459 | |
2432 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2460 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2433 | { |
2461 | { |
2434 | Send_With_Handling (pl->socket, &sl); |
2462 | pl->socket->send_packet (sl); |
2435 | |
2463 | |
2436 | sl.reset (); |
2464 | sl.reset (); |
2437 | sl << "addspell "; |
2465 | sl << "addspell "; |
2438 | } |
2466 | } |
2439 | |
2467 | |
… | |
… | |
2453 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2481 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2454 | fatal (0); |
2482 | fatal (0); |
2455 | } |
2483 | } |
2456 | |
2484 | |
2457 | /* finally, we can send the packet */ |
2485 | /* finally, we can send the packet */ |
2458 | Send_With_Handling (pl->socket, &sl); |
2486 | pl->socket->send_packet (sl); |
2459 | } |
2487 | } |
2460 | |
2488 | |