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.3 by root, Sun Apr 16 02:56:46 2006 UTC vs.
Revision 1.5 by root, Mon Apr 17 06:11:41 2006 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * static char *rcsid_init_c =
3 * "$Id: request.c,v 1.3 2006/04/16 02:56:46 root Exp $"; 3 * "$Id: request.c,v 1.5 2006/04/17 06:11:41 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
123 123
124 if (ob->map && ob->map->path [0]) 124 if (ob->map && ob->map->path [0])
125 { 125 {
126 int flags = 0; 126 int flags = 0;
127 127
128 if (ob->map->tile_map [0]) flags |= 1; 128 if (ob->map->tile_path [0]) flags |= 1;
129 if (ob->map->tile_map [1]) flags |= 2; 129 if (ob->map->tile_path [1]) flags |= 2;
130 if (ob->map->tile_map [2]) flags |= 4; 130 if (ob->map->tile_path [2]) flags |= 4;
131 if (ob->map->tile_map [3]) flags |= 8; 131 if (ob->map->tile_path [3]) flags |= 8;
132 132
133 snprintf (buf, MAX_BUF, "mapinfo current %d %d %d %d %d %s", 133 snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s",
134 flags, ob->x, ob->y, 134 flags, pl->socket.mapx / 2 - ob->x, pl->socket.mapy / 2 - ob->y,
135 ob->map->width, ob->map->height, ob->map->path); 135 ob->map->width, ob->map->height, ob->map->path);
136 } 136 }
137 else 137 else
138 snprintf (buf, MAX_BUF, "mapinfo current"); 138 snprintf (buf, MAX_BUF, "mapinfo current");
139 139
140 Write_String_To_Socket (&pl->socket, buf, strlen (buf)); 140 Write_String_To_Socket (&pl->socket, buf, strlen (buf));
141 } 141 }
142}
143
144void MapInfoCmd (char *buf, int len, player *pl)
145{
146 // <mapinfo tag spatial tile-path
147 // >mapinfo tag spatial flags x y w h hash
148
149 char bigbuf[MAX_BUF], *cp, *token;
150
151 token = buf;
152 // copy token
153 if (!(buf = strchr (buf, ' ')))
154 return;
155
156 *buf++ = 0;
157
158 if (!strncmp (buf, "spatial ", 8))
159 {
160 buf += 8;
161
162 // initial map and its origin
163 mapstruct *map = pl->ob->map;
164 sint16 dx, dy;
165 int mapx = pl->socket.mapx / 2 - pl->ob->x;
166 int mapy = pl->socket.mapy / 2 - pl->ob->y;
167 int max_distance = 8; // limit maximum path length to something generous
168
169 while (*buf && map && max_distance)
170 {
171 int dir = *buf++;
172
173 switch (dir)
174 {
175 case '1':
176 dx = 0; dy = -1; map = get_map_from_coord (map, &dx, &dy);
177 map && (mapy -= map->height);
178 break;
179 case '2':
180 mapx += map->width;
181 dx = map->width; dy = 0; map = get_map_from_coord (map, &dx, &dy);
182 break;
183 case '3':
184 mapy += map->height;
185 dx = 0; dy = map->height; map = get_map_from_coord (map, &dx, &dy);
186 break;
187 case '4':
188 dx = -1; dy = 0; map = get_map_from_coord (map, &dx, &dy);
189 map && (mapx -= map->width);
190 break;
191 }
192
193 --max_distance;
194 }
195
196 if (!max_distance)
197 snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token);
198 else if (map && map->path [0])
199 {
200 int flags = 0;
201
202 if (map->tile_path [0]) flags |= 1;
203 if (map->tile_path [1]) flags |= 2;
204 if (map->tile_path [2]) flags |= 4;
205 if (map->tile_path [3]) flags |= 8;
206
207 snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s",
208 token, flags, mapx, mapy,
209 map->width, map->height, map->path);
210 }
211 else
212 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
213 }
214 else
215 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
216
217 Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf));
142} 218}
143 219
144/** This is the Setup cmd - easy first implementation */ 220/** This is the Setup cmd - easy first implementation */
145void SetUp(char *buf, int len, NewSocket *ns) 221void SetUp(char *buf, int len, NewSocket *ns)
146{ 222{
711{ 787{
712 if( pl->socket.newmapcmd == 1) { 788 if( pl->socket.newmapcmd == 1) {
713 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 789 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
714 Write_String_To_Socket( &pl->socket, "newmap", 6); 790 Write_String_To_Socket( &pl->socket, "newmap", 6);
715 } 791 }
716 check_map_change (pl);
717} 792}
718 793
719 794
720 795
721/** 796/**
1476 uint16 mask,emask; 1551 uint16 mask,emask;
1477 uint8 eentrysize; 1552 uint8 eentrysize;
1478 uint16 ewhatstart,ewhatflag; 1553 uint16 ewhatstart,ewhatflag;
1479 uint8 extendedinfos; 1554 uint8 extendedinfos;
1480 mapstruct *m; 1555 mapstruct *m;
1481
1482 check_map_change (pl->contr);
1483 1556
1484 sl.buf=malloc(MAXSOCKBUF); 1557 sl.buf=malloc(MAXSOCKBUF);
1485 if (pl->contr->socket.mapmode == Map1Cmd) 1558 if (pl->contr->socket.mapmode == Map1Cmd)
1486 strcpy((char*)sl.buf,"map1 "); 1559 strcpy((char*)sl.buf,"map1 ");
1487 else 1560 else
1768 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1841 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1769 Send_With_Handling(&pl->contr->socket, &sl); 1842 Send_With_Handling(&pl->contr->socket, &sl);
1770 pl->contr->socket.sent_scroll = 0; 1843 pl->contr->socket.sent_scroll = 0;
1771 } 1844 }
1772 free(sl.buf); 1845 free(sl.buf);
1846
1847 check_map_change (pl->contr);
1773} 1848}
1774 1849
1775/** 1850/**
1776 * Draws client map. 1851 * Draws client map.
1777 */ 1852 */
1890 } 1965 }
1891 } /* Is a valid space */ 1966 } /* Is a valid space */
1892 } 1967 }
1893 } 1968 }
1894 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1969 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1970
1971 check_map_change (pl->contr);
1895} 1972}
1896 1973
1897 1974
1898void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1975void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1899{ 1976{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines