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.9 by root, Sun Jun 11 15:02:17 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.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 - 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 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));
142} 223}
143 224
144/** This is the Setup cmd - easy first implementation */ 225/** This is the Setup cmd - easy first implementation */
145void SetUp(char *buf, int len, NewSocket *ns) 226void 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/**
1975 for (i=1; i< NUM_SKILLS; i++) { 2060 for (i=1; i< NUM_SKILLS; i++) {
1976 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,
1977 skill_names[i]); 2062 skill_names[i]);
1978 } 2063 }
1979 sl.len = strlen((char*)sl.buf); 2064 sl.len = strlen((char*)sl.buf);
1980 if (sl.len > MAXSOCKBUF) { 2065 if (sl.len >= MAXSOCKBUF) {
1981 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 2066 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1982 fatal(0); 2067 fatal(0);
1983 } 2068 }
1984 Send_With_Handling(ns, &sl); 2069 Send_With_Handling(ns, &sl);
1985 free(sl.buf); 2070 free(sl.buf);
1996 sl.buf = malloc(MAXSOCKBUF); 2081 sl.buf = malloc(MAXSOCKBUF);
1997 strcpy((char*)sl.buf,"replyinfo spell_paths\n"); 2082 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1998 for(i=0; i<NRSPELLPATHS; i++) 2083 for(i=0; i<NRSPELLPATHS; i++)
1999 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]);
2000 sl.len = strlen((char*)sl.buf); 2085 sl.len = strlen((char*)sl.buf);
2001 if (sl.len > MAXSOCKBUF) { 2086 if (sl.len >= MAXSOCKBUF) {
2002 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2087 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
2003 fatal(0); 2088 fatal(0);
2004 } 2089 }
2005 Send_With_Handling(ns, &sl); 2090 Send_With_Handling(ns, &sl);
2006 free(sl.buf); 2091 free(sl.buf);
2140 * 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
2141 * 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
2142 * like it will fix this 2227 * like it will fix this
2143 */ 2228 */
2144 if (spell->type != SPELL) continue; 2229 if (spell->type != SPELL) continue;
2145 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2230 if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) +
2146 (spell->msg?strlen(spell->msg):0)))) { 2231 (spell->msg?strlen(spell->msg):0)))) {
2147 Send_With_Handling(&pl->socket, &sl); 2232 Send_With_Handling(&pl->socket, &sl);
2148 strcpy((char*)sl.buf,"addspell "); 2233 strcpy((char*)sl.buf,"addspell ");
2149 sl.len=strlen((char*)sl.buf); 2234 sl.len=strlen((char*)sl.buf);
2150 } 2235 }
2154 else if (spell->type != SPELL) { 2239 else if (spell->type != SPELL) {
2155 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");
2156 return; 2241 return;
2157 } 2242 }
2158 else append_spell(pl, &sl, spell); 2243 else append_spell(pl, &sl, spell);
2159 if (sl.len > MAXSOCKBUF) { 2244 if (sl.len >= MAXSOCKBUF) {
2160 LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); 2245 LOG(llevError,"Buffer overflow in esrv_add_spells!\n");
2161 fatal(0); 2246 fatal(0);
2162 } 2247 }
2163 /* finally, we can send the packet */ 2248 /* finally, we can send the packet */
2164 Send_With_Handling(&pl->socket, &sl); 2249 Send_With_Handling(&pl->socket, &sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines