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.1 by root, Fri Feb 3 07:14:46 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.1 2006/02/03 07:14:46 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
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 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}
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; 228 int s, slen;
113 char *cmd, *param, cmdback[HUGE_BUF]; 229 char *cmd, *param, cmdback[HUGE_BUF];
114 230
115 /* run through the cmds of setup 231 /* run through the cmds of setup
116 * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... 232 * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
117 * 233 *
137 253
138 for(;buf[s] && buf[s] != ' ';s++) ; 254 for(;buf[s] && buf[s] != ' ';s++) ;
139 buf[s++]=0; 255 buf[s++]=0;
140 while (buf[s] == ' ') s++; 256 while (buf[s] == ' ') s++;
141 257
142 strcat(cmdback, " "); 258 slen = strlen(cmdback);
143 strcat(cmdback, cmd); 259 safe_strcat(cmdback, " ", &slen, HUGE_BUF);
144 strcat(cmdback, " "); 260 safe_strcat(cmdback, cmd, &slen, HUGE_BUF);
145 261 safe_strcat(cmdback, " ", &slen, HUGE_BUF);
146 262
147 if (!strcmp(cmd,"sound")) { 263 if (!strcmp(cmd,"sound")) {
148 ns->sound = atoi(param); 264 ns->sound = atoi(param);
149 strcat(cmdback, param); 265 safe_strcat(cmdback, param, &slen, HUGE_BUF);
150 } 266 }
151 else if (!strcmp(cmd,"exp64")) { 267 else if (!strcmp(cmd,"exp64")) {
152 ns->exp64 = atoi(param); 268 ns->exp64 = atoi(param);
153 strcat(cmdback, param); 269 safe_strcat(cmdback, param, &slen, HUGE_BUF);
154 } else if (!strcmp(cmd, "spellmon")) { 270 } else if (!strcmp(cmd, "spellmon")) {
155 ns->monitor_spells = atoi(param); 271 ns->monitor_spells = atoi(param);
156 strcat(cmdback, param); 272 safe_strcat(cmdback, param, &slen, HUGE_BUF);
157 } else if (!strcmp(cmd,"darkness")) { 273 } else if (!strcmp(cmd,"darkness")) {
158 ns->darkness = atoi(param); 274 ns->darkness = atoi(param);
159 strcat(cmdback, param); 275 safe_strcat(cmdback, param, &slen, HUGE_BUF);
160 } else if (!strcmp(cmd,"map1cmd")) { 276 } else if (!strcmp(cmd,"map1cmd")) {
161 if (atoi(param)) ns->mapmode = Map1Cmd; 277 if (atoi(param)) ns->mapmode = Map1Cmd;
162 /* if beyond this size, need to use map1cmd no matter what */ 278 /* if beyond this size, need to use map1cmd no matter what */
163 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; 279 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd;
164 strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0"); 280 safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF);
165 } else if (!strcmp(cmd,"map1acmd")) { 281 } else if (!strcmp(cmd,"map1acmd")) {
166 if (atoi(param)) ns->mapmode = Map1aCmd; 282 if (atoi(param)) ns->mapmode = Map1aCmd;
167 /* if beyond this size, need to use map1acmd no matter what */ 283 /* if beyond this size, need to use map1acmd no matter what */
168 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; 284 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd;
169 strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0"); 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 strcat(cmdback, param); 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 strcat(cmdback, param); 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];
178 int q = atoi(param); 303 int q = atoi(param);
179 304
180 if (is_valid_faceset(q)) 305 if (is_valid_faceset(q))
181 ns->faceset=q; 306 ns->faceset=q;
182 sprintf(tmpbuf,"%d", ns->faceset); 307 sprintf(tmpbuf,"%d", ns->faceset);
183 strcat(cmdback, tmpbuf); 308 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
184 /* if the client is using faceset, it knows about image2 command */ 309 /* if the client is using faceset, it knows about image2 command */
185 ns->image2=1; 310 ns->image2=1;
186 } else if (!strcmp(cmd,"itemcmd")) { 311 } else if (!strcmp(cmd,"itemcmd")) {
187 /* Version of the item protocol command to use. Currently, 312 /* Version of the item protocol command to use. Currently,
188 * only supported versions are 1 and 2. Using a numeric 313 * only supported versions are 1 and 2. Using a numeric
194 strcpy(tmpbuf,"FALSE"); 319 strcpy(tmpbuf,"FALSE");
195 } else { 320 } else {
196 ns->itemcmd = q; 321 ns->itemcmd = q;
197 sprintf(tmpbuf,"%d", ns->itemcmd); 322 sprintf(tmpbuf,"%d", ns->itemcmd);
198 } 323 }
199 strcat(cmdback, tmpbuf); 324 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
200 } else if (!strcmp(cmd,"mapsize")) { 325 } else if (!strcmp(cmd,"mapsize")) {
201 int x, y=0; 326 int x, y=0;
202 char tmpbuf[MAX_BUF], *cp; 327 char tmpbuf[MAX_BUF], *cp;
203 328
204 x = atoi(param); 329 x = atoi(param);
207 y = atoi(cp+1); 332 y = atoi(cp+1);
208 break; 333 break;
209 } 334 }
210 if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { 335 if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) {
211 sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); 336 sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y);
212 strcat(cmdback, tmpbuf); 337 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
213 } else { 338 } else {
214 ns->mapx = x; 339 ns->mapx = x;
215 ns->mapy = y; 340 ns->mapy = y;
216 /* better to send back what we are really using and not the 341 /* better to send back what we are really using and not the
217 * param as given to us in case it gets parsed differently. 342 * param as given to us in case it gets parsed differently.
218 */ 343 */
219 sprintf(tmpbuf,"%dx%d", x,y); 344 sprintf(tmpbuf,"%dx%d", x,y);
220 strcat(cmdback, tmpbuf); 345 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
221 /* If beyond this size and still using orig map command, need to 346 /* If beyond this size and still using orig map command, need to
222 * go to map1cmd. 347 * go to map1cmd.
223 */ 348 */
224 if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; 349 if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd;
225 } 350 }
226 } else if (!strcmp(cmd,"extendedMapInfos")) { 351 } else if (!strcmp(cmd,"extendedMapInfos")) {
227 /* Added by tchize 352 /* Added by tchize
228 * prepare to use the mapextended command 353 * prepare to use the mapextended command
229 */ 354 */
230 char tmpbuf[20]; 355 char tmpbuf[20];
231 ns->ext_mapinfos = (atoi(param)); 356 ns->ext_mapinfos = (atoi(param));
232 sprintf(tmpbuf,"%d", ns->ext_mapinfos); 357 sprintf(tmpbuf,"%d", ns->ext_mapinfos);
233 strcat(cmdback, tmpbuf); 358 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
234 } else if (!strcmp(cmd,"extendedTextInfos")) { 359 } else if (!strcmp(cmd,"extendedTextInfos")) {
235 /* Added by tchize 360 /* Added by tchize
236 * prepare to use the extended text commands 361 * prepare to use the extended text commands
237 * Client toggle this to non zero to get exttext 362 * Client toggle this to non zero to get exttext
238 */ 363 */
239 char tmpbuf[20]; 364 char tmpbuf[20];
365
240 ns->has_readable_type = (atoi(param)); 366 ns->has_readable_type = (atoi(param));
241 sprintf(tmpbuf,"%d", ns->has_readable_type); 367 sprintf(tmpbuf,"%d", ns->has_readable_type);
242 strcat(cmdback, tmpbuf); 368 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
243 } else { 369 } else {
244 /* Didn't get a setup command we understood - 370 /* Didn't get a setup command we understood -
245 * report a failure to the client. 371 * report a failure to the client.
246 */ 372 */
247 strcat(cmdback, "FALSE"); 373 safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF);
248 } 374 }
249 } /* for processing all the setup commands */ 375 } /* for processing all the setup commands */
250 LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); 376 LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback);
251 Write_String_To_Socket(ns, cmdback, strlen(cmdback)); 377 Write_String_To_Socket(ns, cmdback, strlen(cmdback));
252} 378}
362 * Basically, it makes no sense to wait for the client to request a 488 * Basically, it makes no sense to wait for the client to request a
363 * a piece of data from us that we know the client wants. So 489 * a piece of data from us that we know the client wants. So
364 * if we know the client wants it, might as well push it to the 490 * if we know the client wants it, might as well push it to the
365 * client. 491 * client.
366 */ 492 */
367void SendSmooth(NewSocket *ns, uint16 face) { 493static void SendSmooth(NewSocket *ns, uint16 face) {
368 uint16 smoothface; 494 uint16 smoothface;
369 uint8 reply[MAX_BUF]; 495 uint8 reply[MAX_BUF];
370 SockList sl; 496 SockList sl;
371 497
372 /* If we can't find a face, return and set it so we won't try to send this 498 /* If we can't find a face, return and set it so we won't try to send this
468 short packet; 594 short packet;
469 char command[MAX_BUF]; 595 char command[MAX_BUF];
470 SockList sl; 596 SockList sl;
471 597
472 if (len < 7) { 598 if (len < 7) {
473 LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); 599 LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf);
474 return; 600 return;
475 } 601 }
476 602
477 packet = GetShort_String(buf); 603 packet = GetShort_String(buf);
478 repeat = GetInt_String(buf+2); 604 repeat = GetInt_String(buf+2);
617 LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); 743 LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version);
618#endif 744#endif
619 } 745 }
620 cp = strchr(cp+1, ' '); 746 cp = strchr(cp+1, ' ');
621 if (cp) { 747 if (cp) {
622 LOG(llevDebug,"CS: connection from client of type <%s>\n", cp); 748 LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
623 749
624 /* This is first implementation - i skip all beta DX clients with it 750 /* This is first implementation - i skip all beta DX clients with it
625 * Add later stuff here for other clients 751 * Add later stuff here for other clients
626 */ 752 */
627 753
669{ 795{
670 if( pl->socket.newmapcmd == 1) { 796 if( pl->socket.newmapcmd == 1) {
671 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 797 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
672 Write_String_To_Socket( &pl->socket, "newmap", 6); 798 Write_String_To_Socket( &pl->socket, "newmap", 6);
673 } 799 }
800 pl->socket.current_map = 0;
674} 801}
675 802
676 803
677 804
678/** 805/**
1484 1611
1485 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++) {
1486 ax=0; 1613 ax=0;
1487 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++) {
1488 1615
1489 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1490 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1616 emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
1491 1617
1492 /* 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
1493 * 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
1494 * the client wants if using the map1a command - this is because 1620 * the client wants if using the map1a command - this is because
1495 * 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
1723 if (sl.len>startlen || pl->contr->socket.sent_scroll) { 1849 if (sl.len>startlen || pl->contr->socket.sent_scroll) {
1724 Send_With_Handling(&pl->contr->socket, &sl); 1850 Send_With_Handling(&pl->contr->socket, &sl);
1725 pl->contr->socket.sent_scroll = 0; 1851 pl->contr->socket.sent_scroll = 0;
1726 } 1852 }
1727 free(sl.buf); 1853 free(sl.buf);
1854
1855 check_map_change (pl->contr);
1728} 1856}
1729 1857
1730/** 1858/**
1731 * Draws client map. 1859 * Draws client map.
1732 */ 1860 */
1736 sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */ 1864 sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */
1737 New_Face *face,*floor; 1865 New_Face *face,*floor;
1738 New_Face *floor2; 1866 New_Face *floor2;
1739 int d, mflags; 1867 int d, mflags;
1740 struct Map newmap; 1868 struct Map newmap;
1741 mapstruct *m; 1869 mapstruct *m, *pm;
1742 1870
1743 if (pl->type != PLAYER) { 1871 if (pl->type != PLAYER) {
1744 LOG(llevError,"draw_client_map called with non player/non eric-server\n"); 1872 LOG(llevError,"draw_client_map called with non player/non eric-server\n");
1745 return; 1873 return;
1746 } 1874 }
1747 1875
1876 if (pl->contr->transport) {
1877 pm = pl->contr->transport->map;
1878 }
1879 else
1880 pm = pl->map;
1881
1748 /* IF player is just joining the game, he isn't here yet, so the map 1882 /* If player is just joining the game, he isn't here yet, so the map
1749 * can get swapped out. If so, don't try to send them a map. All will 1883 * can get swapped out. If so, don't try to send them a map. All will
1750 * be OK once they really log in. 1884 * be OK once they really log in.
1751 */ 1885 */
1752 if (pl->map==NULL || pl->map->in_memory!=MAP_IN_MEMORY) return; 1886 if (pm==NULL || pm->in_memory!=MAP_IN_MEMORY) return;
1753 1887
1754 memset(&newmap, 0, sizeof(struct Map)); 1888 memset(&newmap, 0, sizeof(struct Map));
1755 1889
1756 for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { 1890 for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) {
1757 for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { 1891 for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) {
1758 ax=i; 1892 ax=i;
1759 ay=j; 1893 ay=j;
1760 m = pl->map; 1894 m = pm;
1761 mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); 1895 mflags = get_map_flags(m, &m, ax, ay, &ax, &ay);
1762 if (mflags & P_OUT_OF_MAP) 1896 if (mflags & P_OUT_OF_MAP)
1763 continue; 1897 continue;
1764 if (mflags & P_NEED_UPDATE) 1898 if (mflags & P_NEED_UPDATE)
1765 update_position(m, ax, ay); 1899 update_position(m, ax, ay);
1807 /* note the out_of_map and d>3 checks are both within the same 1941 /* note the out_of_map and d>3 checks are both within the same
1808 * negation check. 1942 * negation check.
1809 */ 1943 */
1810 nx = i; 1944 nx = i;
1811 ny = j; 1945 ny = j;
1812 m = get_map_from_coord(pl->map, &nx, &ny); 1946 m = get_map_from_coord(pm, &nx, &ny);
1813 if (m && d<4) { 1947 if (m && d<4) {
1814 face = GET_MAP_FACE(m, nx, ny,0); 1948 face = GET_MAP_FACE(m, nx, ny,0);
1815 floor2 = GET_MAP_FACE(m, nx, ny,1); 1949 floor2 = GET_MAP_FACE(m, nx, ny,1);
1816 floor = GET_MAP_FACE(m, nx, ny,2); 1950 floor = GET_MAP_FACE(m, nx, ny,2);
1817 1951
1839 } 1973 }
1840 } /* Is a valid space */ 1974 } /* Is a valid space */
1841 } 1975 }
1842 } 1976 }
1843 esrv_map_doneredraw(&pl->contr->socket, &newmap); 1977 esrv_map_doneredraw(&pl->contr->socket, &newmap);
1978
1979 check_map_change (pl->contr);
1844} 1980}
1845 1981
1846 1982
1847void esrv_map_scroll(NewSocket *ns,int dx,int dy) 1983void esrv_map_scroll(NewSocket *ns,int dx,int dy)
1848{ 1984{
1917{ 2053{
1918 SockList sl; 2054 SockList sl;
1919 int i; 2055 int i;
1920 2056
1921 sl.buf = malloc(MAXSOCKBUF); 2057 sl.buf = malloc(MAXSOCKBUF);
1922 strcpy(sl.buf,"replyinfo skill_info\n"); 2058 strcpy((char*)sl.buf,"replyinfo skill_info\n");
1923 for (i=1; i< NUM_SKILLS; i++) { 2059 for (i=1; i< NUM_SKILLS; i++) {
1924 sprintf(sl.buf + strlen(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,
1925 skill_names[i]); 2061 skill_names[i]);
1926 } 2062 }
1927 sl.len = strlen(sl.buf); 2063 sl.len = strlen((char*)sl.buf);
1928 if (sl.len > MAXSOCKBUF) { 2064 if (sl.len >= MAXSOCKBUF) {
1929 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 2065 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1930 fatal(0); 2066 fatal(0);
1931 } 2067 }
1932 Send_With_Handling(ns, &sl); 2068 Send_With_Handling(ns, &sl);
1933 free(sl.buf); 2069 free(sl.buf);
1940void send_spell_paths (NewSocket *ns, char *params) { 2076void send_spell_paths (NewSocket *ns, char *params) {
1941 SockList sl; 2077 SockList sl;
1942 int i; 2078 int i;
1943 2079
1944 sl.buf = malloc(MAXSOCKBUF); 2080 sl.buf = malloc(MAXSOCKBUF);
1945 strcpy(sl.buf,"replyinfo spell_paths\n"); 2081 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1946 for(i=0; i<NRSPELLPATHS; i++) 2082 for(i=0; i<NRSPELLPATHS; i++)
1947 sprintf(sl.buf + strlen(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]);
1948 sl.len = strlen(sl.buf); 2084 sl.len = strlen((char*)sl.buf);
1949 if (sl.len > MAXSOCKBUF) { 2085 if (sl.len >= MAXSOCKBUF) {
1950 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2086 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
1951 fatal(0); 2087 fatal(0);
1952 } 2088 }
1953 Send_With_Handling(ns, &sl); 2089 Send_With_Handling(ns, &sl);
1954 free(sl.buf); 2090 free(sl.buf);
1978 spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); 2114 spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell);
1979 flags |= UPD_SP_DAMAGE; 2115 flags |= UPD_SP_DAMAGE;
1980 } 2116 }
1981 if (flags !=0) { 2117 if (flags !=0) {
1982 sl.buf = malloc(MAXSOCKBUF); 2118 sl.buf = malloc(MAXSOCKBUF);
1983 strcpy(sl.buf,"updspell "); 2119 strcpy((char*)sl.buf,"updspell ");
1984 sl.len=strlen((char*)sl.buf); 2120 sl.len=strlen((char*)sl.buf);
1985 SockList_AddChar(&sl, flags); 2121 SockList_AddChar(&sl, flags);
1986 SockList_AddInt(&sl, spell->count); 2122 SockList_AddInt(&sl, spell->count);
1987 if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); 2123 if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp);
1988 if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); 2124 if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace);
2002 if (!pl || !spell || spell->env != pl->ob) { 2138 if (!pl || !spell || spell->env != pl->ob) {
2003 LOG(llevError, "Invalid call to esrv_remove_spell"); 2139 LOG(llevError, "Invalid call to esrv_remove_spell");
2004 return; 2140 return;
2005 } 2141 }
2006 sl.buf = malloc(MAXSOCKBUF); 2142 sl.buf = malloc(MAXSOCKBUF);
2007 strcpy(sl.buf,"delspell "); 2143 strcpy((char*)sl.buf,"delspell ");
2008 sl.len=strlen((char*)sl.buf); 2144 sl.len=strlen((char*)sl.buf);
2009 SockList_AddInt(&sl, spell->count); 2145 SockList_AddInt(&sl, spell->count);
2010 Send_With_Handling(&pl->socket, &sl); 2146 Send_With_Handling(&pl->socket, &sl);
2011 free(sl.buf); 2147 free(sl.buf);
2012} 2148}
2013 2149
2014/* appends the spell *spell to the Socklist we will send the data to. */ 2150/* appends the spell *spell to the Socklist we will send the data to. */
2015static void append_spell (player *pl, SockList *sl, object *spell) { 2151static void append_spell (player *pl, SockList *sl, object *spell) {
2016 int len, i, skill=0; 2152 int len, i, skill=0;
2017 2153
2018 if (!(spell->name)) { 2154 if (!(spell->name)) {
2019 LOG(llevError, "item number %d is a spell with no name.\n", spell->count); 2155 LOG(llevError, "item number %d is a spell with no name.\n", spell->count);
2020 return; 2156 return;
2021 } 2157 }
2029 /* send the current values */ 2165 /* send the current values */
2030 SockList_AddShort(sl, spell->last_sp); 2166 SockList_AddShort(sl, spell->last_sp);
2031 SockList_AddShort(sl, spell->last_grace); 2167 SockList_AddShort(sl, spell->last_grace);
2032 SockList_AddShort(sl, spell->last_eat); 2168 SockList_AddShort(sl, spell->last_eat);
2033 2169
2034 /* figure out which skill it uses */ 2170 /* figure out which skill it uses, if it uses one */
2171 if (spell->skill) {
2035 for (i=1; i< NUM_SKILLS; i++) 2172 for (i=1; i< NUM_SKILLS; i++)
2036 if (!strcmp(spell->skill, skill_names[i])) { 2173 if (!strcmp(spell->skill, skill_names[i])) {
2037 skill = i+CS_STAT_SKILLINFO; 2174 skill = i+CS_STAT_SKILLINFO;
2038 break; 2175 break;
2039 } 2176 }
2040 skill = i+CS_STAT_SKILLINFO; 2177 }
2041 SockList_AddChar(sl, skill); 2178 SockList_AddChar(sl, skill);
2042 2179
2043 SockList_AddInt(sl, spell->path_attuned); 2180 SockList_AddInt(sl, spell->path_attuned);
2044 SockList_AddInt(sl, (spell->face)?spell->face->number:0); 2181 SockList_AddInt(sl, (spell->face)?spell->face->number:0);
2045 2182
2069 LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2206 LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2070 return; 2207 return;
2071 } 2208 }
2072 if (!pl->socket.monitor_spells) return; 2209 if (!pl->socket.monitor_spells) return;
2073 sl.buf = malloc(MAXSOCKBUF); 2210 sl.buf = malloc(MAXSOCKBUF);
2074 strcpy(sl.buf,"addspell "); 2211 strcpy((char*)sl.buf,"addspell ");
2075 sl.len=strlen((char*)sl.buf); 2212 sl.len=strlen((char*)sl.buf);
2076 if (!spell) { 2213 if (!spell) {
2077 for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { 2214 for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) {
2078 /* were we to simply keep appending data here, we could exceed 2215 /* were we to simply keep appending data here, we could exceed
2079 * MAXSOCKBUF if the player has enough spells to add, we know that 2216 * MAXSOCKBUF if the player has enough spells to add, we know that
2087 * 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
2088 * 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
2089 * like it will fix this 2226 * like it will fix this
2090 */ 2227 */
2091 if (spell->type != SPELL) continue; 2228 if (spell->type != SPELL) continue;
2092 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2229 if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) +
2093 (spell->msg?strlen(spell->msg):0)))) { 2230 (spell->msg?strlen(spell->msg):0)))) {
2094 Send_With_Handling(&pl->socket, &sl); 2231 Send_With_Handling(&pl->socket, &sl);
2095 strcpy(sl.buf,"addspell "); 2232 strcpy((char*)sl.buf,"addspell ");
2096 sl.len=strlen((char*)sl.buf); 2233 sl.len=strlen((char*)sl.buf);
2097 } 2234 }
2098 append_spell(pl, &sl, spell); 2235 append_spell(pl, &sl, spell);
2099 } 2236 }
2100 } 2237 }
2101 else if (spell->type != SPELL) { 2238 else if (spell->type != SPELL) {
2102 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");
2103 return; 2240 return;
2104 } 2241 }
2105 else append_spell(pl, &sl, spell); 2242 else append_spell(pl, &sl, spell);
2106 if (sl.len > MAXSOCKBUF) { 2243 if (sl.len >= MAXSOCKBUF) {
2107 LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); 2244 LOG(llevError,"Buffer overflow in esrv_add_spells!\n");
2108 fatal(0); 2245 fatal(0);
2109 } 2246 }
2110 /* finally, we can send the packet */ 2247 /* finally, we can send the packet */
2111 Send_With_Handling(&pl->socket, &sl); 2248 Send_With_Handling(&pl->socket, &sl);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines