1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: request.c,v 1.1.1.2 2006/02/22 18:03:29 elmex Exp $"; |
3 | * "$Id: request.c,v 1.5 2006/04/17 06:11:41 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 */ |
|
|
110 | static void |
|
|
111 | check_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 | |
|
|
144 | void 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)); |
|
|
218 | } |
|
|
219 | |
109 | /** This is the Setup cmd - easy first implementation */ |
220 | /** This is the Setup cmd - easy first implementation */ |
110 | void SetUp(char *buf, int len, NewSocket *ns) |
221 | void SetUp(char *buf, int len, NewSocket *ns) |
111 | { |
222 | { |
112 | int s; |
223 | int s, slen; |
113 | char *cmd, *param, cmdback[HUGE_BUF]; |
224 | char *cmd, *param, cmdback[HUGE_BUF]; |
114 | |
225 | |
115 | /* run through the cmds of setup |
226 | /* run through the cmds of setup |
116 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
227 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
117 | * |
228 | * |
… | |
… | |
137 | |
248 | |
138 | for(;buf[s] && buf[s] != ' ';s++) ; |
249 | for(;buf[s] && buf[s] != ' ';s++) ; |
139 | buf[s++]=0; |
250 | buf[s++]=0; |
140 | while (buf[s] == ' ') s++; |
251 | while (buf[s] == ' ') s++; |
141 | |
252 | |
142 | strcat(cmdback, " "); |
253 | slen = strlen(cmdback); |
143 | strcat(cmdback, cmd); |
254 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
144 | strcat(cmdback, " "); |
255 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
145 | |
256 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
146 | |
257 | |
147 | if (!strcmp(cmd,"sound")) { |
258 | if (!strcmp(cmd,"sound")) { |
148 | ns->sound = atoi(param); |
259 | ns->sound = atoi(param); |
149 | strcat(cmdback, param); |
260 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
150 | } |
261 | } |
151 | else if (!strcmp(cmd,"exp64")) { |
262 | else if (!strcmp(cmd,"exp64")) { |
152 | ns->exp64 = atoi(param); |
263 | ns->exp64 = atoi(param); |
153 | strcat(cmdback, param); |
264 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
154 | } else if (!strcmp(cmd, "spellmon")) { |
265 | } else if (!strcmp(cmd, "spellmon")) { |
155 | ns->monitor_spells = atoi(param); |
266 | ns->monitor_spells = atoi(param); |
156 | strcat(cmdback, param); |
267 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
157 | } else if (!strcmp(cmd,"darkness")) { |
268 | } else if (!strcmp(cmd,"darkness")) { |
158 | ns->darkness = atoi(param); |
269 | ns->darkness = atoi(param); |
159 | strcat(cmdback, param); |
270 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
160 | } else if (!strcmp(cmd,"map1cmd")) { |
271 | } else if (!strcmp(cmd,"map1cmd")) { |
161 | if (atoi(param)) ns->mapmode = Map1Cmd; |
272 | if (atoi(param)) ns->mapmode = Map1Cmd; |
162 | /* if beyond this size, need to use map1cmd no matter what */ |
273 | /* if beyond this size, need to use map1cmd no matter what */ |
163 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
274 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
164 | strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0"); |
275 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
165 | } else if (!strcmp(cmd,"map1acmd")) { |
276 | } else if (!strcmp(cmd,"map1acmd")) { |
166 | if (atoi(param)) ns->mapmode = Map1aCmd; |
277 | if (atoi(param)) ns->mapmode = Map1aCmd; |
167 | /* if beyond this size, need to use map1acmd no matter what */ |
278 | /* if beyond this size, need to use map1acmd no matter what */ |
168 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
279 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
169 | strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0"); |
280 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
170 | } else if (!strcmp(cmd,"newmapcmd")) { |
281 | } else if (!strcmp(cmd,"newmapcmd")) { |
171 | ns->newmapcmd= atoi(param); |
282 | ns->newmapcmd= atoi(param); |
172 | strcat(cmdback, param); |
283 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
|
|
284 | // } else if (!strcmp(cmd,"plugincmd")) { |
|
|
285 | // ns->plugincmd = atoi(param); |
|
|
286 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
|
|
287 | } else if (!strcmp(cmd,"mapinfocmd")) { |
|
|
288 | ns->mapinfocmd = atoi(param); |
|
|
289 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
173 | } else if (!strcmp(cmd,"facecache")) { |
290 | } else if (!strcmp(cmd,"facecache")) { |
174 | ns->facecache = atoi(param); |
291 | ns->facecache = atoi(param); |
175 | strcat(cmdback, param); |
292 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
176 | } else if (!strcmp(cmd,"faceset")) { |
293 | } else if (!strcmp(cmd,"faceset")) { |
177 | char tmpbuf[20]; |
294 | char tmpbuf[20]; |
178 | int q = atoi(param); |
295 | int q = atoi(param); |
179 | |
296 | |
180 | if (is_valid_faceset(q)) |
297 | if (is_valid_faceset(q)) |
181 | ns->faceset=q; |
298 | ns->faceset=q; |
182 | sprintf(tmpbuf,"%d", ns->faceset); |
299 | sprintf(tmpbuf,"%d", ns->faceset); |
183 | strcat(cmdback, tmpbuf); |
300 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
184 | /* if the client is using faceset, it knows about image2 command */ |
301 | /* if the client is using faceset, it knows about image2 command */ |
185 | ns->image2=1; |
302 | ns->image2=1; |
186 | } else if (!strcmp(cmd,"itemcmd")) { |
303 | } else if (!strcmp(cmd,"itemcmd")) { |
187 | /* Version of the item protocol command to use. Currently, |
304 | /* Version of the item protocol command to use. Currently, |
188 | * only supported versions are 1 and 2. Using a numeric |
305 | * only supported versions are 1 and 2. Using a numeric |
… | |
… | |
194 | strcpy(tmpbuf,"FALSE"); |
311 | strcpy(tmpbuf,"FALSE"); |
195 | } else { |
312 | } else { |
196 | ns->itemcmd = q; |
313 | ns->itemcmd = q; |
197 | sprintf(tmpbuf,"%d", ns->itemcmd); |
314 | sprintf(tmpbuf,"%d", ns->itemcmd); |
198 | } |
315 | } |
199 | strcat(cmdback, tmpbuf); |
316 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
200 | } else if (!strcmp(cmd,"mapsize")) { |
317 | } else if (!strcmp(cmd,"mapsize")) { |
201 | int x, y=0; |
318 | int x, y=0; |
202 | char tmpbuf[MAX_BUF], *cp; |
319 | char tmpbuf[MAX_BUF], *cp; |
203 | |
320 | |
204 | x = atoi(param); |
321 | x = atoi(param); |
… | |
… | |
207 | y = atoi(cp+1); |
324 | y = atoi(cp+1); |
208 | break; |
325 | break; |
209 | } |
326 | } |
210 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
327 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
211 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
328 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
212 | strcat(cmdback, tmpbuf); |
329 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
213 | } else { |
330 | } else { |
214 | ns->mapx = x; |
331 | ns->mapx = x; |
215 | ns->mapy = y; |
332 | ns->mapy = y; |
216 | /* better to send back what we are really using and not the |
333 | /* better to send back what we are really using and not the |
217 | * param as given to us in case it gets parsed differently. |
334 | * param as given to us in case it gets parsed differently. |
218 | */ |
335 | */ |
219 | sprintf(tmpbuf,"%dx%d", x,y); |
336 | sprintf(tmpbuf,"%dx%d", x,y); |
220 | strcat(cmdback, tmpbuf); |
337 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
221 | /* If beyond this size and still using orig map command, need to |
338 | /* If beyond this size and still using orig map command, need to |
222 | * go to map1cmd. |
339 | * go to map1cmd. |
223 | */ |
340 | */ |
224 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
341 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
225 | } |
342 | } |
226 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
343 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
227 | /* Added by tchize |
344 | /* Added by tchize |
228 | * prepare to use the mapextended command |
345 | * prepare to use the mapextended command |
229 | */ |
346 | */ |
230 | char tmpbuf[20]; |
347 | char tmpbuf[20]; |
231 | ns->ext_mapinfos = (atoi(param)); |
348 | ns->ext_mapinfos = (atoi(param)); |
232 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
349 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
233 | strcat(cmdback, tmpbuf); |
350 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
234 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
351 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
235 | /* Added by tchize |
352 | /* Added by tchize |
236 | * prepare to use the extended text commands |
353 | * prepare to use the extended text commands |
237 | * Client toggle this to non zero to get exttext |
354 | * Client toggle this to non zero to get exttext |
238 | */ |
355 | */ |
239 | char tmpbuf[20]; |
356 | char tmpbuf[20]; |
|
|
357 | |
240 | ns->has_readable_type = (atoi(param)); |
358 | ns->has_readable_type = (atoi(param)); |
241 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
359 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
242 | strcat(cmdback, tmpbuf); |
360 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
243 | } else { |
361 | } else { |
244 | /* Didn't get a setup command we understood - |
362 | /* Didn't get a setup command we understood - |
245 | * report a failure to the client. |
363 | * report a failure to the client. |
246 | */ |
364 | */ |
247 | strcat(cmdback, "FALSE"); |
365 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
248 | } |
366 | } |
249 | } /* for processing all the setup commands */ |
367 | } /* for processing all the setup commands */ |
250 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
368 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
251 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
369 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
252 | } |
370 | } |
… | |
… | |
617 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
735 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
618 | #endif |
736 | #endif |
619 | } |
737 | } |
620 | cp = strchr(cp+1, ' '); |
738 | cp = strchr(cp+1, ' '); |
621 | if (cp) { |
739 | if (cp) { |
622 | LOG(llevDebug,"CS: connection from client of type <%s>\n", cp); |
740 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
623 | |
741 | |
624 | /* This is first implementation - i skip all beta DX clients with it |
742 | /* This is first implementation - i skip all beta DX clients with it |
625 | * Add later stuff here for other clients |
743 | * Add later stuff here for other clients |
626 | */ |
744 | */ |
627 | |
745 | |
… | |
… | |
1723 | if (sl.len>startlen || pl->contr->socket.sent_scroll) { |
1841 | if (sl.len>startlen || pl->contr->socket.sent_scroll) { |
1724 | Send_With_Handling(&pl->contr->socket, &sl); |
1842 | Send_With_Handling(&pl->contr->socket, &sl); |
1725 | pl->contr->socket.sent_scroll = 0; |
1843 | pl->contr->socket.sent_scroll = 0; |
1726 | } |
1844 | } |
1727 | free(sl.buf); |
1845 | free(sl.buf); |
|
|
1846 | |
|
|
1847 | check_map_change (pl->contr); |
1728 | } |
1848 | } |
1729 | |
1849 | |
1730 | /** |
1850 | /** |
1731 | * Draws client map. |
1851 | * Draws client map. |
1732 | */ |
1852 | */ |
… | |
… | |
1845 | } |
1965 | } |
1846 | } /* Is a valid space */ |
1966 | } /* Is a valid space */ |
1847 | } |
1967 | } |
1848 | } |
1968 | } |
1849 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
1969 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
|
|
1970 | |
|
|
1971 | check_map_change (pl->contr); |
1850 | } |
1972 | } |
1851 | |
1973 | |
1852 | |
1974 | |
1853 | void esrv_map_scroll(NewSocket *ns,int dx,int dy) |
1975 | void esrv_map_scroll(NewSocket *ns,int dx,int dy) |
1854 | { |
1976 | { |
… | |
… | |
1923 | { |
2045 | { |
1924 | SockList sl; |
2046 | SockList sl; |
1925 | int i; |
2047 | int i; |
1926 | |
2048 | |
1927 | sl.buf = malloc(MAXSOCKBUF); |
2049 | sl.buf = malloc(MAXSOCKBUF); |
1928 | strcpy(sl.buf,"replyinfo skill_info\n"); |
2050 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
1929 | for (i=1; i< NUM_SKILLS; i++) { |
2051 | for (i=1; i< NUM_SKILLS; i++) { |
1930 | sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2052 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
1931 | skill_names[i]); |
2053 | skill_names[i]); |
1932 | } |
2054 | } |
1933 | sl.len = strlen(sl.buf); |
2055 | sl.len = strlen((char*)sl.buf); |
1934 | if (sl.len > MAXSOCKBUF) { |
2056 | if (sl.len > MAXSOCKBUF) { |
1935 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2057 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
1936 | fatal(0); |
2058 | fatal(0); |
1937 | } |
2059 | } |
1938 | Send_With_Handling(ns, &sl); |
2060 | Send_With_Handling(ns, &sl); |
… | |
… | |
1946 | void send_spell_paths (NewSocket *ns, char *params) { |
2068 | void send_spell_paths (NewSocket *ns, char *params) { |
1947 | SockList sl; |
2069 | SockList sl; |
1948 | int i; |
2070 | int i; |
1949 | |
2071 | |
1950 | sl.buf = malloc(MAXSOCKBUF); |
2072 | sl.buf = malloc(MAXSOCKBUF); |
1951 | strcpy(sl.buf,"replyinfo spell_paths\n"); |
2073 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
1952 | for(i=0; i<NRSPELLPATHS; i++) |
2074 | for(i=0; i<NRSPELLPATHS; i++) |
1953 | sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2075 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
1954 | sl.len = strlen(sl.buf); |
2076 | sl.len = strlen((char*)sl.buf); |
1955 | if (sl.len > MAXSOCKBUF) { |
2077 | if (sl.len > MAXSOCKBUF) { |
1956 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2078 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
1957 | fatal(0); |
2079 | fatal(0); |
1958 | } |
2080 | } |
1959 | Send_With_Handling(ns, &sl); |
2081 | Send_With_Handling(ns, &sl); |
… | |
… | |
1984 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2106 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
1985 | flags |= UPD_SP_DAMAGE; |
2107 | flags |= UPD_SP_DAMAGE; |
1986 | } |
2108 | } |
1987 | if (flags !=0) { |
2109 | if (flags !=0) { |
1988 | sl.buf = malloc(MAXSOCKBUF); |
2110 | sl.buf = malloc(MAXSOCKBUF); |
1989 | strcpy(sl.buf,"updspell "); |
2111 | strcpy((char*)sl.buf,"updspell "); |
1990 | sl.len=strlen((char*)sl.buf); |
2112 | sl.len=strlen((char*)sl.buf); |
1991 | SockList_AddChar(&sl, flags); |
2113 | SockList_AddChar(&sl, flags); |
1992 | SockList_AddInt(&sl, spell->count); |
2114 | SockList_AddInt(&sl, spell->count); |
1993 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2115 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
1994 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2116 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
… | |
… | |
2008 | if (!pl || !spell || spell->env != pl->ob) { |
2130 | if (!pl || !spell || spell->env != pl->ob) { |
2009 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2131 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2010 | return; |
2132 | return; |
2011 | } |
2133 | } |
2012 | sl.buf = malloc(MAXSOCKBUF); |
2134 | sl.buf = malloc(MAXSOCKBUF); |
2013 | strcpy(sl.buf,"delspell "); |
2135 | strcpy((char*)sl.buf,"delspell "); |
2014 | sl.len=strlen((char*)sl.buf); |
2136 | sl.len=strlen((char*)sl.buf); |
2015 | SockList_AddInt(&sl, spell->count); |
2137 | SockList_AddInt(&sl, spell->count); |
2016 | Send_With_Handling(&pl->socket, &sl); |
2138 | Send_With_Handling(&pl->socket, &sl); |
2017 | free(sl.buf); |
2139 | free(sl.buf); |
2018 | } |
2140 | } |
… | |
… | |
2076 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2198 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2077 | return; |
2199 | return; |
2078 | } |
2200 | } |
2079 | if (!pl->socket.monitor_spells) return; |
2201 | if (!pl->socket.monitor_spells) return; |
2080 | sl.buf = malloc(MAXSOCKBUF); |
2202 | sl.buf = malloc(MAXSOCKBUF); |
2081 | strcpy(sl.buf,"addspell "); |
2203 | strcpy((char*)sl.buf,"addspell "); |
2082 | sl.len=strlen((char*)sl.buf); |
2204 | sl.len=strlen((char*)sl.buf); |
2083 | if (!spell) { |
2205 | if (!spell) { |
2084 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2206 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2085 | /* were we to simply keep appending data here, we could exceed |
2207 | /* were we to simply keep appending data here, we could exceed |
2086 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2208 | * MAXSOCKBUF if the player has enough spells to add, we know that |
… | |
… | |
2097 | */ |
2219 | */ |
2098 | if (spell->type != SPELL) continue; |
2220 | if (spell->type != SPELL) continue; |
2099 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2221 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2100 | (spell->msg?strlen(spell->msg):0)))) { |
2222 | (spell->msg?strlen(spell->msg):0)))) { |
2101 | Send_With_Handling(&pl->socket, &sl); |
2223 | Send_With_Handling(&pl->socket, &sl); |
2102 | strcpy(sl.buf,"addspell "); |
2224 | strcpy((char*)sl.buf,"addspell "); |
2103 | sl.len=strlen((char*)sl.buf); |
2225 | sl.len=strlen((char*)sl.buf); |
2104 | } |
2226 | } |
2105 | append_spell(pl, &sl, spell); |
2227 | append_spell(pl, &sl, spell); |
2106 | } |
2228 | } |
2107 | } |
2229 | } |