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.2 by root, Sat Apr 15 22:38:31 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.2 2006/04/15 22:38:31 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
120 if (pl->socket.current_map != ob->map) 120 if (pl->socket.current_map != ob->map)
121 { 121 {
122 pl->socket.current_map = ob->map; 122 pl->socket.current_map = ob->map;
123 123
124 if (ob->map && ob->map->path [0]) 124 if (ob->map && ob->map->path [0])
125 {
126 int flags = 0;
127
128 if (ob->map->tile_path [0]) flags |= 1;
129 if (ob->map->tile_path [1]) flags |= 2;
130 if (ob->map->tile_path [2]) flags |= 4;
131 if (ob->map->tile_path [3]) flags |= 8;
132
125 snprintf (buf, MAX_BUF, "mapinfo current %d %d %d %d %s", 133 snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s",
126 ob->x, ob->y, 134 flags, pl->socket.mapx / 2 - ob->x, pl->socket.mapy / 2 - ob->y,
127 ob->map->width, ob->map->height, ob->map->path); 135 ob->map->width, ob->map->height, ob->map->path);
136 }
128 else 137 else
129 snprintf (buf, MAX_BUF, "mapinfo current"); 138 snprintf (buf, MAX_BUF, "mapinfo current");
130 139
131 Write_String_To_Socket (&pl->socket, buf, strlen (buf)); 140 Write_String_To_Socket (&pl->socket, buf, strlen (buf));
132 } 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));
133} 218}
134 219
135/** This is the Setup cmd - easy first implementation */ 220/** This is the Setup cmd - easy first implementation */
136void SetUp(char *buf, int len, NewSocket *ns) 221void SetUp(char *buf, int len, NewSocket *ns)
137{ 222{
702{ 787{
703 if( pl->socket.newmapcmd == 1) { 788 if( pl->socket.newmapcmd == 1) {
704 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 789 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
705 Write_String_To_Socket( &pl->socket, "newmap", 6); 790 Write_String_To_Socket( &pl->socket, "newmap", 6);
706 } 791 }
707 check_map_change (pl);
708} 792}
709 793
710 794
711 795
712/** 796/**
1467 uint16 mask,emask; 1551 uint16 mask,emask;
1468 uint8 eentrysize; 1552 uint8 eentrysize;
1469 uint16 ewhatstart,ewhatflag; 1553 uint16 ewhatstart,ewhatflag;
1470 uint8 extendedinfos; 1554 uint8 extendedinfos;
1471 mapstruct *m; 1555 mapstruct *m;
1472
1473 check_map_change (pl->contr);
1474 1556
1475 sl.buf=malloc(MAXSOCKBUF); 1557 sl.buf=malloc(MAXSOCKBUF);
1476 if (pl->contr->socket.mapmode == Map1Cmd) 1558 if (pl->contr->socket.mapmode == Map1Cmd)
1477 strcpy((char*)sl.buf,"map1 "); 1559 strcpy((char*)sl.buf,"map1 ");
1478 else 1560 else
1759 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1841 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1760 Send_With_Handling(&pl->contr->socket, &sl); 1842 Send_With_Handling(&pl->contr->socket, &sl);
1761 pl->contr->socket.sent_scroll = 0; 1843 pl->contr->socket.sent_scroll = 0;
1762 } 1844 }
1763 free(sl.buf); 1845 free(sl.buf);
1846
1847 check_map_change (pl->contr);
1764} 1848}
1765 1849
1766/** 1850/**
1767 * Draws client map. 1851 * Draws client map.
1768 */ 1852 */
1881 } 1965 }
1882 } /* Is a valid space */ 1966 } /* Is a valid space */
1883 } 1967 }
1884 } 1968 }
1885 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1969 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1970
1971 check_map_change (pl->contr);
1886} 1972}
1887 1973
1888 1974
1889void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1975void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1890{ 1976{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines