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.4 by root, Sun Apr 16 04:36:34 2006 UTC vs.
Revision 1.7 by root, Fri Apr 21 05:13:28 2006 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * static char *rcsid_init_c =
3 * "$Id: request.c,v 1.4 2006/04/16 04:36:34 root Exp $"; 3 * "$Id: request.c,v 1.7 2006/04/21 05:13:28 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 - pl->socket.mapx / 2, ob->y - pl->socket.mapy / 2, 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{
510 short packet; 586 short packet;
511 char command[MAX_BUF]; 587 char command[MAX_BUF];
512 SockList sl; 588 SockList sl;
513 589
514 if (len < 7) { 590 if (len < 7) {
515 LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); 591 LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf);
516 return; 592 return;
517 } 593 }
518 594
519 packet = GetShort_String(buf); 595 packet = GetShort_String(buf);
520 repeat = GetInt_String(buf+2); 596 repeat = GetInt_String(buf+2);
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 }
792 pl->socket.current_map = 0;
716} 793}
717 794
718 795
719 796
720/** 797/**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines