ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.36 by root, Thu Dec 14 04:30:33 2006 UTC vs.
Revision 1.39 by root, Fri Dec 15 03:53:44 2006 UTC

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
699 694
700 sl << "smooth " 695 sl << "smooth "
701 << uint16 (face) 696 << uint16 (face)
702 << uint16 (smoothface); 697 << uint16 (smoothface);
703 698
704 Send_With_Handling (ns, &sl); 699 ns->send_packet (sl);
705} 700}
706 701
707 /** 702 /**
708 * Tells client the picture it has to use 703 * Tells client the picture it has to use
709 * to smooth a picture number given as argument. 704 * to smooth a picture number given as argument.
774 * etc.). It is a lot like PlayerCmd above, but is called with the 769 * 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 770 * 'ncom' method which gives more information back to the client so it
776 * can throttle. 771 * can throttle.
777 */ 772 */
778void 773void
779NewPlayerCmd (uint8 * buf, int len, player *pl) 774NewPlayerCmd (char *buf, int len, player *pl)
780{ 775{
781 int time, repeat; 776 int time, repeat;
782 char command[MAX_BUF]; 777 char command[MAX_BUF];
783 int pktlen; 778 int pktlen;
784 779
786 { 781 {
787 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 782 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
788 return; 783 return;
789 } 784 }
790 785
791 pktlen = net_uint16 (buf); 786 pktlen = net_uint16 ((uint8 *)buf);
792 repeat = net_uint32 (buf + 2); 787 repeat = net_uint32 ((uint8 *)buf + 2);
793 788
794 /* -1 is special - no repeat, but don't update */ 789 /* -1 is special - no repeat, but don't update */
795 if (repeat != -1) 790 if (repeat != -1)
796 pl->count = repeat; 791 pl->count = repeat;
797 792
798 if ((len - 4) >= MAX_BUF) 793 if ((len - 4) >= MAX_BUF)
799 len = MAX_BUF - 5; 794 len = MAX_BUF - 5;
800 795
801 strncpy ((char *) command, (char *) buf + 6, len - 4); 796 strncpy ((char *) command, (char *) buf + 6, len - 4);
802 command[len - 4] = '\0'; 797 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 798
815 /* This should not happen anymore. */ 799 /* This should not happen anymore. */
816 if (pl->ob->speed_left < -1.0) 800 if (pl->ob->speed_left < -1.0)
817 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 801 LOG (llevError, "Player has negative time - shouldn't do command.\n");
818 802
832 816
833 /* Send confirmation of command execution now */ 817 /* Send confirmation of command execution now */
834 818
835 packet sl; 819 packet sl;
836 sl << "comc " << uint16 (pktlen) << uint32 (time); 820 sl << "comc " << uint16 (pktlen) << uint32 (time);
837 Send_With_Handling (pl->socket, &sl); 821 pl->socket->send_packet (sl);
838} 822}
839 823
840 824
841/** This is a reply to a previous query. */ 825/** This is a reply to a previous query. */
842void 826void
1173 set_title (pl->ob, buf); 1157 set_title (pl->ob, buf);
1174 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); 1158 AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE);
1175 1159
1176 /* Only send it away if we have some actual data */ 1160 /* Only send it away if we have some actual data */
1177 if (sl.length () > 6) 1161 if (sl.length () > 6)
1178 Send_With_Handling (pl->socket, &sl); 1162 pl->socket->send_packet (sl);
1179} 1163}
1180 1164
1181/** 1165/**
1182 * Tells the client that here is a player it should start using. 1166 * Tells the client that here is a player it should start using.
1183 */ 1167 */
1192 sl << uint32 (pl->ob->count) 1176 sl << uint32 (pl->ob->count)
1193 << uint32 (weight) 1177 << uint32 (weight)
1194 << uint32 (pl->ob->face->number) 1178 << uint32 (pl->ob->face->number)
1195 << data8 (pl->ob->name); 1179 << data8 (pl->ob->name);
1196 1180
1197 Send_With_Handling (pl->socket, &sl); 1181 pl->socket->send_packet (sl);
1198 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1182 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1199} 1183}
1200 1184
1201/** 1185/**
1202 * Need to send an animation sequence to the client. 1186 * Need to send an animation sequence to the client.
1234 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) 1218 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1235 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1219 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1236 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1220 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1237 } 1221 }
1238 1222
1239 Send_With_Handling (ns, &sl); 1223 ns->send_packet (sl);
1240 1224
1241 ns->anims_sent[anim_num] = 1; 1225 ns->anims_sent[anim_num] = 1;
1242} 1226}
1243 1227
1244 1228
1868 * with no faces tells the client to blank out the 1852 * with no faces tells the client to blank out the
1869 * space. 1853 * space.
1870 */ 1854 */
1871 got_one = 0; 1855 got_one = 0;
1872 for (i = oldlen + 2; i < sl.length (); i++) 1856 for (i = oldlen + 2; i < sl.length (); i++)
1873 if (sl.buf[i]) 1857 if (sl[i])
1874 got_one = 1; 1858 got_one = 1;
1875 1859
1876 if (got_one && (mask & 0xf)) 1860 if (got_one && (mask & 0xf))
1877 sl.buf[oldlen + 1] = mask & 0xff; 1861 sl[oldlen + 1] = mask & 0xff;
1878 else 1862 else
1879 { /*either all faces blank, either no face at all */ 1863 { /*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 */ 1864 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1881 sl.reset (oldlen + 2); 1865 sl.reset (oldlen + 2);
1882 else 1866 else
1948 1932
1949 map_clearcell (&lastcell, 0, 0, 0, count); 1933 map_clearcell (&lastcell, 0, 0, 0, count);
1950 } 1934 }
1951 1935
1952 if ((mask & 0xf) || need_send) 1936 if ((mask & 0xf) || need_send)
1953 sl.buf[oldlen + 1] = mask & 0xff; 1937 sl[oldlen + 1] = mask & 0xff;
1954 else 1938 else
1955 sl.reset (oldlen); 1939 sl.reset (oldlen);
1956 } 1940 }
1957 else 1941 else
1958 { 1942 {
1988 mask |= 0x8; 1972 mask |= 0x8;
1989 1973
1990 if (socket.extmap) 1974 if (socket.extmap)
1991 { 1975 {
1992 *last_ext |= 0x80; 1976 *last_ext |= 0x80;
1993 last_ext = sl.buf + sl.length (); 1977 last_ext = &sl[sl.length ()];
1994 sl << uint8 (d); 1978 sl << uint8 (d);
1995 } 1979 }
1996 else 1980 else
1997 sl << uint8 (255 - 64 * d); 1981 sl << uint8 (255 - 64 * d);
1998 } 1982 }
2032 { 2016 {
2033 lastcell.stat_hp = stat_hp; 2017 lastcell.stat_hp = stat_hp;
2034 2018
2035 mask |= 0x8; 2019 mask |= 0x8;
2036 *last_ext |= 0x80; 2020 *last_ext |= 0x80;
2037 last_ext = sl.buf + sl.length (); 2021 last_ext = &sl[sl.length ()];
2038 2022
2039 sl << uint8 (5) << uint8 (stat_hp); 2023 sl << uint8 (5) << uint8 (stat_hp);
2040 2024
2041 if (stat_width > 1) 2025 if (stat_width > 1)
2042 { 2026 {
2043 *last_ext |= 0x80; 2027 *last_ext |= 0x80;
2044 last_ext = sl.buf + sl.length (); 2028 last_ext = &sl[sl.length ()];
2045 2029
2046 sl << uint8 (6) << uint8 (stat_width); 2030 sl << uint8 (6) << uint8 (stat_width);
2047 } 2031 }
2048 } 2032 }
2049 2033
2051 { 2035 {
2052 lastcell.player = player; 2036 lastcell.player = player;
2053 2037
2054 mask |= 0x8; 2038 mask |= 0x8;
2055 *last_ext |= 0x80; 2039 *last_ext |= 0x80;
2056 last_ext = sl.buf + sl.length (); 2040 last_ext = &sl[sl.length ()];
2057 2041
2058 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2042 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2059 } 2043 }
2060 2044
2061 if (lastcell.flags != flags) 2045 if (lastcell.flags != flags)
2062 { 2046 {
2063 lastcell.flags = flags; 2047 lastcell.flags = flags;
2064 2048
2065 mask |= 0x8; 2049 mask |= 0x8;
2066 *last_ext |= 0x80; 2050 *last_ext |= 0x80;
2067 last_ext = sl.buf + sl.length (); 2051 last_ext = &sl[sl.length ()];
2068 2052
2069 sl << uint8 (8) << uint8 (flags); 2053 sl << uint8 (8) << uint8 (flags);
2070 } 2054 }
2071 } 2055 }
2072 2056
2114 * space by checking the mask. If so, update the mask. 2098 * space by checking the mask. If so, update the mask.
2115 * if not, reset the len to that from before adding the mask 2099 * if not, reset the len to that from before adding the mask
2116 * value, so we don't send those bits. 2100 * value, so we don't send those bits.
2117 */ 2101 */
2118 if (mask & 0xf) 2102 if (mask & 0xf)
2119 sl.buf[oldlen + 1] = mask & 0xff; 2103 sl[oldlen + 1] = mask & 0xff;
2120 else 2104 else
2121 sl.reset (oldlen); 2105 sl.reset (oldlen);
2122 2106
2123 if (emask & 0xf) 2107 if (emask & 0xf)
2124 esl.buf[eoldlen + 1] = emask & 0xff; 2108 esl[eoldlen + 1] = emask & 0xff;
2125 else 2109 else
2126 esl.reset (eoldlen); 2110 esl.reset (eoldlen);
2127 } /* else this is a viewable space */ 2111 } /* else this is a viewable space */
2128 } /* for x loop */ 2112 } /* for x loop */
2129 } /* for y loop */ 2113 } /* for y loop */
2135 { 2119 {
2136 /* No map data will follow, so don't say the client 2120 /* No map data will follow, so don't say the client
2137 * it doesn't need draw! 2121 * it doesn't need draw!
2138 */ 2122 */
2139 ewhatflag &= (~EMI_NOREDRAW); 2123 ewhatflag &= (~EMI_NOREDRAW);
2140 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2124 esl[ewhatstart + 1] = ewhatflag & 0xff;
2141 } 2125 }
2142 2126
2143 if (esl.length () > estartlen) 2127 if (esl.length () > estartlen)
2144 Send_With_Handling (&socket, &esl); 2128 socket.send_packet (esl);
2145 } 2129 }
2146 2130
2147 if (sl.length () > startlen || socket.sent_scroll) 2131 if (sl.length () > startlen || socket.sent_scroll)
2148 { 2132 {
2149 Send_With_Handling (&socket, &sl); 2133 socket.send_packet (sl);
2150 socket.sent_scroll = 0; 2134 socket.sent_scroll = 0;
2151 } 2135 }
2152} 2136}
2153 2137
2154/** 2138/**
2246 { 2230 {
2247 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2231 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2248 fatal (0); 2232 fatal (0);
2249 } 2233 }
2250 2234
2251 Send_With_Handling (ns, &sl); 2235 ns->send_packet (sl);
2252} 2236}
2253 2237
2254/** 2238/**
2255 * This sends the spell path to name mapping. We ignore 2239 * This sends the spell path to name mapping. We ignore
2256 * the params - we always send the same info no matter what. 2240 * the params - we always send the same info no matter what.
2269 { 2253 {
2270 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2254 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2271 fatal (0); 2255 fatal (0);
2272 } 2256 }
2273 2257
2274 Send_With_Handling (ns, &sl); 2258 ns->send_packet (sl);
2275} 2259}
2276 2260
2277/** 2261/**
2278 * This looks for any spells the player may have that have changed their stats. 2262 * 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 2263 * it then sends an updspell packet for each spell that has changed in this way
2319 2303
2320 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2304 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2321 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2305 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2322 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2306 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2323 2307
2324 Send_With_Handling (pl->socket, &sl); 2308 pl->socket->send_packet (sl);
2325 } 2309 }
2326 } 2310 }
2327 } 2311 }
2328} 2312}
2329 2313
2342 packet sl; 2326 packet sl;
2343 2327
2344 sl << "delspell " 2328 sl << "delspell "
2345 << uint32 (spell->count); 2329 << uint32 (spell->count);
2346 2330
2347 Send_With_Handling (pl->socket, &sl); 2331 pl->socket->send_packet (sl);
2348} 2332}
2349 2333
2350/* appends the spell *spell to the Socklist we will send the data to. */ 2334/* appends the spell *spell to the Socklist we will send the data to. */
2351static void 2335static void
2352append_spell (player *pl, packet &sl, object *spell) 2336append_spell (player *pl, packet &sl, object *spell)
2429 if (spell->type != SPELL) 2413 if (spell->type != SPELL)
2430 continue; 2414 continue;
2431 2415
2432 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2416 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2433 { 2417 {
2434 Send_With_Handling (pl->socket, &sl); 2418 pl->socket->send_packet (sl);
2435 2419
2436 sl.reset (); 2420 sl.reset ();
2437 sl << "addspell "; 2421 sl << "addspell ";
2438 } 2422 }
2439 2423
2453 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2437 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2454 fatal (0); 2438 fatal (0);
2455 } 2439 }
2456 2440
2457 /* finally, we can send the packet */ 2441 /* finally, we can send the packet */
2458 Send_With_Handling (pl->socket, &sl); 2442 pl->socket->send_packet (sl);
2459} 2443}
2460 2444

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines