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.24 by root, Tue Sep 19 22:05:55 2006 UTC vs.
Revision 1.26 by pippijn, Mon Dec 11 19:46:47 2006 UTC

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
1460map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) 1452map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count)
1461{ 1453{
1462 cell->faces[0] = face0; 1454 cell->faces[0] = face0;
1463 cell->faces[1] = face1; 1455 cell->faces[1] = face1;
1464 cell->faces[2] = face2; 1456 cell->faces[2] = face2;
1465 cell->count = count; 1457 cell->count = count;
1466 cell->stat_hp = 0; 1458 cell->stat_hp = 0;
1459 cell->flags = 0;
1467 cell->player = 0; 1460 cell->player = 0;
1468} 1461}
1469 1462
1470#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) 1463#define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y)
1471#define MAX_LAYERS 3 1464#define MAX_LAYERS 3
1472 1465
1868 strcpy ((char *) sl.buf, "map1 "); 1861 strcpy ((char *) sl.buf, "map1 ");
1869 else 1862 else
1870 strcpy ((char *) sl.buf, "map1a "); 1863 strcpy ((char *) sl.buf, "map1a ");
1871 sl.len = strlen ((char *) sl.buf); 1864 sl.len = strlen ((char *) sl.buf);
1872 startlen = sl.len; 1865 startlen = sl.len;
1866
1873 /*Extendedmapinfo structure initialisation */ 1867 /*Extendedmapinfo structure initialisation */
1874 if (socket.ext_mapinfos) 1868 if (socket.ext_mapinfos)
1875 { 1869 {
1876 esl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1870 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1877 strcpy ((char *) esl.buf, "mapextended "); 1871 strcpy ((char *) esl.buf, "mapextended ");
1878 esl.len = strlen ((char *) esl.buf); 1872 esl.len = strlen ((char *) esl.buf);
1879 extendedinfos = EMI_NOREDRAW; 1873 extendedinfos = EMI_NOREDRAW;
1874
1880 if (socket.EMI_smooth) 1875 if (socket.EMI_smooth)
1881 extendedinfos |= EMI_SMOOTH; 1876 extendedinfos |= EMI_SMOOTH;
1877
1882 ewhatstart = esl.len; 1878 ewhatstart = esl.len;
1883 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1879 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1884 could need to be taken away */ 1880 could need to be taken away */
1885 SockList_AddChar (&esl, extendedinfos); 1881 SockList_AddChar (&esl, extendedinfos);
1886 eentrysize = getExtendedMapInfoSize (&socket); 1882 eentrysize = getExtendedMapInfoSize (&socket);
1892 /* suppress compiler warnings */ 1888 /* suppress compiler warnings */
1893 ewhatstart = 0; 1889 ewhatstart = 0;
1894 ewhatflag = 0; 1890 ewhatflag = 0;
1895 estartlen = 0; 1891 estartlen = 0;
1896 } 1892 }
1893
1897 /* Init data to zero */ 1894 /* Init data to zero */
1898 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS); 1895 memset (heads, 0, sizeof (object *) * MAX_HEAD_POS * MAX_HEAD_POS * MAX_LAYERS);
1899 1896
1900 /* x,y are the real map locations. ax, ay are viewport relative 1897 /* x,y are the real map locations. ax, ay are viewport relative
1901 * locations. 1898 * locations.
1905 /* We could do this logic as conditionals in the if statement, 1902 /* We could do this logic as conditionals in the if statement,
1906 * but that started to get a bit messy to look at. 1903 * but that started to get a bit messy to look at.
1907 */ 1904 */
1908 max_x = pl->x + (socket.mapx + 1) / 2; 1905 max_x = pl->x + (socket.mapx + 1) / 2;
1909 max_y = pl->y + (socket.mapy + 1) / 2; 1906 max_y = pl->y + (socket.mapy + 1) / 2;
1907
1910 if (socket.mapmode == Map1aCmd) 1908 if (socket.mapmode == Map1aCmd)
1911 { 1909 {
1912 max_x += MAX_HEAD_OFFSET; 1910 max_x += MAX_HEAD_OFFSET;
1913 max_y += MAX_HEAD_OFFSET; 1911 max_y += MAX_HEAD_OFFSET;
1914 } 1912 }
1947 * with no faces tells the client to blank out the 1945 * with no faces tells the client to blank out the
1948 * space. 1946 * space.
1949 */ 1947 */
1950 got_one = 0; 1948 got_one = 0;
1951 for (i = oldlen + 2; i < sl.len; i++) 1949 for (i = oldlen + 2; i < sl.len; i++)
1952 {
1953 if (sl.buf[i]) 1950 if (sl.buf[i])
1954 got_one = 1; 1951 got_one = 1;
1955 }
1956 1952
1957 if (got_one && (mask & 0xf)) 1953 if (got_one && (mask & 0xf))
1958 {
1959 sl.buf[oldlen + 1] = mask & 0xff; 1954 sl.buf[oldlen + 1] = mask & 0xff;
1960 }
1961 else 1955 else
1962 { /*either all faces blank, either no face at all */ 1956 { /*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 */ 1957 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1964 sl.len = oldlen + 2; 1958 sl.len = oldlen + 2;
1965 else 1959 else
1966 sl.len = oldlen; 1960 sl.len = oldlen;
1967 } 1961 }
1962
1968 /*What concerns extendinfos, nothing to be done for now 1963 /*What concerns extendinfos, nothing to be done for now
1969 * (perhaps effects layer later) 1964 * (perhaps effects layer later)
1970 */ 1965 */
1971 continue; /* don't do processing below */ 1966 continue; /* don't do processing below */
1972 } 1967 }
1973 1968
1974 MapCell & lastcell = socket.lastmap.cells[ax][ay]; 1969 MapCell &lastcell = socket.lastmap.cells[ax][ay];
1975 1970
1976 d = pl->contr->blocked_los[ax][ay]; 1971 d = pl->contr->blocked_los[ax][ay];
1977 1972
1978 /* If the coordinates are not valid, or it is too dark to see, 1973 /* If the coordinates are not valid, or it is too dark to see,
1979 * we tell the client as such 1974 * we tell the client as such
1980 */ 1975 */
1981 nx = x; 1976 nx = x;
1982 ny = y; 1977 ny = y;
1983 m = get_map_from_coord (pl->map, &nx, &ny); 1978 m = get_map_from_coord (pl->map, &nx, &ny);
1979
1984 if (!m) 1980 if (!m)
1985 { 1981 {
1986 /* space is out of map. Update space and clear values 1982 /* space is out of map. Update space and clear values
1987 * if this hasn't already been done. If the space is out 1983 * if this hasn't already been done. If the space is out
1988 * of the map, it shouldn't have a head 1984 * of the map, it shouldn't have a head
2002 */ 1998 */
2003 1999
2004 oldlen = sl.len; 2000 oldlen = sl.len;
2005 2001
2006 SockList_AddShort (&sl, mask); 2002 SockList_AddShort (&sl, mask);
2003
2007 if (lastcell.count != -1) 2004 if (lastcell.count != -1)
2008 need_send = 1; 2005 need_send = 1;
2006
2009 count = -1; 2007 count = -1;
2010 2008
2011 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 2009 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2012 { 2010 {
2013 /* Now check to see if any heads need to be sent */ 2011 /* Now check to see if any heads need to be sent */
2018 mask |= 0x2; 2016 mask |= 0x2;
2019 if (check_head (sl, socket, ax, ay, 0)) 2017 if (check_head (sl, socket, ax, ay, 0))
2020 mask |= 0x1; 2018 mask |= 0x1;
2021 2019
2022 lastcell.count = count; 2020 lastcell.count = count;
2023
2024 } 2021 }
2025 else 2022 else
2026 { 2023 {
2027 struct MapCell *cell = &lastcell;
2028
2029 /* properly clear a previously sent big face */ 2024 /* properly clear a previously sent big face */
2030 if (cell->faces[0] != 0 || cell->faces[1] != 0 || cell->faces[2] != 0) 2025 if (lastcell.faces[0] != 0 || lastcell.faces[1] != 0 || lastcell.faces[2] != 0
2026 || lastcell.stat_hp || lastcell.flags || lastcell.player)
2031 need_send = 1; 2027 need_send = 1;
2028
2032 map_clearcell (&lastcell, 0, 0, 0, count); 2029 map_clearcell (&lastcell, 0, 0, 0, count);
2033 } 2030 }
2034 2031
2035 if ((mask & 0xf) || need_send) 2032 if ((mask & 0xf) || need_send)
2036 {
2037 sl.buf[oldlen + 1] = mask & 0xff; 2033 sl.buf[oldlen + 1] = mask & 0xff;
2038 }
2039 else 2034 else
2040 {
2041 sl.len = oldlen; 2035 sl.len = oldlen;
2042 }
2043 } 2036 }
2044 else 2037 else
2045 { 2038 {
2046 /* In this block, the space is visible or there are head objects 2039 /* In this block, the space is visible or there are head objects
2047 * we need to send. 2040 * we need to send.
2178 { 2171 {
2179 if (lastcell.faces[0] != pl->face->number) 2172 if (lastcell.faces[0] != pl->face->number)
2180 { 2173 {
2181 lastcell.faces[0] = pl->face->number; 2174 lastcell.faces[0] = pl->face->number;
2182 mask |= 0x1; 2175 mask |= 0x1;
2176
2183 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2177 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2184 esrv_send_face (&socket, pl->face->number, 0); 2178 esrv_send_face (&socket, pl->face->number, 0);
2179
2185 SockList_AddShort (&sl, pl->face->number); 2180 SockList_AddShort (&sl, pl->face->number);
2186 } 2181 }
2187 } 2182 }
2188 /* Top face */
2189 else 2183 else
2190 { 2184 {
2185 /* Top face */
2191 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2186 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0))
2192 mask |= 0x1; 2187 mask |= 0x1;
2188
2193 if (socket.EMI_smooth) 2189 if (socket.EMI_smooth)
2194 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2190 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0))
2195 {
2196 emask |= 0x1; 2191 emask |= 0x1;
2197 }
2198 } 2192 }
2193
2199 /* Check to see if we are in fact sending anything for this 2194 /* Check to see if we are in fact sending anything for this
2200 * space by checking the mask. If so, update the mask. 2195 * space by checking the mask. If so, update the mask.
2201 * if not, reset the len to that from before adding the mask 2196 * if not, reset the len to that from before adding the mask
2202 * value, so we don't send those bits. 2197 * value, so we don't send those bits.
2203 */ 2198 */
2204 if (mask & 0xf) 2199 if (mask & 0xf)
2205 {
2206 sl.buf[oldlen + 1] = mask & 0xff; 2200 sl.buf[oldlen + 1] = mask & 0xff;
2207 }
2208 else 2201 else
2209 {
2210 sl.len = oldlen; 2202 sl.len = oldlen;
2211 } 2203
2212 if (emask & 0xf) 2204 if (emask & 0xf)
2213 {
2214 esl.buf[eoldlen + 1] = emask & 0xff; 2205 esl.buf[eoldlen + 1] = emask & 0xff;
2215 }
2216 else 2206 else
2217 {
2218 esl.len = eoldlen; 2207 esl.len = eoldlen;
2219 }
2220 } /* else this is a viewable space */ 2208 } /* else this is a viewable space */
2221 } /* for x loop */ 2209 } /* for x loop */
2222 } /* for y loop */ 2210 } /* for y loop */
2223 2211
2224 /* Verify that we in fact do need to send this */ 2212 /* Verify that we in fact do need to send this */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines