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.10 by root, Mon Jun 19 10:15:44 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.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
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 ExtCmd (char *buf, int len, player *pl)
145{
146 execute_global_event (EVENT_EXTCMD, pl, buf, len);
147}
148
149void 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));
133} 223}
134 224
135/** This is the Setup cmd - easy first implementation */ 225/** This is the Setup cmd - easy first implementation */
136void SetUp(char *buf, int len, NewSocket *ns) 226void SetUp(char *buf, int len, NewSocket *ns)
137{ 227{
199// } else if (!strcmp(cmd,"plugincmd")) { 289// } else if (!strcmp(cmd,"plugincmd")) {
200// ns->plugincmd = atoi(param); 290// ns->plugincmd = atoi(param);
201// safe_strcat(cmdback, param, &slen, HUGE_BUF); 291// safe_strcat(cmdback, param, &slen, HUGE_BUF);
202 } else if (!strcmp(cmd,"mapinfocmd")) { 292 } else if (!strcmp(cmd,"mapinfocmd")) {
203 ns->mapinfocmd = atoi(param); 293 ns->mapinfocmd = atoi(param);
204 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);
205 } else if (!strcmp(cmd,"facecache")) { 298 } else if (!strcmp(cmd,"facecache")) {
206 ns->facecache = atoi(param); 299 ns->facecache = atoi(param);
207 safe_strcat(cmdback, param, &slen, HUGE_BUF); 300 safe_strcat(cmdback, param, &slen, HUGE_BUF);
208 } else if (!strcmp(cmd,"faceset")) { 301 } else if (!strcmp(cmd,"faceset")) {
209 char tmpbuf[20]; 302 char tmpbuf[20];
501 short packet; 594 short packet;
502 char command[MAX_BUF]; 595 char command[MAX_BUF];
503 SockList sl; 596 SockList sl;
504 597
505 if (len < 7) { 598 if (len < 7) {
506 LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); 599 LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf);
507 return; 600 return;
508 } 601 }
509 602
510 packet = GetShort_String(buf); 603 packet = GetShort_String(buf);
511 repeat = GetInt_String(buf+2); 604 repeat = GetInt_String(buf+2);
702{ 795{
703 if( pl->socket.newmapcmd == 1) { 796 if( pl->socket.newmapcmd == 1) {
704 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 797 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
705 Write_String_To_Socket( &pl->socket, "newmap", 6); 798 Write_String_To_Socket( &pl->socket, "newmap", 6);
706 } 799 }
707 check_map_change (pl); 800 pl->socket.current_map = 0;
708} 801}
709 802
710 803
711 804
712/** 805/**
1468 uint8 eentrysize; 1561 uint8 eentrysize;
1469 uint16 ewhatstart,ewhatflag; 1562 uint16 ewhatstart,ewhatflag;
1470 uint8 extendedinfos; 1563 uint8 extendedinfos;
1471 mapstruct *m; 1564 mapstruct *m;
1472 1565
1473 check_map_change (pl->contr);
1474
1475 sl.buf=malloc(MAXSOCKBUF); 1566 sl.buf=malloc(MAXSOCKBUF);
1476 if (pl->contr->socket.mapmode == Map1Cmd) 1567 if (pl->contr->socket.mapmode == Map1Cmd)
1477 strcpy((char*)sl.buf,"map1 "); 1568 strcpy((char*)sl.buf,"map1 ");
1478 else 1569 else
1479 strcpy((char*)sl.buf,"map1a "); 1570 strcpy((char*)sl.buf,"map1a ");
1520 1611
1521 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++) {
1522 ax=0; 1613 ax=0;
1523 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++) {
1524 1615
1525 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1526 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1616 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1527 1617
1528 /* 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
1529 * 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
1530 * the client wants if using the map1a command - this is because 1620 * the client wants if using the map1a command - this is because
1531 * 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
1759 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1849 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1760 Send_With_Handling(&pl->contr->socket, &sl); 1850 Send_With_Handling(&pl->contr->socket, &sl);
1761 pl->contr->socket.sent_scroll = 0; 1851 pl->contr->socket.sent_scroll = 0;
1762 } 1852 }
1763 free(sl.buf); 1853 free(sl.buf);
1854
1855 check_map_change (pl->contr);
1764} 1856}
1765 1857
1766/** 1858/**
1767 * Draws client map. 1859 * Draws client map.
1768 */ 1860 */
1881 } 1973 }
1882 } /* Is a valid space */ 1974 } /* Is a valid space */
1883 } 1975 }
1884 } 1976 }
1885 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1977 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1978
1979 check_map_change (pl->contr);
1886} 1980}
1887 1981
1888 1982
1889void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1983void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1890{ 1984{
1965 for (i=1; i< NUM_SKILLS; i++) { 2059 for (i=1; i< NUM_SKILLS; i++) {
1966 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,
1967 skill_names[i]); 2061 skill_names[i]);
1968 } 2062 }
1969 sl.len = strlen((char*)sl.buf); 2063 sl.len = strlen((char*)sl.buf);
1970 if (sl.len > MAXSOCKBUF) { 2064 if (sl.len >= MAXSOCKBUF) {
1971 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 2065 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1972 fatal(0); 2066 fatal(0);
1973 } 2067 }
1974 Send_With_Handling(ns, &sl); 2068 Send_With_Handling(ns, &sl);
1975 free(sl.buf); 2069 free(sl.buf);
1986 sl.buf = malloc(MAXSOCKBUF); 2080 sl.buf = malloc(MAXSOCKBUF);
1987 strcpy((char*)sl.buf,"replyinfo spell_paths\n"); 2081 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1988 for(i=0; i<NRSPELLPATHS; i++) 2082 for(i=0; i<NRSPELLPATHS; i++)
1989 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]);
1990 sl.len = strlen((char*)sl.buf); 2084 sl.len = strlen((char*)sl.buf);
1991 if (sl.len > MAXSOCKBUF) { 2085 if (sl.len >= MAXSOCKBUF) {
1992 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2086 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
1993 fatal(0); 2087 fatal(0);
1994 } 2088 }
1995 Send_With_Handling(ns, &sl); 2089 Send_With_Handling(ns, &sl);
1996 free(sl.buf); 2090 free(sl.buf);
2130 * 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
2131 * 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
2132 * like it will fix this 2226 * like it will fix this
2133 */ 2227 */
2134 if (spell->type != SPELL) continue; 2228 if (spell->type != SPELL) continue;
2135 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2229 if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) +
2136 (spell->msg?strlen(spell->msg):0)))) { 2230 (spell->msg?strlen(spell->msg):0)))) {
2137 Send_With_Handling(&pl->socket, &sl); 2231 Send_With_Handling(&pl->socket, &sl);
2138 strcpy((char*)sl.buf,"addspell "); 2232 strcpy((char*)sl.buf,"addspell ");
2139 sl.len=strlen((char*)sl.buf); 2233 sl.len=strlen((char*)sl.buf);
2140 } 2234 }
2144 else if (spell->type != SPELL) { 2238 else if (spell->type != SPELL) {
2145 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");
2146 return; 2240 return;
2147 } 2241 }
2148 else append_spell(pl, &sl, spell); 2242 else append_spell(pl, &sl, spell);
2149 if (sl.len > MAXSOCKBUF) { 2243 if (sl.len >= MAXSOCKBUF) {
2150 LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); 2244 LOG(llevError,"Buffer overflow in esrv_add_spells!\n");
2151 fatal(0); 2245 fatal(0);
2152 } 2246 }
2153 /* finally, we can send the packet */ 2247 /* finally, we can send the packet */
2154 Send_With_Handling(&pl->socket, &sl); 2248 Send_With_Handling(&pl->socket, &sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines