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.10 2006/06/19 10:15:44 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 | |
|
|
144 | void ExtCmd (char *buf, int len, player *pl) |
|
|
145 | { |
|
|
146 | execute_global_event (EVENT_EXTCMD, pl, buf, len); |
|
|
147 | } |
|
|
148 | |
|
|
149 | void MapInfoCmd (char *buf, int len, player *pl) |
|
|
150 | { |
|
|
151 | // <mapinfo tag spatial tile-path |
|
|
152 | // >mapinfo tag spatial flags x y w h hash |
|
|
153 | |
|
|
154 | char bigbuf[MAX_BUF], *cp, *token; |
|
|
155 | |
|
|
156 | token = buf; |
|
|
157 | // copy token |
|
|
158 | if (!(buf = strchr (buf, ' '))) |
|
|
159 | return; |
|
|
160 | |
|
|
161 | *buf++ = 0; |
|
|
162 | |
|
|
163 | if (!strncmp (buf, "spatial ", 8)) |
|
|
164 | { |
|
|
165 | buf += 8; |
|
|
166 | |
|
|
167 | // initial map and its origin |
|
|
168 | mapstruct *map = pl->ob->map; |
|
|
169 | sint16 dx, dy; |
|
|
170 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
|
|
171 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
|
|
172 | int max_distance = 8; // limit maximum path length to something generous |
|
|
173 | |
|
|
174 | while (*buf && map && max_distance) |
|
|
175 | { |
|
|
176 | int dir = *buf++; |
|
|
177 | |
|
|
178 | switch (dir) |
|
|
179 | { |
|
|
180 | case '1': |
|
|
181 | dx = 0; dy = -1; map = get_map_from_coord (map, &dx, &dy); |
|
|
182 | map && (mapy -= map->height); |
|
|
183 | break; |
|
|
184 | case '2': |
|
|
185 | mapx += map->width; |
|
|
186 | dx = map->width; dy = 0; map = get_map_from_coord (map, &dx, &dy); |
|
|
187 | break; |
|
|
188 | case '3': |
|
|
189 | mapy += map->height; |
|
|
190 | dx = 0; dy = map->height; map = get_map_from_coord (map, &dx, &dy); |
|
|
191 | break; |
|
|
192 | case '4': |
|
|
193 | dx = -1; dy = 0; map = get_map_from_coord (map, &dx, &dy); |
|
|
194 | map && (mapx -= map->width); |
|
|
195 | break; |
|
|
196 | } |
|
|
197 | |
|
|
198 | --max_distance; |
|
|
199 | } |
|
|
200 | |
|
|
201 | if (!max_distance) |
|
|
202 | snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token); |
|
|
203 | else if (map && map->path [0]) |
|
|
204 | { |
|
|
205 | int flags = 0; |
|
|
206 | |
|
|
207 | if (map->tile_path [0]) flags |= 1; |
|
|
208 | if (map->tile_path [1]) flags |= 2; |
|
|
209 | if (map->tile_path [2]) flags |= 4; |
|
|
210 | if (map->tile_path [3]) flags |= 8; |
|
|
211 | |
|
|
212 | snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", |
|
|
213 | token, flags, mapx, mapy, |
|
|
214 | map->width, map->height, map->path); |
|
|
215 | } |
|
|
216 | else |
|
|
217 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
|
|
218 | } |
|
|
219 | else |
|
|
220 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
|
|
221 | |
|
|
222 | Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); |
142 | } |
223 | } |
143 | |
224 | |
144 | /** This is the Setup cmd - easy first implementation */ |
225 | /** This is the Setup cmd - easy first implementation */ |
145 | void SetUp(char *buf, int len, NewSocket *ns) |
226 | void SetUp(char *buf, int len, NewSocket *ns) |
146 | { |
227 | { |
… | |
… | |
208 | // } else if (!strcmp(cmd,"plugincmd")) { |
289 | // } else if (!strcmp(cmd,"plugincmd")) { |
209 | // ns->plugincmd = atoi(param); |
290 | // ns->plugincmd = atoi(param); |
210 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
291 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
211 | } else if (!strcmp(cmd,"mapinfocmd")) { |
292 | } else if (!strcmp(cmd,"mapinfocmd")) { |
212 | ns->mapinfocmd = atoi(param); |
293 | ns->mapinfocmd = atoi(param); |
213 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
294 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
|
|
295 | } else if (!strcmp(cmd,"extcmd")) { |
|
|
296 | ns->extcmd = atoi(param); |
|
|
297 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
214 | } else if (!strcmp(cmd,"facecache")) { |
298 | } else if (!strcmp(cmd,"facecache")) { |
215 | ns->facecache = atoi(param); |
299 | ns->facecache = atoi(param); |
216 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
300 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
217 | } else if (!strcmp(cmd,"faceset")) { |
301 | } else if (!strcmp(cmd,"faceset")) { |
218 | char tmpbuf[20]; |
302 | char tmpbuf[20]; |
… | |
… | |
510 | short packet; |
594 | short packet; |
511 | char command[MAX_BUF]; |
595 | char command[MAX_BUF]; |
512 | SockList sl; |
596 | SockList sl; |
513 | |
597 | |
514 | if (len < 7) { |
598 | if (len < 7) { |
515 | LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); |
599 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
516 | return; |
600 | return; |
517 | } |
601 | } |
518 | |
602 | |
519 | packet = GetShort_String(buf); |
603 | packet = GetShort_String(buf); |
520 | repeat = GetInt_String(buf+2); |
604 | repeat = GetInt_String(buf+2); |
… | |
… | |
711 | { |
795 | { |
712 | if( pl->socket.newmapcmd == 1) { |
796 | if( pl->socket.newmapcmd == 1) { |
713 | memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); |
797 | memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); |
714 | Write_String_To_Socket( &pl->socket, "newmap", 6); |
798 | Write_String_To_Socket( &pl->socket, "newmap", 6); |
715 | } |
799 | } |
|
|
800 | pl->socket.current_map = 0; |
716 | } |
801 | } |
717 | |
802 | |
718 | |
803 | |
719 | |
804 | |
720 | /** |
805 | /** |
… | |
… | |
1526 | |
1611 | |
1527 | for(y=pl->y-pl->contr->socket.mapy/2; y<max_y; y++,ay++) { |
1612 | for(y=pl->y-pl->contr->socket.mapy/2; y<max_y; y++,ay++) { |
1528 | ax=0; |
1613 | ax=0; |
1529 | for(x=pl->x-pl->contr->socket.mapx/2;x<max_x;x++,ax++) { |
1614 | for(x=pl->x-pl->contr->socket.mapx/2;x<max_x;x++,ax++) { |
1530 | |
1615 | |
1531 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
|
|
1532 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1616 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1533 | |
1617 | |
1534 | /* If this space is out of the normal viewable area, we only check |
1618 | /* If this space is out of the normal viewable area, we only check |
1535 | * the heads value ax or ay will only be greater than what |
1619 | * the heads value ax or ay will only be greater than what |
1536 | * the client wants if using the map1a command - this is because |
1620 | * the client wants if using the map1a command - this is because |
1537 | * if the map1a command is not used, max_x and max_y will be |
1621 | * if the map1a command is not used, max_x and max_y will be |
… | |
… | |
1975 | for (i=1; i< NUM_SKILLS; i++) { |
2059 | for (i=1; i< NUM_SKILLS; i++) { |
1976 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2060 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
1977 | skill_names[i]); |
2061 | skill_names[i]); |
1978 | } |
2062 | } |
1979 | sl.len = strlen((char*)sl.buf); |
2063 | sl.len = strlen((char*)sl.buf); |
1980 | if (sl.len > MAXSOCKBUF) { |
2064 | if (sl.len >= MAXSOCKBUF) { |
1981 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2065 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
1982 | fatal(0); |
2066 | fatal(0); |
1983 | } |
2067 | } |
1984 | Send_With_Handling(ns, &sl); |
2068 | Send_With_Handling(ns, &sl); |
1985 | free(sl.buf); |
2069 | free(sl.buf); |
… | |
… | |
1996 | sl.buf = malloc(MAXSOCKBUF); |
2080 | sl.buf = malloc(MAXSOCKBUF); |
1997 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2081 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
1998 | for(i=0; i<NRSPELLPATHS; i++) |
2082 | for(i=0; i<NRSPELLPATHS; i++) |
1999 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2083 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2000 | sl.len = strlen((char*)sl.buf); |
2084 | sl.len = strlen((char*)sl.buf); |
2001 | if (sl.len > MAXSOCKBUF) { |
2085 | if (sl.len >= MAXSOCKBUF) { |
2002 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2086 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2003 | fatal(0); |
2087 | fatal(0); |
2004 | } |
2088 | } |
2005 | Send_With_Handling(ns, &sl); |
2089 | Send_With_Handling(ns, &sl); |
2006 | free(sl.buf); |
2090 | free(sl.buf); |
… | |
… | |
2140 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2224 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2141 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2225 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2142 | * like it will fix this |
2226 | * like it will fix this |
2143 | */ |
2227 | */ |
2144 | if (spell->type != SPELL) continue; |
2228 | if (spell->type != SPELL) continue; |
2145 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2229 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2146 | (spell->msg?strlen(spell->msg):0)))) { |
2230 | (spell->msg?strlen(spell->msg):0)))) { |
2147 | Send_With_Handling(&pl->socket, &sl); |
2231 | Send_With_Handling(&pl->socket, &sl); |
2148 | strcpy((char*)sl.buf,"addspell "); |
2232 | strcpy((char*)sl.buf,"addspell "); |
2149 | sl.len=strlen((char*)sl.buf); |
2233 | sl.len=strlen((char*)sl.buf); |
2150 | } |
2234 | } |
… | |
… | |
2154 | else if (spell->type != SPELL) { |
2238 | else if (spell->type != SPELL) { |
2155 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2239 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2156 | return; |
2240 | return; |
2157 | } |
2241 | } |
2158 | else append_spell(pl, &sl, spell); |
2242 | else append_spell(pl, &sl, spell); |
2159 | if (sl.len > MAXSOCKBUF) { |
2243 | if (sl.len >= MAXSOCKBUF) { |
2160 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2244 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2161 | fatal(0); |
2245 | fatal(0); |
2162 | } |
2246 | } |
2163 | /* finally, we can send the packet */ |
2247 | /* finally, we can send the packet */ |
2164 | Send_With_Handling(&pl->socket, &sl); |
2248 | Send_With_Handling(&pl->socket, &sl); |