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.3 by root, Sun Apr 16 02:56:46 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.3 2006/04/16 02:56:46 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_map [0]) flags |= 1;
129 if (ob->map->tile_map [1]) flags |= 2;
130 if (ob->map->tile_map [2]) flags |= 4;
131 if (ob->map->tile_map [3]) flags |= 8;
132
133 snprintf (buf, MAX_BUF, "mapinfo current %d %d %d %d %d %s",
134 flags, ob->x, 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
109/** This is the Setup cmd - easy first implementation */ 144/** This is the Setup cmd - easy first implementation */
110void SetUp(char *buf, int len, NewSocket *ns) 145void SetUp(char *buf, int len, NewSocket *ns)
111{ 146{
112 int s; 147 int s, slen;
113 char *cmd, *param, cmdback[HUGE_BUF]; 148 char *cmd, *param, cmdback[HUGE_BUF];
114 149
115 /* run through the cmds of setup 150 /* run through the cmds of setup
116 * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... 151 * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ...
117 * 152 *
137 172
138 for(;buf[s] && buf[s] != ' ';s++) ; 173 for(;buf[s] && buf[s] != ' ';s++) ;
139 buf[s++]=0; 174 buf[s++]=0;
140 while (buf[s] == ' ') s++; 175 while (buf[s] == ' ') s++;
141 176
142 strcat(cmdback, " "); 177 slen = strlen(cmdback);
143 strcat(cmdback, cmd); 178 safe_strcat(cmdback, " ", &slen, HUGE_BUF);
144 strcat(cmdback, " "); 179 safe_strcat(cmdback, cmd, &slen, HUGE_BUF);
145 180 safe_strcat(cmdback, " ", &slen, HUGE_BUF);
146 181
147 if (!strcmp(cmd,"sound")) { 182 if (!strcmp(cmd,"sound")) {
148 ns->sound = atoi(param); 183 ns->sound = atoi(param);
149 strcat(cmdback, param); 184 safe_strcat(cmdback, param, &slen, HUGE_BUF);
150 } 185 }
151 else if (!strcmp(cmd,"exp64")) { 186 else if (!strcmp(cmd,"exp64")) {
152 ns->exp64 = atoi(param); 187 ns->exp64 = atoi(param);
153 strcat(cmdback, param); 188 safe_strcat(cmdback, param, &slen, HUGE_BUF);
154 } else if (!strcmp(cmd, "spellmon")) { 189 } else if (!strcmp(cmd, "spellmon")) {
155 ns->monitor_spells = atoi(param); 190 ns->monitor_spells = atoi(param);
156 strcat(cmdback, param); 191 safe_strcat(cmdback, param, &slen, HUGE_BUF);
157 } else if (!strcmp(cmd,"darkness")) { 192 } else if (!strcmp(cmd,"darkness")) {
158 ns->darkness = atoi(param); 193 ns->darkness = atoi(param);
159 strcat(cmdback, param); 194 safe_strcat(cmdback, param, &slen, HUGE_BUF);
160 } else if (!strcmp(cmd,"map1cmd")) { 195 } else if (!strcmp(cmd,"map1cmd")) {
161 if (atoi(param)) ns->mapmode = Map1Cmd; 196 if (atoi(param)) ns->mapmode = Map1Cmd;
162 /* if beyond this size, need to use map1cmd no matter what */ 197 /* if beyond this size, need to use map1cmd no matter what */
163 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; 198 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd;
164 strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0"); 199 safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF);
165 } else if (!strcmp(cmd,"map1acmd")) { 200 } else if (!strcmp(cmd,"map1acmd")) {
166 if (atoi(param)) ns->mapmode = Map1aCmd; 201 if (atoi(param)) ns->mapmode = Map1aCmd;
167 /* if beyond this size, need to use map1acmd no matter what */ 202 /* if beyond this size, need to use map1acmd no matter what */
168 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; 203 if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd;
169 strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0"); 204 safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF);
170 } else if (!strcmp(cmd,"newmapcmd")) { 205 } else if (!strcmp(cmd,"newmapcmd")) {
171 ns->newmapcmd= atoi(param); 206 ns->newmapcmd= atoi(param);
172 strcat(cmdback, param); 207 safe_strcat(cmdback, param, &slen, HUGE_BUF);
208// } else if (!strcmp(cmd,"plugincmd")) {
209// ns->plugincmd = atoi(param);
210// safe_strcat(cmdback, param, &slen, HUGE_BUF);
211 } else if (!strcmp(cmd,"mapinfocmd")) {
212 ns->mapinfocmd = atoi(param);
213 safe_strcat(cmdback, param, &slen, HUGE_BUF);
173 } else if (!strcmp(cmd,"facecache")) { 214 } else if (!strcmp(cmd,"facecache")) {
174 ns->facecache = atoi(param); 215 ns->facecache = atoi(param);
175 strcat(cmdback, param); 216 safe_strcat(cmdback, param, &slen, HUGE_BUF);
176 } else if (!strcmp(cmd,"faceset")) { 217 } else if (!strcmp(cmd,"faceset")) {
177 char tmpbuf[20]; 218 char tmpbuf[20];
178 int q = atoi(param); 219 int q = atoi(param);
179 220
180 if (is_valid_faceset(q)) 221 if (is_valid_faceset(q))
181 ns->faceset=q; 222 ns->faceset=q;
182 sprintf(tmpbuf,"%d", ns->faceset); 223 sprintf(tmpbuf,"%d", ns->faceset);
183 strcat(cmdback, tmpbuf); 224 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
184 /* if the client is using faceset, it knows about image2 command */ 225 /* if the client is using faceset, it knows about image2 command */
185 ns->image2=1; 226 ns->image2=1;
186 } else if (!strcmp(cmd,"itemcmd")) { 227 } else if (!strcmp(cmd,"itemcmd")) {
187 /* Version of the item protocol command to use. Currently, 228 /* Version of the item protocol command to use. Currently,
188 * only supported versions are 1 and 2. Using a numeric 229 * only supported versions are 1 and 2. Using a numeric
194 strcpy(tmpbuf,"FALSE"); 235 strcpy(tmpbuf,"FALSE");
195 } else { 236 } else {
196 ns->itemcmd = q; 237 ns->itemcmd = q;
197 sprintf(tmpbuf,"%d", ns->itemcmd); 238 sprintf(tmpbuf,"%d", ns->itemcmd);
198 } 239 }
199 strcat(cmdback, tmpbuf); 240 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
200 } else if (!strcmp(cmd,"mapsize")) { 241 } else if (!strcmp(cmd,"mapsize")) {
201 int x, y=0; 242 int x, y=0;
202 char tmpbuf[MAX_BUF], *cp; 243 char tmpbuf[MAX_BUF], *cp;
203 244
204 x = atoi(param); 245 x = atoi(param);
207 y = atoi(cp+1); 248 y = atoi(cp+1);
208 break; 249 break;
209 } 250 }
210 if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { 251 if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) {
211 sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); 252 sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y);
212 strcat(cmdback, tmpbuf); 253 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
213 } else { 254 } else {
214 ns->mapx = x; 255 ns->mapx = x;
215 ns->mapy = y; 256 ns->mapy = y;
216 /* better to send back what we are really using and not the 257 /* better to send back what we are really using and not the
217 * param as given to us in case it gets parsed differently. 258 * param as given to us in case it gets parsed differently.
218 */ 259 */
219 sprintf(tmpbuf,"%dx%d", x,y); 260 sprintf(tmpbuf,"%dx%d", x,y);
220 strcat(cmdback, tmpbuf); 261 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
221 /* If beyond this size and still using orig map command, need to 262 /* If beyond this size and still using orig map command, need to
222 * go to map1cmd. 263 * go to map1cmd.
223 */ 264 */
224 if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; 265 if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd;
225 } 266 }
226 } else if (!strcmp(cmd,"extendedMapInfos")) { 267 } else if (!strcmp(cmd,"extendedMapInfos")) {
227 /* Added by tchize 268 /* Added by tchize
228 * prepare to use the mapextended command 269 * prepare to use the mapextended command
229 */ 270 */
230 char tmpbuf[20]; 271 char tmpbuf[20];
231 ns->ext_mapinfos = (atoi(param)); 272 ns->ext_mapinfos = (atoi(param));
232 sprintf(tmpbuf,"%d", ns->ext_mapinfos); 273 sprintf(tmpbuf,"%d", ns->ext_mapinfos);
233 strcat(cmdback, tmpbuf); 274 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
234 } else if (!strcmp(cmd,"extendedTextInfos")) { 275 } else if (!strcmp(cmd,"extendedTextInfos")) {
235 /* Added by tchize 276 /* Added by tchize
236 * prepare to use the extended text commands 277 * prepare to use the extended text commands
237 * Client toggle this to non zero to get exttext 278 * Client toggle this to non zero to get exttext
238 */ 279 */
239 char tmpbuf[20]; 280 char tmpbuf[20];
281
240 ns->has_readable_type = (atoi(param)); 282 ns->has_readable_type = (atoi(param));
241 sprintf(tmpbuf,"%d", ns->has_readable_type); 283 sprintf(tmpbuf,"%d", ns->has_readable_type);
242 strcat(cmdback, tmpbuf); 284 safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF);
243 } else { 285 } else {
244 /* Didn't get a setup command we understood - 286 /* Didn't get a setup command we understood -
245 * report a failure to the client. 287 * report a failure to the client.
246 */ 288 */
247 strcat(cmdback, "FALSE"); 289 safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF);
248 } 290 }
249 } /* for processing all the setup commands */ 291 } /* for processing all the setup commands */
250 LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); 292 LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback);
251 Write_String_To_Socket(ns, cmdback, strlen(cmdback)); 293 Write_String_To_Socket(ns, cmdback, strlen(cmdback));
252} 294}
362 * Basically, it makes no sense to wait for the client to request a 404 * 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 405 * 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 406 * if we know the client wants it, might as well push it to the
365 * client. 407 * client.
366 */ 408 */
367void SendSmooth(NewSocket *ns, uint16 face) { 409static void SendSmooth(NewSocket *ns, uint16 face) {
368 uint16 smoothface; 410 uint16 smoothface;
369 uint8 reply[MAX_BUF]; 411 uint8 reply[MAX_BUF];
370 SockList sl; 412 SockList sl;
371 413
372 /* If we can't find a face, return and set it so we won't try to send this 414 /* If we can't find a face, return and set it so we won't try to send this
617 LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); 659 LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version);
618#endif 660#endif
619 } 661 }
620 cp = strchr(cp+1, ' '); 662 cp = strchr(cp+1, ' ');
621 if (cp) { 663 if (cp) {
622 LOG(llevDebug,"CS: connection from client of type <%s>\n", cp); 664 LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
623 665
624 /* This is first implementation - i skip all beta DX clients with it 666 /* This is first implementation - i skip all beta DX clients with it
625 * Add later stuff here for other clients 667 * Add later stuff here for other clients
626 */ 668 */
627 669
669{ 711{
670 if( pl->socket.newmapcmd == 1) { 712 if( pl->socket.newmapcmd == 1) {
671 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); 713 memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap));
672 Write_String_To_Socket( &pl->socket, "newmap", 6); 714 Write_String_To_Socket( &pl->socket, "newmap", 6);
673 } 715 }
716 check_map_change (pl);
674} 717}
675 718
676 719
677 720
678/** 721/**
1433 uint16 mask,emask; 1476 uint16 mask,emask;
1434 uint8 eentrysize; 1477 uint8 eentrysize;
1435 uint16 ewhatstart,ewhatflag; 1478 uint16 ewhatstart,ewhatflag;
1436 uint8 extendedinfos; 1479 uint8 extendedinfos;
1437 mapstruct *m; 1480 mapstruct *m;
1481
1482 check_map_change (pl->contr);
1438 1483
1439 sl.buf=malloc(MAXSOCKBUF); 1484 sl.buf=malloc(MAXSOCKBUF);
1440 if (pl->contr->socket.mapmode == Map1Cmd) 1485 if (pl->contr->socket.mapmode == Map1Cmd)
1441 strcpy((char*)sl.buf,"map1 "); 1486 strcpy((char*)sl.buf,"map1 ");
1442 else 1487 else
1736 sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */ 1781 sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */
1737 New_Face *face,*floor; 1782 New_Face *face,*floor;
1738 New_Face *floor2; 1783 New_Face *floor2;
1739 int d, mflags; 1784 int d, mflags;
1740 struct Map newmap; 1785 struct Map newmap;
1741 mapstruct *m; 1786 mapstruct *m, *pm;
1742 1787
1743 if (pl->type != PLAYER) { 1788 if (pl->type != PLAYER) {
1744 LOG(llevError,"draw_client_map called with non player/non eric-server\n"); 1789 LOG(llevError,"draw_client_map called with non player/non eric-server\n");
1745 return; 1790 return;
1746 } 1791 }
1747 1792
1793 if (pl->contr->transport) {
1794 pm = pl->contr->transport->map;
1795 }
1796 else
1797 pm = pl->map;
1798
1748 /* IF player is just joining the game, he isn't here yet, so the map 1799 /* 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 1800 * can get swapped out. If so, don't try to send them a map. All will
1750 * be OK once they really log in. 1801 * be OK once they really log in.
1751 */ 1802 */
1752 if (pl->map==NULL || pl->map->in_memory!=MAP_IN_MEMORY) return; 1803 if (pm==NULL || pm->in_memory!=MAP_IN_MEMORY) return;
1753 1804
1754 memset(&newmap, 0, sizeof(struct Map)); 1805 memset(&newmap, 0, sizeof(struct Map));
1755 1806
1756 for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { 1807 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++) { 1808 for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) {
1758 ax=i; 1809 ax=i;
1759 ay=j; 1810 ay=j;
1760 m = pl->map; 1811 m = pm;
1761 mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); 1812 mflags = get_map_flags(m, &m, ax, ay, &ax, &ay);
1762 if (mflags & P_OUT_OF_MAP) 1813 if (mflags & P_OUT_OF_MAP)
1763 continue; 1814 continue;
1764 if (mflags & P_NEED_UPDATE) 1815 if (mflags & P_NEED_UPDATE)
1765 update_position(m, ax, ay); 1816 update_position(m, ax, ay);
1807 /* note the out_of_map and d>3 checks are both within the same 1858 /* note the out_of_map and d>3 checks are both within the same
1808 * negation check. 1859 * negation check.
1809 */ 1860 */
1810 nx = i; 1861 nx = i;
1811 ny = j; 1862 ny = j;
1812 m = get_map_from_coord(pl->map, &nx, &ny); 1863 m = get_map_from_coord(pm, &nx, &ny);
1813 if (m && d<4) { 1864 if (m && d<4) {
1814 face = GET_MAP_FACE(m, nx, ny,0); 1865 face = GET_MAP_FACE(m, nx, ny,0);
1815 floor2 = GET_MAP_FACE(m, nx, ny,1); 1866 floor2 = GET_MAP_FACE(m, nx, ny,1);
1816 floor = GET_MAP_FACE(m, nx, ny,2); 1867 floor = GET_MAP_FACE(m, nx, ny,2);
1817 1868
1917{ 1968{
1918 SockList sl; 1969 SockList sl;
1919 int i; 1970 int i;
1920 1971
1921 sl.buf = malloc(MAXSOCKBUF); 1972 sl.buf = malloc(MAXSOCKBUF);
1922 strcpy(sl.buf,"replyinfo skill_info\n"); 1973 strcpy((char*)sl.buf,"replyinfo skill_info\n");
1923 for (i=1; i< NUM_SKILLS; i++) { 1974 for (i=1; i< NUM_SKILLS; i++) {
1924 sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, 1975 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO,
1925 skill_names[i]); 1976 skill_names[i]);
1926 } 1977 }
1927 sl.len = strlen(sl.buf); 1978 sl.len = strlen((char*)sl.buf);
1928 if (sl.len > MAXSOCKBUF) { 1979 if (sl.len > MAXSOCKBUF) {
1929 LOG(llevError,"Buffer overflow in send_skill_info!\n"); 1980 LOG(llevError,"Buffer overflow in send_skill_info!\n");
1930 fatal(0); 1981 fatal(0);
1931 } 1982 }
1932 Send_With_Handling(ns, &sl); 1983 Send_With_Handling(ns, &sl);
1940void send_spell_paths (NewSocket *ns, char *params) { 1991void send_spell_paths (NewSocket *ns, char *params) {
1941 SockList sl; 1992 SockList sl;
1942 int i; 1993 int i;
1943 1994
1944 sl.buf = malloc(MAXSOCKBUF); 1995 sl.buf = malloc(MAXSOCKBUF);
1945 strcpy(sl.buf,"replyinfo spell_paths\n"); 1996 strcpy((char*)sl.buf,"replyinfo spell_paths\n");
1946 for(i=0; i<NRSPELLPATHS; i++) 1997 for(i=0; i<NRSPELLPATHS; i++)
1947 sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); 1998 sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]);
1948 sl.len = strlen(sl.buf); 1999 sl.len = strlen((char*)sl.buf);
1949 if (sl.len > MAXSOCKBUF) { 2000 if (sl.len > MAXSOCKBUF) {
1950 LOG(llevError,"Buffer overflow in send_spell_paths!\n"); 2001 LOG(llevError,"Buffer overflow in send_spell_paths!\n");
1951 fatal(0); 2002 fatal(0);
1952 } 2003 }
1953 Send_With_Handling(ns, &sl); 2004 Send_With_Handling(ns, &sl);
1978 spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); 2029 spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell);
1979 flags |= UPD_SP_DAMAGE; 2030 flags |= UPD_SP_DAMAGE;
1980 } 2031 }
1981 if (flags !=0) { 2032 if (flags !=0) {
1982 sl.buf = malloc(MAXSOCKBUF); 2033 sl.buf = malloc(MAXSOCKBUF);
1983 strcpy(sl.buf,"updspell "); 2034 strcpy((char*)sl.buf,"updspell ");
1984 sl.len=strlen((char*)sl.buf); 2035 sl.len=strlen((char*)sl.buf);
1985 SockList_AddChar(&sl, flags); 2036 SockList_AddChar(&sl, flags);
1986 SockList_AddInt(&sl, spell->count); 2037 SockList_AddInt(&sl, spell->count);
1987 if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); 2038 if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp);
1988 if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); 2039 if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace);
2002 if (!pl || !spell || spell->env != pl->ob) { 2053 if (!pl || !spell || spell->env != pl->ob) {
2003 LOG(llevError, "Invalid call to esrv_remove_spell"); 2054 LOG(llevError, "Invalid call to esrv_remove_spell");
2004 return; 2055 return;
2005 } 2056 }
2006 sl.buf = malloc(MAXSOCKBUF); 2057 sl.buf = malloc(MAXSOCKBUF);
2007 strcpy(sl.buf,"delspell "); 2058 strcpy((char*)sl.buf,"delspell ");
2008 sl.len=strlen((char*)sl.buf); 2059 sl.len=strlen((char*)sl.buf);
2009 SockList_AddInt(&sl, spell->count); 2060 SockList_AddInt(&sl, spell->count);
2010 Send_With_Handling(&pl->socket, &sl); 2061 Send_With_Handling(&pl->socket, &sl);
2011 free(sl.buf); 2062 free(sl.buf);
2012} 2063}
2013 2064
2014/* appends the spell *spell to the Socklist we will send the data to. */ 2065/* appends the spell *spell to the Socklist we will send the data to. */
2015static void append_spell (player *pl, SockList *sl, object *spell) { 2066static void append_spell (player *pl, SockList *sl, object *spell) {
2016 int len, i, skill=0; 2067 int len, i, skill=0;
2017 2068
2018 if (!(spell->name)) { 2069 if (!(spell->name)) {
2019 LOG(llevError, "item number %d is a spell with no name.\n", spell->count); 2070 LOG(llevError, "item number %d is a spell with no name.\n", spell->count);
2020 return; 2071 return;
2021 } 2072 }
2029 /* send the current values */ 2080 /* send the current values */
2030 SockList_AddShort(sl, spell->last_sp); 2081 SockList_AddShort(sl, spell->last_sp);
2031 SockList_AddShort(sl, spell->last_grace); 2082 SockList_AddShort(sl, spell->last_grace);
2032 SockList_AddShort(sl, spell->last_eat); 2083 SockList_AddShort(sl, spell->last_eat);
2033 2084
2034 /* figure out which skill it uses */ 2085 /* figure out which skill it uses, if it uses one */
2086 if (spell->skill) {
2035 for (i=1; i< NUM_SKILLS; i++) 2087 for (i=1; i< NUM_SKILLS; i++)
2036 if (!strcmp(spell->skill, skill_names[i])) { 2088 if (!strcmp(spell->skill, skill_names[i])) {
2037 skill = i+CS_STAT_SKILLINFO; 2089 skill = i+CS_STAT_SKILLINFO;
2038 break; 2090 break;
2039 } 2091 }
2040 skill = i+CS_STAT_SKILLINFO; 2092 }
2041 SockList_AddChar(sl, skill); 2093 SockList_AddChar(sl, skill);
2042 2094
2043 SockList_AddInt(sl, spell->path_attuned); 2095 SockList_AddInt(sl, spell->path_attuned);
2044 SockList_AddInt(sl, (spell->face)?spell->face->number:0); 2096 SockList_AddInt(sl, (spell->face)?spell->face->number:0);
2045 2097
2069 LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2121 LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2070 return; 2122 return;
2071 } 2123 }
2072 if (!pl->socket.monitor_spells) return; 2124 if (!pl->socket.monitor_spells) return;
2073 sl.buf = malloc(MAXSOCKBUF); 2125 sl.buf = malloc(MAXSOCKBUF);
2074 strcpy(sl.buf,"addspell "); 2126 strcpy((char*)sl.buf,"addspell ");
2075 sl.len=strlen((char*)sl.buf); 2127 sl.len=strlen((char*)sl.buf);
2076 if (!spell) { 2128 if (!spell) {
2077 for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { 2129 for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) {
2078 /* were we to simply keep appending data here, we could exceed 2130 /* were we to simply keep appending data here, we could exceed
2079 * MAXSOCKBUF if the player has enough spells to add, we know that 2131 * MAXSOCKBUF if the player has enough spells to add, we know that
2090 */ 2142 */
2091 if (spell->type != SPELL) continue; 2143 if (spell->type != SPELL) continue;
2092 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + 2144 if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) +
2093 (spell->msg?strlen(spell->msg):0)))) { 2145 (spell->msg?strlen(spell->msg):0)))) {
2094 Send_With_Handling(&pl->socket, &sl); 2146 Send_With_Handling(&pl->socket, &sl);
2095 strcpy(sl.buf,"addspell "); 2147 strcpy((char*)sl.buf,"addspell ");
2096 sl.len=strlen((char*)sl.buf); 2148 sl.len=strlen((char*)sl.buf);
2097 } 2149 }
2098 append_spell(pl, &sl, spell); 2150 append_spell(pl, &sl, spell);
2099 } 2151 }
2100 } 2152 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines