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.9 2006/06/11 15:02:17 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 | |
|
|
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 | } |
716 | check_map_change (pl); |
800 | pl->socket.current_map = 0; |
717 | } |
801 | } |
718 | |
802 | |
719 | |
803 | |
720 | |
804 | |
721 | /** |
805 | /** |
… | |
… | |
1476 | uint16 mask,emask; |
1560 | uint16 mask,emask; |
1477 | uint8 eentrysize; |
1561 | uint8 eentrysize; |
1478 | uint16 ewhatstart,ewhatflag; |
1562 | uint16 ewhatstart,ewhatflag; |
1479 | uint8 extendedinfos; |
1563 | uint8 extendedinfos; |
1480 | mapstruct *m; |
1564 | mapstruct *m; |
1481 | |
|
|
1482 | check_map_change (pl->contr); |
|
|
1483 | |
1565 | |
1484 | sl.buf=malloc(MAXSOCKBUF); |
1566 | sl.buf=malloc(MAXSOCKBUF); |
1485 | if (pl->contr->socket.mapmode == Map1Cmd) |
1567 | if (pl->contr->socket.mapmode == Map1Cmd) |
1486 | strcpy((char*)sl.buf,"map1 "); |
1568 | strcpy((char*)sl.buf,"map1 "); |
1487 | else |
1569 | else |
… | |
… | |
1768 | if (sl.len>startlen || pl->contr->socket.sent_scroll) { |
1850 | if (sl.len>startlen || pl->contr->socket.sent_scroll) { |
1769 | Send_With_Handling(&pl->contr->socket, &sl); |
1851 | Send_With_Handling(&pl->contr->socket, &sl); |
1770 | pl->contr->socket.sent_scroll = 0; |
1852 | pl->contr->socket.sent_scroll = 0; |
1771 | } |
1853 | } |
1772 | free(sl.buf); |
1854 | free(sl.buf); |
|
|
1855 | |
|
|
1856 | check_map_change (pl->contr); |
1773 | } |
1857 | } |
1774 | |
1858 | |
1775 | /** |
1859 | /** |
1776 | * Draws client map. |
1860 | * Draws client map. |
1777 | */ |
1861 | */ |
… | |
… | |
1890 | } |
1974 | } |
1891 | } /* Is a valid space */ |
1975 | } /* Is a valid space */ |
1892 | } |
1976 | } |
1893 | } |
1977 | } |
1894 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
1978 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
|
|
1979 | |
|
|
1980 | check_map_change (pl->contr); |
1895 | } |
1981 | } |
1896 | |
1982 | |
1897 | |
1983 | |
1898 | void esrv_map_scroll(NewSocket *ns,int dx,int dy) |
1984 | void esrv_map_scroll(NewSocket *ns,int dx,int dy) |
1899 | { |
1985 | { |
… | |
… | |
1974 | for (i=1; i< NUM_SKILLS; i++) { |
2060 | for (i=1; i< NUM_SKILLS; i++) { |
1975 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2061 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
1976 | skill_names[i]); |
2062 | skill_names[i]); |
1977 | } |
2063 | } |
1978 | sl.len = strlen((char*)sl.buf); |
2064 | sl.len = strlen((char*)sl.buf); |
1979 | if (sl.len > MAXSOCKBUF) { |
2065 | if (sl.len >= MAXSOCKBUF) { |
1980 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2066 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
1981 | fatal(0); |
2067 | fatal(0); |
1982 | } |
2068 | } |
1983 | Send_With_Handling(ns, &sl); |
2069 | Send_With_Handling(ns, &sl); |
1984 | free(sl.buf); |
2070 | free(sl.buf); |
… | |
… | |
1995 | sl.buf = malloc(MAXSOCKBUF); |
2081 | sl.buf = malloc(MAXSOCKBUF); |
1996 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2082 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
1997 | for(i=0; i<NRSPELLPATHS; i++) |
2083 | for(i=0; i<NRSPELLPATHS; i++) |
1998 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2084 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
1999 | sl.len = strlen((char*)sl.buf); |
2085 | sl.len = strlen((char*)sl.buf); |
2000 | if (sl.len > MAXSOCKBUF) { |
2086 | if (sl.len >= MAXSOCKBUF) { |
2001 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2087 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2002 | fatal(0); |
2088 | fatal(0); |
2003 | } |
2089 | } |
2004 | Send_With_Handling(ns, &sl); |
2090 | Send_With_Handling(ns, &sl); |
2005 | free(sl.buf); |
2091 | free(sl.buf); |
… | |
… | |
2139 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2225 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2140 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2226 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2141 | * like it will fix this |
2227 | * like it will fix this |
2142 | */ |
2228 | */ |
2143 | if (spell->type != SPELL) continue; |
2229 | if (spell->type != SPELL) continue; |
2144 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2230 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2145 | (spell->msg?strlen(spell->msg):0)))) { |
2231 | (spell->msg?strlen(spell->msg):0)))) { |
2146 | Send_With_Handling(&pl->socket, &sl); |
2232 | Send_With_Handling(&pl->socket, &sl); |
2147 | strcpy((char*)sl.buf,"addspell "); |
2233 | strcpy((char*)sl.buf,"addspell "); |
2148 | sl.len=strlen((char*)sl.buf); |
2234 | sl.len=strlen((char*)sl.buf); |
2149 | } |
2235 | } |
… | |
… | |
2153 | else if (spell->type != SPELL) { |
2239 | else if (spell->type != SPELL) { |
2154 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2240 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2155 | return; |
2241 | return; |
2156 | } |
2242 | } |
2157 | else append_spell(pl, &sl, spell); |
2243 | else append_spell(pl, &sl, spell); |
2158 | if (sl.len > MAXSOCKBUF) { |
2244 | if (sl.len >= MAXSOCKBUF) { |
2159 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2245 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2160 | fatal(0); |
2246 | fatal(0); |
2161 | } |
2247 | } |
2162 | /* finally, we can send the packet */ |
2248 | /* finally, we can send the packet */ |
2163 | Send_With_Handling(&pl->socket, &sl); |
2249 | Send_With_Handling(&pl->socket, &sl); |