1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: request.c,v 1.1 2006/02/03 07:14:46 root Exp $"; |
3 | * "$Id: request.c,v 1.1.1.3 2006/03/15 14:05:40 elmex 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 | |
… | |
… | |
107 | }; |
107 | }; |
108 | |
108 | |
109 | /** This is the Setup cmd - easy first implementation */ |
109 | /** This is the Setup cmd - easy first implementation */ |
110 | void SetUp(char *buf, int len, NewSocket *ns) |
110 | void SetUp(char *buf, int len, NewSocket *ns) |
111 | { |
111 | { |
112 | int s; |
112 | int s, slen; |
113 | char *cmd, *param, cmdback[HUGE_BUF]; |
113 | char *cmd, *param, cmdback[HUGE_BUF]; |
114 | |
114 | |
115 | /* run through the cmds of setup |
115 | /* run through the cmds of setup |
116 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
116 | * syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
117 | * |
117 | * |
… | |
… | |
137 | |
137 | |
138 | for(;buf[s] && buf[s] != ' ';s++) ; |
138 | for(;buf[s] && buf[s] != ' ';s++) ; |
139 | buf[s++]=0; |
139 | buf[s++]=0; |
140 | while (buf[s] == ' ') s++; |
140 | while (buf[s] == ' ') s++; |
141 | |
141 | |
142 | strcat(cmdback, " "); |
142 | slen = strlen(cmdback); |
143 | strcat(cmdback, cmd); |
143 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
144 | strcat(cmdback, " "); |
144 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
145 | |
145 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
146 | |
146 | |
147 | if (!strcmp(cmd,"sound")) { |
147 | if (!strcmp(cmd,"sound")) { |
148 | ns->sound = atoi(param); |
148 | ns->sound = atoi(param); |
149 | strcat(cmdback, param); |
149 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
150 | } |
150 | } |
151 | else if (!strcmp(cmd,"exp64")) { |
151 | else if (!strcmp(cmd,"exp64")) { |
152 | ns->exp64 = atoi(param); |
152 | ns->exp64 = atoi(param); |
153 | strcat(cmdback, param); |
153 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
154 | } else if (!strcmp(cmd, "spellmon")) { |
154 | } else if (!strcmp(cmd, "spellmon")) { |
155 | ns->monitor_spells = atoi(param); |
155 | ns->monitor_spells = atoi(param); |
156 | strcat(cmdback, param); |
156 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
157 | } else if (!strcmp(cmd,"darkness")) { |
157 | } else if (!strcmp(cmd,"darkness")) { |
158 | ns->darkness = atoi(param); |
158 | ns->darkness = atoi(param); |
159 | strcat(cmdback, param); |
159 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
160 | } else if (!strcmp(cmd,"map1cmd")) { |
160 | } else if (!strcmp(cmd,"map1cmd")) { |
161 | if (atoi(param)) ns->mapmode = Map1Cmd; |
161 | if (atoi(param)) ns->mapmode = Map1Cmd; |
162 | /* if beyond this size, need to use map1cmd no matter what */ |
162 | /* if beyond this size, need to use map1cmd no matter what */ |
163 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
163 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
164 | strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0"); |
164 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
165 | } else if (!strcmp(cmd,"map1acmd")) { |
165 | } else if (!strcmp(cmd,"map1acmd")) { |
166 | if (atoi(param)) ns->mapmode = Map1aCmd; |
166 | if (atoi(param)) ns->mapmode = Map1aCmd; |
167 | /* if beyond this size, need to use map1acmd no matter what */ |
167 | /* if beyond this size, need to use map1acmd no matter what */ |
168 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
168 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
169 | strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0"); |
169 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
170 | } else if (!strcmp(cmd,"newmapcmd")) { |
170 | } else if (!strcmp(cmd,"newmapcmd")) { |
171 | ns->newmapcmd= atoi(param); |
171 | ns->newmapcmd= atoi(param); |
172 | strcat(cmdback, param); |
172 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
173 | } else if (!strcmp(cmd,"facecache")) { |
173 | } else if (!strcmp(cmd,"facecache")) { |
174 | ns->facecache = atoi(param); |
174 | ns->facecache = atoi(param); |
175 | strcat(cmdback, param); |
175 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
176 | } else if (!strcmp(cmd,"faceset")) { |
176 | } else if (!strcmp(cmd,"faceset")) { |
177 | char tmpbuf[20]; |
177 | char tmpbuf[20]; |
178 | int q = atoi(param); |
178 | int q = atoi(param); |
179 | |
179 | |
180 | if (is_valid_faceset(q)) |
180 | if (is_valid_faceset(q)) |
181 | ns->faceset=q; |
181 | ns->faceset=q; |
182 | sprintf(tmpbuf,"%d", ns->faceset); |
182 | sprintf(tmpbuf,"%d", ns->faceset); |
183 | strcat(cmdback, tmpbuf); |
183 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
184 | /* if the client is using faceset, it knows about image2 command */ |
184 | /* if the client is using faceset, it knows about image2 command */ |
185 | ns->image2=1; |
185 | ns->image2=1; |
186 | } else if (!strcmp(cmd,"itemcmd")) { |
186 | } else if (!strcmp(cmd,"itemcmd")) { |
187 | /* Version of the item protocol command to use. Currently, |
187 | /* Version of the item protocol command to use. Currently, |
188 | * only supported versions are 1 and 2. Using a numeric |
188 | * only supported versions are 1 and 2. Using a numeric |
… | |
… | |
194 | strcpy(tmpbuf,"FALSE"); |
194 | strcpy(tmpbuf,"FALSE"); |
195 | } else { |
195 | } else { |
196 | ns->itemcmd = q; |
196 | ns->itemcmd = q; |
197 | sprintf(tmpbuf,"%d", ns->itemcmd); |
197 | sprintf(tmpbuf,"%d", ns->itemcmd); |
198 | } |
198 | } |
199 | strcat(cmdback, tmpbuf); |
199 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
200 | } else if (!strcmp(cmd,"mapsize")) { |
200 | } else if (!strcmp(cmd,"mapsize")) { |
201 | int x, y=0; |
201 | int x, y=0; |
202 | char tmpbuf[MAX_BUF], *cp; |
202 | char tmpbuf[MAX_BUF], *cp; |
203 | |
203 | |
204 | x = atoi(param); |
204 | x = atoi(param); |
… | |
… | |
207 | y = atoi(cp+1); |
207 | y = atoi(cp+1); |
208 | break; |
208 | break; |
209 | } |
209 | } |
210 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
210 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
211 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
211 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
212 | strcat(cmdback, tmpbuf); |
212 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
213 | } else { |
213 | } else { |
214 | ns->mapx = x; |
214 | ns->mapx = x; |
215 | ns->mapy = y; |
215 | ns->mapy = y; |
216 | /* better to send back what we are really using and not the |
216 | /* better to send back what we are really using and not the |
217 | * param as given to us in case it gets parsed differently. |
217 | * param as given to us in case it gets parsed differently. |
218 | */ |
218 | */ |
219 | sprintf(tmpbuf,"%dx%d", x,y); |
219 | sprintf(tmpbuf,"%dx%d", x,y); |
220 | strcat(cmdback, tmpbuf); |
220 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
221 | /* If beyond this size and still using orig map command, need to |
221 | /* If beyond this size and still using orig map command, need to |
222 | * go to map1cmd. |
222 | * go to map1cmd. |
223 | */ |
223 | */ |
224 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
224 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
225 | } |
225 | } |
226 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
226 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
227 | /* Added by tchize |
227 | /* Added by tchize |
228 | * prepare to use the mapextended command |
228 | * prepare to use the mapextended command |
229 | */ |
229 | */ |
230 | char tmpbuf[20]; |
230 | char tmpbuf[20]; |
231 | ns->ext_mapinfos = (atoi(param)); |
231 | ns->ext_mapinfos = (atoi(param)); |
232 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
232 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
233 | strcat(cmdback, tmpbuf); |
233 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
234 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
234 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
235 | /* Added by tchize |
235 | /* Added by tchize |
236 | * prepare to use the extended text commands |
236 | * prepare to use the extended text commands |
237 | * Client toggle this to non zero to get exttext |
237 | * Client toggle this to non zero to get exttext |
238 | */ |
238 | */ |
239 | char tmpbuf[20]; |
239 | char tmpbuf[20]; |
|
|
240 | |
240 | ns->has_readable_type = (atoi(param)); |
241 | ns->has_readable_type = (atoi(param)); |
241 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
242 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
242 | strcat(cmdback, tmpbuf); |
243 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
243 | } else { |
244 | } else { |
244 | /* Didn't get a setup command we understood - |
245 | /* Didn't get a setup command we understood - |
245 | * report a failure to the client. |
246 | * report a failure to the client. |
246 | */ |
247 | */ |
247 | strcat(cmdback, "FALSE"); |
248 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
248 | } |
249 | } |
249 | } /* for processing all the setup commands */ |
250 | } /* for processing all the setup commands */ |
250 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
251 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
251 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
252 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
252 | } |
253 | } |
… | |
… | |
362 | * Basically, it makes no sense to wait for the client to request a |
363 | * 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 |
364 | * 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 |
365 | * if we know the client wants it, might as well push it to the |
365 | * client. |
366 | * client. |
366 | */ |
367 | */ |
367 | void SendSmooth(NewSocket *ns, uint16 face) { |
368 | static void SendSmooth(NewSocket *ns, uint16 face) { |
368 | uint16 smoothface; |
369 | uint16 smoothface; |
369 | uint8 reply[MAX_BUF]; |
370 | uint8 reply[MAX_BUF]; |
370 | SockList sl; |
371 | SockList sl; |
371 | |
372 | |
372 | /* If we can't find a face, return and set it so we won't try to send this |
373 | /* 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); |
618 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
618 | #endif |
619 | #endif |
619 | } |
620 | } |
620 | cp = strchr(cp+1, ' '); |
621 | cp = strchr(cp+1, ' '); |
621 | if (cp) { |
622 | if (cp) { |
622 | LOG(llevDebug,"CS: connection from client of type <%s>\n", cp); |
623 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
623 | |
624 | |
624 | /* This is first implementation - i skip all beta DX clients with it |
625 | /* This is first implementation - i skip all beta DX clients with it |
625 | * Add later stuff here for other clients |
626 | * Add later stuff here for other clients |
626 | */ |
627 | */ |
627 | |
628 | |
… | |
… | |
1736 | sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */ |
1737 | sint16 ax, ay, nx, ny;/* ax and ay goes from 0 to max-size of arrays */ |
1737 | New_Face *face,*floor; |
1738 | New_Face *face,*floor; |
1738 | New_Face *floor2; |
1739 | New_Face *floor2; |
1739 | int d, mflags; |
1740 | int d, mflags; |
1740 | struct Map newmap; |
1741 | struct Map newmap; |
1741 | mapstruct *m; |
1742 | mapstruct *m, *pm; |
1742 | |
1743 | |
1743 | if (pl->type != PLAYER) { |
1744 | if (pl->type != PLAYER) { |
1744 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1745 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1745 | return; |
1746 | return; |
1746 | } |
1747 | } |
1747 | |
1748 | |
|
|
1749 | if (pl->contr->transport) { |
|
|
1750 | pm = pl->contr->transport->map; |
|
|
1751 | } |
|
|
1752 | else |
|
|
1753 | pm = pl->map; |
|
|
1754 | |
1748 | /* IF player is just joining the game, he isn't here yet, so the map |
1755 | /* 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 |
1756 | * can get swapped out. If so, don't try to send them a map. All will |
1750 | * be OK once they really log in. |
1757 | * be OK once they really log in. |
1751 | */ |
1758 | */ |
1752 | if (pl->map==NULL || pl->map->in_memory!=MAP_IN_MEMORY) return; |
1759 | if (pm==NULL || pm->in_memory!=MAP_IN_MEMORY) return; |
1753 | |
1760 | |
1754 | memset(&newmap, 0, sizeof(struct Map)); |
1761 | memset(&newmap, 0, sizeof(struct Map)); |
1755 | |
1762 | |
1756 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
1763 | 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++) { |
1764 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
1758 | ax=i; |
1765 | ax=i; |
1759 | ay=j; |
1766 | ay=j; |
1760 | m = pl->map; |
1767 | m = pm; |
1761 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
1768 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
1762 | if (mflags & P_OUT_OF_MAP) |
1769 | if (mflags & P_OUT_OF_MAP) |
1763 | continue; |
1770 | continue; |
1764 | if (mflags & P_NEED_UPDATE) |
1771 | if (mflags & P_NEED_UPDATE) |
1765 | update_position(m, ax, ay); |
1772 | update_position(m, ax, ay); |
… | |
… | |
1807 | /* note the out_of_map and d>3 checks are both within the same |
1814 | /* note the out_of_map and d>3 checks are both within the same |
1808 | * negation check. |
1815 | * negation check. |
1809 | */ |
1816 | */ |
1810 | nx = i; |
1817 | nx = i; |
1811 | ny = j; |
1818 | ny = j; |
1812 | m = get_map_from_coord(pl->map, &nx, &ny); |
1819 | m = get_map_from_coord(pm, &nx, &ny); |
1813 | if (m && d<4) { |
1820 | if (m && d<4) { |
1814 | face = GET_MAP_FACE(m, nx, ny,0); |
1821 | face = GET_MAP_FACE(m, nx, ny,0); |
1815 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
1822 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
1816 | floor = GET_MAP_FACE(m, nx, ny,2); |
1823 | floor = GET_MAP_FACE(m, nx, ny,2); |
1817 | |
1824 | |
… | |
… | |
1917 | { |
1924 | { |
1918 | SockList sl; |
1925 | SockList sl; |
1919 | int i; |
1926 | int i; |
1920 | |
1927 | |
1921 | sl.buf = malloc(MAXSOCKBUF); |
1928 | sl.buf = malloc(MAXSOCKBUF); |
1922 | strcpy(sl.buf,"replyinfo skill_info\n"); |
1929 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
1923 | for (i=1; i< NUM_SKILLS; i++) { |
1930 | for (i=1; i< NUM_SKILLS; i++) { |
1924 | sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
1931 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
1925 | skill_names[i]); |
1932 | skill_names[i]); |
1926 | } |
1933 | } |
1927 | sl.len = strlen(sl.buf); |
1934 | sl.len = strlen((char*)sl.buf); |
1928 | if (sl.len > MAXSOCKBUF) { |
1935 | if (sl.len > MAXSOCKBUF) { |
1929 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
1936 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
1930 | fatal(0); |
1937 | fatal(0); |
1931 | } |
1938 | } |
1932 | Send_With_Handling(ns, &sl); |
1939 | Send_With_Handling(ns, &sl); |
… | |
… | |
1940 | void send_spell_paths (NewSocket *ns, char *params) { |
1947 | void send_spell_paths (NewSocket *ns, char *params) { |
1941 | SockList sl; |
1948 | SockList sl; |
1942 | int i; |
1949 | int i; |
1943 | |
1950 | |
1944 | sl.buf = malloc(MAXSOCKBUF); |
1951 | sl.buf = malloc(MAXSOCKBUF); |
1945 | strcpy(sl.buf,"replyinfo spell_paths\n"); |
1952 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
1946 | for(i=0; i<NRSPELLPATHS; i++) |
1953 | for(i=0; i<NRSPELLPATHS; i++) |
1947 | sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
1954 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
1948 | sl.len = strlen(sl.buf); |
1955 | sl.len = strlen((char*)sl.buf); |
1949 | if (sl.len > MAXSOCKBUF) { |
1956 | if (sl.len > MAXSOCKBUF) { |
1950 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
1957 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
1951 | fatal(0); |
1958 | fatal(0); |
1952 | } |
1959 | } |
1953 | Send_With_Handling(ns, &sl); |
1960 | Send_With_Handling(ns, &sl); |
… | |
… | |
1978 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
1985 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
1979 | flags |= UPD_SP_DAMAGE; |
1986 | flags |= UPD_SP_DAMAGE; |
1980 | } |
1987 | } |
1981 | if (flags !=0) { |
1988 | if (flags !=0) { |
1982 | sl.buf = malloc(MAXSOCKBUF); |
1989 | sl.buf = malloc(MAXSOCKBUF); |
1983 | strcpy(sl.buf,"updspell "); |
1990 | strcpy((char*)sl.buf,"updspell "); |
1984 | sl.len=strlen((char*)sl.buf); |
1991 | sl.len=strlen((char*)sl.buf); |
1985 | SockList_AddChar(&sl, flags); |
1992 | SockList_AddChar(&sl, flags); |
1986 | SockList_AddInt(&sl, spell->count); |
1993 | SockList_AddInt(&sl, spell->count); |
1987 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
1994 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
1988 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
1995 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
… | |
… | |
2002 | if (!pl || !spell || spell->env != pl->ob) { |
2009 | if (!pl || !spell || spell->env != pl->ob) { |
2003 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2010 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2004 | return; |
2011 | return; |
2005 | } |
2012 | } |
2006 | sl.buf = malloc(MAXSOCKBUF); |
2013 | sl.buf = malloc(MAXSOCKBUF); |
2007 | strcpy(sl.buf,"delspell "); |
2014 | strcpy((char*)sl.buf,"delspell "); |
2008 | sl.len=strlen((char*)sl.buf); |
2015 | sl.len=strlen((char*)sl.buf); |
2009 | SockList_AddInt(&sl, spell->count); |
2016 | SockList_AddInt(&sl, spell->count); |
2010 | Send_With_Handling(&pl->socket, &sl); |
2017 | Send_With_Handling(&pl->socket, &sl); |
2011 | free(sl.buf); |
2018 | free(sl.buf); |
2012 | } |
2019 | } |
2013 | |
2020 | |
2014 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2021 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2015 | static void append_spell (player *pl, SockList *sl, object *spell) { |
2022 | static void append_spell (player *pl, SockList *sl, object *spell) { |
2016 | int len, i, skill=0; |
2023 | int len, i, skill=0; |
2017 | |
2024 | |
2018 | if (!(spell->name)) { |
2025 | if (!(spell->name)) { |
2019 | LOG(llevError, "item number %d is a spell with no name.\n", spell->count); |
2026 | LOG(llevError, "item number %d is a spell with no name.\n", spell->count); |
2020 | return; |
2027 | return; |
2021 | } |
2028 | } |
… | |
… | |
2029 | /* send the current values */ |
2036 | /* send the current values */ |
2030 | SockList_AddShort(sl, spell->last_sp); |
2037 | SockList_AddShort(sl, spell->last_sp); |
2031 | SockList_AddShort(sl, spell->last_grace); |
2038 | SockList_AddShort(sl, spell->last_grace); |
2032 | SockList_AddShort(sl, spell->last_eat); |
2039 | SockList_AddShort(sl, spell->last_eat); |
2033 | |
2040 | |
2034 | /* figure out which skill it uses */ |
2041 | /* figure out which skill it uses, if it uses one */ |
|
|
2042 | if (spell->skill) { |
2035 | for (i=1; i< NUM_SKILLS; i++) |
2043 | for (i=1; i< NUM_SKILLS; i++) |
2036 | if (!strcmp(spell->skill, skill_names[i])) { |
2044 | if (!strcmp(spell->skill, skill_names[i])) { |
2037 | skill = i+CS_STAT_SKILLINFO; |
2045 | skill = i+CS_STAT_SKILLINFO; |
2038 | break; |
2046 | break; |
2039 | } |
2047 | } |
2040 | skill = i+CS_STAT_SKILLINFO; |
2048 | } |
2041 | SockList_AddChar(sl, skill); |
2049 | SockList_AddChar(sl, skill); |
2042 | |
2050 | |
2043 | SockList_AddInt(sl, spell->path_attuned); |
2051 | SockList_AddInt(sl, spell->path_attuned); |
2044 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2052 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2045 | |
2053 | |
… | |
… | |
2069 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2077 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2070 | return; |
2078 | return; |
2071 | } |
2079 | } |
2072 | if (!pl->socket.monitor_spells) return; |
2080 | if (!pl->socket.monitor_spells) return; |
2073 | sl.buf = malloc(MAXSOCKBUF); |
2081 | sl.buf = malloc(MAXSOCKBUF); |
2074 | strcpy(sl.buf,"addspell "); |
2082 | strcpy((char*)sl.buf,"addspell "); |
2075 | sl.len=strlen((char*)sl.buf); |
2083 | sl.len=strlen((char*)sl.buf); |
2076 | if (!spell) { |
2084 | if (!spell) { |
2077 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2085 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2078 | /* were we to simply keep appending data here, we could exceed |
2086 | /* were we to simply keep appending data here, we could exceed |
2079 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2087 | * MAXSOCKBUF if the player has enough spells to add, we know that |
… | |
… | |
2090 | */ |
2098 | */ |
2091 | if (spell->type != SPELL) continue; |
2099 | if (spell->type != SPELL) continue; |
2092 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2100 | if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + |
2093 | (spell->msg?strlen(spell->msg):0)))) { |
2101 | (spell->msg?strlen(spell->msg):0)))) { |
2094 | Send_With_Handling(&pl->socket, &sl); |
2102 | Send_With_Handling(&pl->socket, &sl); |
2095 | strcpy(sl.buf,"addspell "); |
2103 | strcpy((char*)sl.buf,"addspell "); |
2096 | sl.len=strlen((char*)sl.buf); |
2104 | sl.len=strlen((char*)sl.buf); |
2097 | } |
2105 | } |
2098 | append_spell(pl, &sl, spell); |
2106 | append_spell(pl, &sl, spell); |
2099 | } |
2107 | } |
2100 | } |
2108 | } |