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.8 by root, Mon May 1 12:22:03 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.8 2006/05/01 12:22:03 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{
501 short packet; 586 short packet;
502 char command[MAX_BUF]; 587 char command[MAX_BUF];
503 SockList sl; 588 SockList sl;
504 589
505 if (len < 7) { 590 if (len < 7) {
506 LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); 591 LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf);
507 return; 592 return;
508 } 593 }
509 594
510 packet = GetShort_String(buf); 595 packet = GetShort_String(buf);
511 repeat = GetInt_String(buf+2); 596 repeat = GetInt_String(buf+2);
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); 792 pl->socket.current_map = 0;
708} 793}
709 794
710 795
711 796
712/** 797/**
1467 uint16 mask,emask; 1552 uint16 mask,emask;
1468 uint8 eentrysize; 1553 uint8 eentrysize;
1469 uint16 ewhatstart,ewhatflag; 1554 uint16 ewhatstart,ewhatflag;
1470 uint8 extendedinfos; 1555 uint8 extendedinfos;
1471 mapstruct *m; 1556 mapstruct *m;
1472
1473 check_map_change (pl->contr);
1474 1557
1475 sl.buf=malloc(MAXSOCKBUF); 1558 sl.buf=malloc(MAXSOCKBUF);
1476 if (pl->contr->socket.mapmode == Map1Cmd) 1559 if (pl->contr->socket.mapmode == Map1Cmd)
1477 strcpy((char*)sl.buf,"map1 "); 1560 strcpy((char*)sl.buf,"map1 ");
1478 else 1561 else
1759 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1842 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1760 Send_With_Handling(&pl->contr->socket, &sl); 1843 Send_With_Handling(&pl->contr->socket, &sl);
1761 pl->contr->socket.sent_scroll = 0; 1844 pl->contr->socket.sent_scroll = 0;
1762 } 1845 }
1763 free(sl.buf); 1846 free(sl.buf);
1847
1848 check_map_change (pl->contr);
1764} 1849}
1765 1850
1766/** 1851/**
1767 * Draws client map. 1852 * Draws client map.
1768 */ 1853 */
1881 } 1966 }
1882 } /* Is a valid space */ 1967 } /* Is a valid space */
1883 } 1968 }
1884 } 1969 }
1885 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1970 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1971
1972 check_map_change (pl->contr);
1886} 1973}
1887 1974
1888 1975
1889void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1976void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1890{ 1977{
1965 for (i=1; i< NUM_SKILLS; i++) { 2052 for (i=1; i< NUM_SKILLS; i++) {
1966 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, 2053 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO,
1967 skill_names[i]); 2054 skill_names[i]);
1968 } 2055 }
1969 sl.len = strlen((char*)sl.buf); 2056 sl.len = strlen((char*)sl.buf);
1970 if (sl.len > MAXSOCKBUF) { 2057 if (sl.len >= MAXSOCKBUF) {
1971 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 2058 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1972 fatal(0); 2059 fatal(0);
1973 } 2060 }
1974 Send_With_Handling(ns, &sl); 2061 Send_With_Handling(ns, &sl);
1975 free(sl.buf); 2062 free(sl.buf);
1986 sl.buf = malloc(MAXSOCKBUF); 2073 sl.buf = malloc(MAXSOCKBUF);
1987 strcpy((char*)sl.buf,"replyinfo spell_paths\n"); 2074 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1988 for(i=0; i<NRSPELLPATHS; i++) 2075 for(i=0; i<NRSPELLPATHS; i++)
1989 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); 2076 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]);
1990 sl.len = strlen((char*)sl.buf); 2077 sl.len = strlen((char*)sl.buf);
1991 if (sl.len > MAXSOCKBUF) { 2078 if (sl.len >= MAXSOCKBUF) {
1992 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2079 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
1993 fatal(0); 2080 fatal(0);
1994 } 2081 }
1995 Send_With_Handling(ns, &sl); 2082 Send_With_Handling(ns, &sl);
1996 free(sl.buf); 2083 free(sl.buf);
2130 * to show add_spell is 26 bytes + 2 strings. However, the overun 2217 * 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 2218 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem
2132 * like it will fix this 2219 * like it will fix this
2133 */ 2220 */
2134 if (spell->type != SPELL) continue; 2221 if (spell->type != SPELL) continue;
2135 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2222 if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) +
2136 (spell->msg?strlen(spell->msg):0)))) { 2223 (spell->msg?strlen(spell->msg):0)))) {
2137 Send_With_Handling(&pl->socket, &sl); 2224 Send_With_Handling(&pl->socket, &sl);
2138 strcpy((char*)sl.buf,"addspell "); 2225 strcpy((char*)sl.buf,"addspell ");
2139 sl.len=strlen((char*)sl.buf); 2226 sl.len=strlen((char*)sl.buf);
2140 } 2227 }
2144 else if (spell->type != SPELL) { 2231 else if (spell->type != SPELL) {
2145 LOG(llevError, "Asked to send a non-spell object as a spell"); 2232 LOG(llevError, "Asked to send a non-spell object as a spell");
2146 return; 2233 return;
2147 } 2234 }
2148 else append_spell(pl, &sl, spell); 2235 else append_spell(pl, &sl, spell);
2149 if (sl.len > MAXSOCKBUF) { 2236 if (sl.len >= MAXSOCKBUF) {
2150 LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); 2237 LOG(llevError,"Buffer overflow in esrv_add_spells!\n");
2151 fatal(0); 2238 fatal(0);
2152 } 2239 }
2153 /* finally, we can send the packet */ 2240 /* finally, we can send the packet */
2154 Send_With_Handling(&pl->socket, &sl); 2241 Send_With_Handling(&pl->socket, &sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines