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.1.1.3 by elmex, Wed Mar 15 14:05:40 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.1.1.3 2006/03/15 14:05:40 elmex 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
103 CS_STAT_RES_BLIND, 103 CS_STAT_RES_BLIND,
104 -1, /* Internal */ 104 -1, /* Internal */
105 -1, /* life stealing */ 105 -1, /* life stealing */
106 -1 /* Disease - not fully done yet */ 106 -1 /* Disease - not fully done yet */
107}; 107};
108
109/** check for map change and send new map data */
110static void
111check_map_change (player *pl)
112{
113 char buf[MAX_BUF]; /* eauugggh */
114
115 object *ob = pl->ob;
116
117 if (!pl->socket.mapinfocmd)
118 return;
119
120 if (pl->socket.current_map != ob->map)
121 {
122 pl->socket.current_map = ob->map;
123
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
133 snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s",
134 flags, pl->socket.mapx / 2 - ob->x, pl->socket.mapy / 2 - ob->y,
135 ob->map->width, ob->map->height, ob->map->path);
136 }
137 else
138 snprintf (buf, MAX_BUF, "mapinfo current");
139
140 Write_String_To_Socket (&pl->socket, buf, strlen (buf));
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));
223}
108 224
109/** This is the Setup cmd - easy first implementation */ 225/** This is the Setup cmd - easy first implementation */
110void SetUp(char *buf, int len, NewSocket *ns) 226void SetUp(char *buf, int len, NewSocket *ns)
111{ 227{
112 int s, slen; 228 int s, slen;
168 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; 284 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd;
169 safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); 285 safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF);
170 } else if (!strcmp(cmd,"newmapcmd")) { 286 } else if (!strcmp(cmd,"newmapcmd")) {
171 ns->newmapcmd= atoi(param); 287 ns->newmapcmd= atoi(param);
172 safe_strcat(cmdback, param, &slen, HUGE_BUF); 288 safe_strcat(cmdback, param, &slen, HUGE_BUF);
289// } else if (!strcmp(cmd,"plugincmd")) {
290// ns->plugincmd = atoi(param);
291// safe_strcat(cmdback, param, &slen, HUGE_BUF);
292 } else if (!strcmp(cmd,"mapinfocmd")) {
293 ns->mapinfocmd = atoi(param);
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);
173 } else if (!strcmp(cmd,"facecache")) { 298 } else if (!strcmp(cmd,"facecache")) {
174 ns->facecache = atoi(param); 299 ns->facecache = atoi(param);
175 safe_strcat(cmdback, param, &slen, HUGE_BUF); 300 safe_strcat(cmdback, param, &slen, HUGE_BUF);
176 } else if (!strcmp(cmd,"faceset")) { 301 } else if (!strcmp(cmd,"faceset")) {
177 char tmpbuf[20]; 302 char tmpbuf[20];
469 short packet; 594 short packet;
470 char command[MAX_BUF]; 595 char command[MAX_BUF];
471 SockList sl; 596 SockList sl;
472 597
473 if (len < 7) { 598 if (len < 7) {
474 LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); 599 LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf);
475 return; 600 return;
476 } 601 }
477 602
478 packet = GetShort_String(buf); 603 packet = GetShort_String(buf);
479 repeat = GetInt_String(buf+2); 604 repeat = GetInt_String(buf+2);
670{ 795{
671 if( pl->socket.newmapcmd == 1) { 796 if( pl->socket.newmapcmd == 1) {
672 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 797 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
673 Write_String_To_Socket( &pl->socket, "newmap", 6); 798 Write_String_To_Socket( &pl->socket, "newmap", 6);
674 } 799 }
800 pl->socket.current_map = 0;
675} 801}
676 802
677 803
678 804
679/** 805/**
1485 1611
1486 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++) {
1487 ax=0; 1613 ax=0;
1488 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++) {
1489 1615
1490 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1491 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1616 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1492 1617
1493 /* 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
1494 * 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
1495 * the client wants if using the map1a command - this is because 1620 * the client wants if using the map1a command - this is because
1496 * 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
1724 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1849 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1725 Send_With_Handling(&pl->contr->socket, &sl); 1850 Send_With_Handling(&pl->contr->socket, &sl);
1726 pl->contr->socket.sent_scroll = 0; 1851 pl->contr->socket.sent_scroll = 0;
1727 } 1852 }
1728 free(sl.buf); 1853 free(sl.buf);
1854
1855 check_map_change (pl->contr);
1729} 1856}
1730 1857
1731/** 1858/**
1732 * Draws client map. 1859 * Draws client map.
1733 */ 1860 */
1846 } 1973 }
1847 } /* Is a valid space */ 1974 } /* Is a valid space */
1848 } 1975 }
1849 } 1976 }
1850 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1977 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1978
1979 check_map_change (pl->contr);
1851} 1980}
1852 1981
1853 1982
1854void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1983void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1855{ 1984{
1930 for (i=1; i< NUM_SKILLS; i++) { 2059 for (i=1; i< NUM_SKILLS; i++) {
1931 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,
1932 skill_names[i]); 2061 skill_names[i]);
1933 } 2062 }
1934 sl.len = strlen((char*)sl.buf); 2063 sl.len = strlen((char*)sl.buf);
1935 if (sl.len > MAXSOCKBUF) { 2064 if (sl.len >= MAXSOCKBUF) {
1936 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 2065 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1937 fatal(0); 2066 fatal(0);
1938 } 2067 }
1939 Send_With_Handling(ns, &sl); 2068 Send_With_Handling(ns, &sl);
1940 free(sl.buf); 2069 free(sl.buf);
1951 sl.buf = malloc(MAXSOCKBUF); 2080 sl.buf = malloc(MAXSOCKBUF);
1952 strcpy((char*)sl.buf,"replyinfo spell_paths\n"); 2081 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1953 for(i=0; i<NRSPELLPATHS; i++) 2082 for(i=0; i<NRSPELLPATHS; i++)
1954 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]);
1955 sl.len = strlen((char*)sl.buf); 2084 sl.len = strlen((char*)sl.buf);
1956 if (sl.len > MAXSOCKBUF) { 2085 if (sl.len >= MAXSOCKBUF) {
1957 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2086 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
1958 fatal(0); 2087 fatal(0);
1959 } 2088 }
1960 Send_With_Handling(ns, &sl); 2089 Send_With_Handling(ns, &sl);
1961 free(sl.buf); 2090 free(sl.buf);
2095 * 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
2096 * 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
2097 * like it will fix this 2226 * like it will fix this
2098 */ 2227 */
2099 if (spell->type != SPELL) continue; 2228 if (spell->type != SPELL) continue;
2100 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2229 if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) +
2101 (spell->msg?strlen(spell->msg):0)))) { 2230 (spell->msg?strlen(spell->msg):0)))) {
2102 Send_With_Handling(&pl->socket, &sl); 2231 Send_With_Handling(&pl->socket, &sl);
2103 strcpy((char*)sl.buf,"addspell "); 2232 strcpy((char*)sl.buf,"addspell ");
2104 sl.len=strlen((char*)sl.buf); 2233 sl.len=strlen((char*)sl.buf);
2105 } 2234 }
2109 else if (spell->type != SPELL) { 2238 else if (spell->type != SPELL) {
2110 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");
2111 return; 2240 return;
2112 } 2241 }
2113 else append_spell(pl, &sl, spell); 2242 else append_spell(pl, &sl, spell);
2114 if (sl.len > MAXSOCKBUF) { 2243 if (sl.len >= MAXSOCKBUF) {
2115 LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); 2244 LOG(llevError,"Buffer overflow in esrv_add_spells!\n");
2116 fatal(0); 2245 fatal(0);
2117 } 2246 }
2118 /* finally, we can send the packet */ 2247 /* finally, we can send the packet */
2119 Send_With_Handling(&pl->socket, &sl); 2248 Send_With_Handling(&pl->socket, &sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines