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.32 by root, Thu Dec 14 01:12:35 2006 UTC vs.
Revision 1.34 by root, Thu Dec 14 01:59:10 2006 UTC

41 * if a face has not already been sent to the client, it is sent now. 41 * if a face has not already been sent to the client, it is sent now.
42 * 42 *
43 * mapcellchanged, compactlayer, compactstack, perform the map compressing 43 * mapcellchanged, compactlayer, compactstack, perform the map compressing
44 * operations 44 * operations
45 * 45 *
46 * esrv_map_doneredraw finishes the map update, and ships across the
47 * map updates.
48 *
49 */ 46 */
50 47
51#include <global.h> 48#include <global.h>
52#include <sproto.h> 49#include <sproto.h>
53 50
102{ 99{
103 struct Map newmap; 100 struct Map newmap;
104 int x, y, mx, my; 101 int x, y, mx, my;
105 102
106 { 103 {
107 SockList sl (MAXSOCKBUF); 104 packet sl;
108 105
109 sl.printf ("map_scroll %d %d", dx, dy); 106 sl.printf ("map_scroll %d %d", dx, dy);
110 ns->send_packet (sl); 107 ns->send_packet (sl);
111 sl.free ();
112 } 108 }
113 109
114 /* If we are using the Map1aCmd, we may in fact send 110 /* If we are using the Map1aCmd, we may in fact send
115 * head information that is outside the viewable map. 111 * head information that is outside the viewable map.
116 * So set the mx,my to the max value we want to 112 * So set the mx,my to the max value we want to
706 if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) 702 if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE))
707 esrv_send_face (ns, smoothface, 0); 703 esrv_send_face (ns, smoothface, 0);
708 704
709 ns->faces_sent[face] |= NS_FACESENT_SMOOTH; 705 ns->faces_sent[face] |= NS_FACESENT_SMOOTH;
710 706
711 SockList sl (MAXSOCKBUF); 707 packet sl;
712 708
713 sl << "smooth " 709 sl << "smooth "
714 << uint16 (face) 710 << uint16 (face)
715 << uint16 (smoothface); 711 << uint16 (smoothface);
716 712
717 Send_With_Handling (ns, &sl); 713 Send_With_Handling (ns, &sl);
718 sl.free ();
719} 714}
720 715
721 /** 716 /**
722 * Tells client the picture it has to use 717 * Tells client the picture it has to use
723 * to smooth a picture number given as argument. 718 * to smooth a picture number given as argument.
792void 787void
793NewPlayerCmd (uint8 * buf, int len, player *pl) 788NewPlayerCmd (uint8 * buf, int len, player *pl)
794{ 789{
795 int time, repeat; 790 int time, repeat;
796 char command[MAX_BUF]; 791 char command[MAX_BUF];
797 short packet; 792 int pktlen;
798 793
799 if (len < 7) 794 if (len < 7)
800 { 795 {
801 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 796 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
802 return; 797 return;
803 } 798 }
804 799
805 packet = net_uint16 (buf); 800 pktlen = net_uint16 (buf);
806 repeat = net_uint32 (buf + 2); 801 repeat = net_uint32 (buf + 2);
807 802
808 /* -1 is special - no repeat, but don't update */ 803 /* -1 is special - no repeat, but don't update */
809 if (repeat != -1) 804 if (repeat != -1)
810 pl->count = repeat; 805 pl->count = repeat;
844 else 839 else
845 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 840 time = (int) (MAX_TIME / FABS (pl->ob->speed));
846 841
847 /* Send confirmation of command execution now */ 842 /* Send confirmation of command execution now */
848 843
849 SockList sl (MAXSOCKBUF); 844 packet sl;
850 sl << "comc " << uint16 (packet) << uint32 (time); 845 sl << "comc " << uint16 (pktlen) << uint32 (time);
851 Send_With_Handling (&pl->socket, &sl); 846 Send_With_Handling (&pl->socket, &sl);
852 sl.free ();
853} 847}
854 848
855 849
856/** This is a reply to a previous query. */ 850/** This is a reply to a previous query. */
857void 851void
1095esrv_update_stats (player *pl) 1089esrv_update_stats (player *pl)
1096{ 1090{
1097 char buf[MAX_BUF]; 1091 char buf[MAX_BUF];
1098 uint16 flags; 1092 uint16 flags;
1099 1093
1100 SockList sl (MAXSOCKBUF); 1094 packet sl;
1101 sl << "stats "; 1095 sl << "stats ";
1102 1096
1103 if (pl->ob != NULL) 1097 if (pl->ob != NULL)
1104 { 1098 {
1105 AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); 1099 AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP);
1187 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1181 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE);
1188 set_title (pl->ob, buf); 1182 set_title (pl->ob, buf);
1189 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE);
1190 1184
1191 /* Only send it away if we have some actual data */ 1185 /* Only send it away if we have some actual data */
1192 if (sl.len > 6) 1186 if (sl.length () > 6)
1193 {
1194#ifdef ESRV_DEBUG
1195 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1196#endif
1197 Send_With_Handling (&pl->socket, &sl); 1187 Send_With_Handling (&pl->socket, &sl);
1198 }
1199
1200 sl.free ();
1201} 1188}
1202 1189
1203/** 1190/**
1204 * Tells the client that here is a player it should start using. 1191 * Tells the client that here is a player it should start using.
1205 */ 1192 */
1206void 1193void
1207esrv_new_player (player *pl, uint32 weight) 1194esrv_new_player (player *pl, uint32 weight)
1208{ 1195{
1209 pl->last_weight = weight; 1196 pl->last_weight = weight;
1210 1197
1211 SockList sl (MAXSOCKBUF); 1198 packet sl;
1212 sl << "player "; 1199 sl << "player ";
1213 1200
1214 sl << uint32 (pl->ob->count) 1201 sl << uint32 (pl->ob->count)
1215 << uint32 (weight) 1202 << uint32 (weight)
1216 << uint32 (pl->ob->face->number) 1203 << uint32 (pl->ob->face->number)
1217 << data8 (pl->ob->name); 1204 << data8 (pl->ob->name);
1218 1205
1219 Send_With_Handling (&pl->socket, &sl); 1206 Send_With_Handling (&pl->socket, &sl);
1220 sl.free ();
1221 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1222} 1208}
1223 1209
1224/** 1210/**
1225 * Need to send an animation sequence to the client. 1211 * Need to send an animation sequence to the client.
1241 { 1227 {
1242 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); 1228 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
1243 return; 1229 return;
1244 } 1230 }
1245 1231
1246 SockList sl (MAXSOCKBUF); 1232 packet sl;
1247 1233
1248 sl << "anim " 1234 sl << "anim "
1249 << uint16 (anim_num) 1235 << uint16 (anim_num)
1250 << uint16 (0); /* flags - not used right now */ 1236 << uint16 (0); /* flags - not used right now */
1251 1237
1258 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1244 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1259 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ 1245 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1260 } 1246 }
1261 1247
1262 Send_With_Handling (ns, &sl); 1248 Send_With_Handling (ns, &sl);
1263 sl.free ();
1264 1249
1265 ns->anims_sent[anim_num] = 1; 1250 ns->anims_sent[anim_num] = 1;
1266} 1251}
1267 1252
1268 1253
1398 *fcur = *fcur | 128; /* mark for end of faces at this layer */ 1383 *fcur = *fcur | 128; /* mark for end of faces at this layer */
1399 } 1384 }
1400 return cur; 1385 return cur;
1401} 1386}
1402 1387
1403static void
1404esrv_map_doneredraw (NewSocket * ns, struct Map *newmap)
1405{
1406 static long frames, bytes, tbytes, tframes;
1407 char *cur;
1408
1409 SockList sl (MAXSOCKBUF);
1410 sl << "map ";
1411
1412 cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap);
1413 sl.len = cur - (char *) sl.buf;
1414
1415/* LOG(llevDebug, "Sending map command.\n");*/
1416
1417 if (sl.len > (int) strlen ("map ") || ns->sent_scroll)
1418 {
1419 /* All of this is just accounting stuff */
1420 if (tframes > 100)
1421 tframes = tbytes = 0;
1422
1423 tframes++;
1424 frames++;
1425 tbytes += sl.len;
1426 bytes += sl.len;
1427 memcpy (&ns->lastmap, newmap, sizeof (struct Map));
1428 Send_With_Handling (ns, &sl);
1429 ns->sent_scroll = 0;
1430 }
1431
1432 sl.free ();
1433}
1434
1435
1436/** Clears a map cell */ 1388/** Clears a map cell */
1437static void 1389static void
1438map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) 1390map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count)
1439{ 1391{
1440 cell->faces[0] = face0; 1392 cell->faces[0] = face0;
1479 * needs to get sent - if so, it adds the data, sending the head 1431 * needs to get sent - if so, it adds the data, sending the head
1480 * if needed, and returning 1. If this no data needs to get 1432 * if needed, and returning 1. If this no data needs to get
1481 * sent, it returns zero. 1433 * sent, it returns zero.
1482 */ 1434 */
1483static int 1435static int
1484check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) 1436check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer)
1485{ 1437{
1486 short face_num; 1438 short face_num;
1487 1439
1488 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1489 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1441 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number;
1523 * the case, it seems to make more sense to have these layer values 1475 * the case, it seems to make more sense to have these layer values
1524 * actually match. 1476 * actually match.
1525 */ 1477 */
1526 1478
1527static int 1479static int
1528update_space (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1480update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1529{ 1481{
1530 object *ob, *head; 1482 object *ob, *head;
1531 uint16 face_num; 1483 uint16 face_num;
1532 int bx, by, i; 1484 int bx, by, i;
1533 1485
1746 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1698 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1747 * take. 1699 * take.
1748 */ 1700 */
1749 1701
1750static inline int 1702static inline int
1751update_smooth (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1703update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1752{ 1704{
1753 object *ob; 1705 object *ob;
1754 int smoothlevel; /* old face_num; */ 1706 int smoothlevel; /* old face_num; */
1755 1707
1756 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1840 1792
1841 NewSocket &socket = pl->contr->socket; 1793 NewSocket &socket = pl->contr->socket;
1842 1794
1843 check_map_change (pl->contr); 1795 check_map_change (pl->contr);
1844 1796
1845 SockList sl (MAXSOCKBUF); 1797 packet sl;
1846 SockList esl (MAXSOCKBUF); 1798 packet esl;
1847 1799
1848 sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); 1800 sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a ");
1849 startlen = sl.len; 1801 startlen = sl.length ();
1850 1802
1851 /*Extendedmapinfo structure initialisation */ 1803 /*Extendedmapinfo structure initialisation */
1852 if (socket.ext_mapinfos) 1804 if (socket.ext_mapinfos)
1853 { 1805 {
1854 extendedinfos = EMI_NOREDRAW; 1806 extendedinfos = EMI_NOREDRAW;
1855 1807
1856 if (socket.EMI_smooth) 1808 if (socket.EMI_smooth)
1857 extendedinfos |= EMI_SMOOTH; 1809 extendedinfos |= EMI_SMOOTH;
1858 1810
1859 ewhatstart = esl.len; 1811 ewhatstart = esl.length ();
1860 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1812 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1861 could need to be taken away */ 1813 could need to be taken away */
1862 eentrysize = getExtendedMapInfoSize (&socket); 1814 eentrysize = getExtendedMapInfoSize (&socket);
1863 esl << "mapextended " 1815 esl << "mapextended "
1864 << uint8 (extendedinfos) 1816 << uint8 (extendedinfos)
1865 << uint8 (eentrysize); 1817 << uint8 (eentrysize);
1818
1866 estartlen = esl.len; 1819 estartlen = esl.length ();
1867 } 1820 }
1868 else 1821 else
1869 { 1822 {
1870 /* suppress compiler warnings */ 1823 /* suppress compiler warnings */
1871 ewhatstart = 0; 1824 ewhatstart = 0;
1909 */ 1862 */
1910 if (ax >= socket.mapx || ay >= socket.mapy) 1863 if (ax >= socket.mapx || ay >= socket.mapy)
1911 { 1864 {
1912 int i, got_one; 1865 int i, got_one;
1913 1866
1914 oldlen = sl.len; 1867 oldlen = sl.length ();
1915 1868
1916 sl << uint16 (mask); 1869 sl << uint16 (mask);
1917 1870
1918 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; 1871 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
1919 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; 1872 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
1923 * actually need to send that - just the coordinates 1876 * actually need to send that - just the coordinates
1924 * with no faces tells the client to blank out the 1877 * with no faces tells the client to blank out the
1925 * space. 1878 * space.
1926 */ 1879 */
1927 got_one = 0; 1880 got_one = 0;
1928 for (i = oldlen + 2; i < sl.len; i++) 1881 for (i = oldlen + 2; i < sl.length (); i++)
1929 if (sl.buf[i]) 1882 if (sl.buf[i])
1930 got_one = 1; 1883 got_one = 1;
1931 1884
1932 if (got_one && (mask & 0xf)) 1885 if (got_one && (mask & 0xf))
1933 sl.buf[oldlen + 1] = mask & 0xff; 1886 sl.buf[oldlen + 1] = mask & 0xff;
1934 else 1887 else
1935 { /*either all faces blank, either no face at all */ 1888 { /*either all faces blank, either no face at all */
1936 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1889 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1937 sl.len = oldlen + 2; 1890 sl.reset (oldlen + 2);
1938 else 1891 else
1939 sl.len = oldlen; 1892 sl.reset (oldlen);
1940 } 1893 }
1941 1894
1942 /*What concerns extendinfos, nothing to be done for now 1895 /*What concerns extendinfos, nothing to be done for now
1943 * (perhaps effects layer later) 1896 * (perhaps effects layer later)
1944 */ 1897 */
1974 1927
1975 /* This block deals with spaces that are not visible for whatever 1928 /* This block deals with spaces that are not visible for whatever
1976 * reason. Still may need to send the head for this space. 1929 * reason. Still may need to send the head for this space.
1977 */ 1930 */
1978 1931
1979 oldlen = sl.len; 1932 oldlen = sl.length ();
1980 1933
1981 sl << uint16 (mask); 1934 sl << uint16 (mask);
1982 1935
1983 if (lastcell.count != -1) 1936 if (lastcell.count != -1)
1984 need_send = 1; 1937 need_send = 1;
2006 } 1959 }
2007 1960
2008 if ((mask & 0xf) || need_send) 1961 if ((mask & 0xf) || need_send)
2009 sl.buf[oldlen + 1] = mask & 0xff; 1962 sl.buf[oldlen + 1] = mask & 0xff;
2010 else 1963 else
2011 sl.len = oldlen; 1964 sl.reset (oldlen);
2012 } 1965 }
2013 else 1966 else
2014 { 1967 {
2015 /* In this block, the space is visible or there are head objects 1968 /* In this block, the space is visible or there are head objects
2016 * we need to send. 1969 * we need to send.
2018 1971
2019 /* Rather than try to figure out what everything that we might 1972 /* Rather than try to figure out what everything that we might
2020 * need to send is, then form the packet after that, 1973 * need to send is, then form the packet after that,
2021 * we presume that we will in fact form a packet, and update 1974 * we presume that we will in fact form a packet, and update
2022 * the bits by what we do actually send. If we send nothing, 1975 * the bits by what we do actually send. If we send nothing,
2023 * we just back out sl.len to the old value, and no harm 1976 * we just back out sl.length () to the old value, and no harm
2024 * is done. 1977 * is done.
2025 * I think this is simpler than doing a bunch of checks to see 1978 * I think this is simpler than doing a bunch of checks to see
2026 * what if anything we need to send, setting the bits, then 1979 * what if anything we need to send, setting the bits, then
2027 * doing those checks again to add the real data. 1980 * doing those checks again to add the real data.
2028 */ 1981 */
2029 oldlen = sl.len; 1982 oldlen = sl.length ();
2030 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1983 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2031 eoldlen = esl.len; 1984 eoldlen = esl.length ();
2032 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1985 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2033 sl << uint16 (mask); 1986 sl << uint16 (mask);
2034 1987
2035 if (socket.ext_mapinfos) 1988 if (socket.ext_mapinfos)
2036 esl << uint16 (emask); 1989 esl << uint16 (emask);
2044 mask |= 0x8; 1997 mask |= 0x8;
2045 1998
2046 if (socket.extmap) 1999 if (socket.extmap)
2047 { 2000 {
2048 *last_ext |= 0x80; 2001 *last_ext |= 0x80;
2049 last_ext = sl.buf + sl.len; 2002 last_ext = sl.buf + sl.length ();
2050 sl << uint8 (d); 2003 sl << uint8 (d);
2051 } 2004 }
2052 else 2005 else
2053 sl << uint8 (255 - 64 * d); 2006 sl << uint8 (255 - 64 * d);
2054 } 2007 }
2088 { 2041 {
2089 lastcell.stat_hp = stat_hp; 2042 lastcell.stat_hp = stat_hp;
2090 2043
2091 mask |= 0x8; 2044 mask |= 0x8;
2092 *last_ext |= 0x80; 2045 *last_ext |= 0x80;
2093 last_ext = sl.buf + sl.len; 2046 last_ext = sl.buf + sl.length ();
2094 2047
2095 sl << uint8 (5) << uint8 (stat_hp); 2048 sl << uint8 (5) << uint8 (stat_hp);
2096 2049
2097 if (stat_width > 1) 2050 if (stat_width > 1)
2098 { 2051 {
2099 *last_ext |= 0x80; 2052 *last_ext |= 0x80;
2100 last_ext = sl.buf + sl.len; 2053 last_ext = sl.buf + sl.length ();
2101 2054
2102 sl << uint8 (6) << uint8 (stat_width); 2055 sl << uint8 (6) << uint8 (stat_width);
2103 } 2056 }
2104 } 2057 }
2105 2058
2107 { 2060 {
2108 lastcell.player = player; 2061 lastcell.player = player;
2109 2062
2110 mask |= 0x8; 2063 mask |= 0x8;
2111 *last_ext |= 0x80; 2064 *last_ext |= 0x80;
2112 last_ext = sl.buf + sl.len; 2065 last_ext = sl.buf + sl.length ();
2113 2066
2114 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2115 } 2068 }
2116 2069
2117 if (lastcell.flags != flags) 2070 if (lastcell.flags != flags)
2118 { 2071 {
2119 lastcell.flags = flags; 2072 lastcell.flags = flags;
2120 2073
2121 mask |= 0x8; 2074 mask |= 0x8;
2122 *last_ext |= 0x80; 2075 *last_ext |= 0x80;
2123 last_ext = sl.buf + sl.len; 2076 last_ext = sl.buf + sl.length ();
2124 2077
2125 sl << uint8 (8) << uint8 (flags); 2078 sl << uint8 (8) << uint8 (flags);
2126 } 2079 }
2127 } 2080 }
2128 2081
2172 * value, so we don't send those bits. 2125 * value, so we don't send those bits.
2173 */ 2126 */
2174 if (mask & 0xf) 2127 if (mask & 0xf)
2175 sl.buf[oldlen + 1] = mask & 0xff; 2128 sl.buf[oldlen + 1] = mask & 0xff;
2176 else 2129 else
2177 sl.len = oldlen; 2130 sl.reset (oldlen);
2178 2131
2179 if (emask & 0xf) 2132 if (emask & 0xf)
2180 esl.buf[eoldlen + 1] = emask & 0xff; 2133 esl.buf[eoldlen + 1] = emask & 0xff;
2181 else 2134 else
2182 esl.len = eoldlen; 2135 esl.reset (eoldlen);
2183 } /* else this is a viewable space */ 2136 } /* else this is a viewable space */
2184 } /* for x loop */ 2137 } /* for x loop */
2185 } /* for y loop */ 2138 } /* for y loop */
2186 2139
2187 /* Verify that we in fact do need to send this */ 2140 /* Verify that we in fact do need to send this */
2188 if (socket.ext_mapinfos) 2141 if (socket.ext_mapinfos)
2189 { 2142 {
2190 if (!(sl.len > startlen || socket.sent_scroll)) 2143 if (!(sl.length () > startlen || socket.sent_scroll))
2191 { 2144 {
2192 /* No map data will follow, so don't say the client 2145 /* No map data will follow, so don't say the client
2193 * it doesn't need draw! 2146 * it doesn't need draw!
2194 */ 2147 */
2195 ewhatflag &= (~EMI_NOREDRAW); 2148 ewhatflag &= (~EMI_NOREDRAW);
2196 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff;
2197 } 2150 }
2198 2151
2199 if (esl.len > estartlen) 2152 if (esl.length () > estartlen)
2200 Send_With_Handling (&socket, &esl); 2153 Send_With_Handling (&socket, &esl);
2201 } 2154 }
2202 2155
2203 if (sl.len > startlen || socket.sent_scroll) 2156 if (sl.length () > startlen || socket.sent_scroll)
2204 { 2157 {
2205 Send_With_Handling (&socket, &sl); 2158 Send_With_Handling (&socket, &sl);
2206 socket.sent_scroll = 0; 2159 socket.sent_scroll = 0;
2207 } 2160 }
2208
2209 sl.free ();
2210 esl.free ();
2211} 2161}
2212 2162
2213/** 2163/**
2214 * Draws client map. 2164 * Draws client map.
2215 */ 2165 */
2266 { 2216 {
2267 update_los (pl); 2217 update_los (pl);
2268 pl->contr->do_los = 0; 2218 pl->contr->do_los = 0;
2269 } 2219 }
2270 2220
2271 if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd)
2272 {
2273 /* Big maps need a different drawing mechanism to work */ 2221 /* Big maps need a different drawing mechanism to work */
2274 draw_client_map1 (pl); 2222 draw_client_map1 (pl);
2275 return;
2276 }
2277
2278 if (pl->invisible & (pl->invisible < 50 ? 4 : 1))
2279 {
2280 esrv_map_setbelow (&pl->contr->socket, pl->contr->socket.mapx / 2, pl->contr->socket.mapy / 2, pl->face->number, &newmap);
2281 }
2282
2283 /* j and i are the y and x coordinates of the real map (which is
2284 * basically some number of spaces around the player)
2285 * ax and ay are values from within the viewport (ie, 0, 0 is upper
2286 * left corner) and are thus disconnected from the map values.
2287 * Subtract 1 from the max values so that we properly handle cases where
2288 * player has specified an even map. Otherwise, we try to send them too
2289 * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually
2290 * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is
2291 * odd, this still works fine.
2292 */
2293 ay = 0;
2294 for (j = pl->y - pl->contr->socket.mapy / 2; j <= pl->y + (pl->contr->socket.mapy - 1) / 2; j++, ay++)
2295 {
2296 ax = 0;
2297 for (i = pl->x - pl->contr->socket.mapx / 2; i <= pl->x + (pl->contr->socket.mapx - 1) / 2; i++, ax++)
2298 {
2299
2300 d = pl->contr->blocked_los[ax][ay];
2301 /* note the out_of_map and d>3 checks are both within the same
2302 * negation check.
2303 */
2304 nx = i;
2305 ny = j;
2306 m = get_map_from_coord (pm, &nx, &ny);
2307 if (m && d < 4)
2308 {
2309 face = GET_MAP_FACE (m, nx, ny, 0);
2310 floor2 = GET_MAP_FACE (m, nx, ny, 1);
2311 floor = GET_MAP_FACE (m, nx, ny, 2);
2312
2313 /* If all is blank, send a blank face. */
2314 if ((!face || face == blank_face) && (!floor2 || floor2 == blank_face) && (!floor || floor == blank_face))
2315 {
2316 esrv_map_setbelow (&pl->contr->socket, ax, ay, blank_face->number, &newmap);
2317 }
2318 else
2319 { /* actually have something interesting */
2320 /* send the darkness mask, if any. */
2321 if (d && pl->contr->socket.darkness)
2322 esrv_map_setbelow (&pl->contr->socket, ax, ay, dark_faces[d - 1]->number, &newmap);
2323
2324 if (face && face != blank_face)
2325 esrv_map_setbelow (&pl->contr->socket, ax, ay, face->number, &newmap);
2326 if (floor2 && floor2 != blank_face)
2327 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor2->number, &newmap);
2328 if (floor && floor != blank_face)
2329 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap);
2330 }
2331 } /* Is a valid space */
2332 }
2333 }
2334
2335 esrv_map_doneredraw (&pl->contr->socket, &newmap);
2336
2337 check_map_change (pl->contr);
2338} 2223}
2339 2224
2340 2225
2341/*****************************************************************************/ 2226/*****************************************************************************/
2342 2227
2358 * the params - we always send the same info no matter what. 2243 * the params - we always send the same info no matter what.
2359 */ 2244 */
2360void 2245void
2361send_skill_info (NewSocket *ns, char *params) 2246send_skill_info (NewSocket *ns, char *params)
2362{ 2247{
2363 SockList sl (MAXSOCKBUF); 2248 packet sl;
2364 sl << "replyinfo skill_info\n"; 2249 sl << "replyinfo skill_info\n";
2365 2250
2366 for (int i = 1; i < NUM_SKILLS; i++) 2251 for (int i = 1; i < NUM_SKILLS; i++)
2367 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 2252 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]);
2368 2253
2369 if (sl.len >= MAXSOCKBUF) 2254 if (sl.length () >= MAXSOCKBUF)
2370 { 2255 {
2371 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2256 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2372 fatal (0); 2257 fatal (0);
2373 } 2258 }
2374 2259
2375 Send_With_Handling (ns, &sl); 2260 Send_With_Handling (ns, &sl);
2376 sl.free ();
2377} 2261}
2378 2262
2379/** 2263/**
2380 * This sends the spell path to name mapping. We ignore 2264 * This sends the spell path to name mapping. We ignore
2381 * the params - we always send the same info no matter what. 2265 * the params - we always send the same info no matter what.
2382 */ 2266 */
2383void 2267void
2384send_spell_paths (NewSocket * ns, char *params) 2268send_spell_paths (NewSocket * ns, char *params)
2385{ 2269{
2386 SockList sl (MAXSOCKBUF); 2270 packet sl;
2387 2271
2388 sl << "replyinfo spell_paths\n"; 2272 sl << "replyinfo spell_paths\n";
2389 2273
2390 for (int i = 0; i < NRSPELLPATHS; i++) 2274 for (int i = 0; i < NRSPELLPATHS; i++)
2391 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); 2275 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
2392 2276
2393 if (sl.len >= MAXSOCKBUF) 2277 if (sl.length () >= MAXSOCKBUF)
2394 { 2278 {
2395 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2396 fatal (0); 2280 fatal (0);
2397 } 2281 }
2398 2282
2399 Send_With_Handling (ns, &sl); 2283 Send_With_Handling (ns, &sl);
2400 sl.free ();
2401} 2284}
2402 2285
2403/** 2286/**
2404 * This looks for any spells the player may have that have changed their stats. 2287 * This looks for any spells the player may have that have changed their stats.
2405 * it then sends an updspell packet for each spell that has changed in this way 2288 * it then sends an updspell packet for each spell that has changed in this way
2435 flags |= UPD_SP_DAMAGE; 2318 flags |= UPD_SP_DAMAGE;
2436 } 2319 }
2437 2320
2438 if (flags) 2321 if (flags)
2439 { 2322 {
2440 SockList sl (MAXSOCKBUF); 2323 packet sl;
2441 2324
2442 sl << "updspell " 2325 sl << "updspell "
2443 << uint8 (flags) 2326 << uint8 (flags)
2444 << uint32 (spell->count); 2327 << uint32 (spell->count);
2445 2328
2446 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2447 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2448 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2449 2332
2450 Send_With_Handling (&pl->socket, &sl); 2333 Send_With_Handling (&pl->socket, &sl);
2451 sl.free ();
2452 } 2334 }
2453 } 2335 }
2454 } 2336 }
2455} 2337}
2456 2338
2464 { 2346 {
2465 LOG (llevError, "Invalid call to esrv_remove_spell"); 2347 LOG (llevError, "Invalid call to esrv_remove_spell");
2466 return; 2348 return;
2467 } 2349 }
2468 2350
2469 SockList sl (MAXSOCKBUF); 2351 packet sl;
2470 2352
2471 sl << "delspell " 2353 sl << "delspell "
2472 << uint32 (spell->count); 2354 << uint32 (spell->count);
2473 2355
2474 Send_With_Handling (&pl->socket, &sl); 2356 Send_With_Handling (&pl->socket, &sl);
2475 sl.free ();
2476} 2357}
2477 2358
2478/* appends the spell *spell to the Socklist we will send the data to. */ 2359/* appends the spell *spell to the Socklist we will send the data to. */
2479static void 2360static void
2480append_spell (player *pl, SockList &sl, object *spell) 2361append_spell (player *pl, packet &sl, object *spell)
2481{ 2362{
2482 int len, i, skill = 0; 2363 int len, i, skill = 0;
2483 2364
2484 if (!(spell->name)) 2365 if (!(spell->name))
2485 { 2366 {
2531 } 2412 }
2532 2413
2533 if (!pl->socket.monitor_spells) 2414 if (!pl->socket.monitor_spells)
2534 return; 2415 return;
2535 2416
2536 SockList sl (MAXSOCKBUF); 2417 packet sl;
2537 2418
2538 sl << "addspell "; 2419 sl << "addspell ";
2539 2420
2540 if (!spell) 2421 if (!spell)
2541 { 2422 {
2555 * like it will fix this 2436 * like it will fix this
2556 */ 2437 */
2557 if (spell->type != SPELL) 2438 if (spell->type != SPELL)
2558 continue; 2439 continue;
2559 2440
2560 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2441 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2561 { 2442 {
2562 Send_With_Handling (&pl->socket, &sl); 2443 Send_With_Handling (&pl->socket, &sl);
2563 strcpy ((char *) sl.buf, "addspell "); 2444
2564 sl.len = strlen ((char *) sl.buf); 2445 sl.reset ();
2446 sl << "addspell ";
2565 } 2447 }
2566 2448
2567 append_spell (pl, sl, spell); 2449 append_spell (pl, sl, spell);
2568 } 2450 }
2569 } 2451 }
2582 } 2464 }
2583 2465
2584 /* finally, we can send the packet */ 2466 /* finally, we can send the packet */
2585 Send_With_Handling (&pl->socket, &sl); 2467 Send_With_Handling (&pl->socket, &sl);
2586 2468
2587 sl.free ();
2588} 2469}
2589 2470

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines