ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/init.C
(Generate patch)

Comparing deliantra/server/common/init.C (file contents):
Revision 1.56 by root, Sun Apr 11 17:27:51 2010 UTC vs.
Revision 1.58 by root, Wed Apr 28 19:49:50 2010 UTC

193//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; 193//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
194 194
195void 195void
196init_attackmess () 196init_attackmess ()
197{ 197{
198 char buf[MAX_BUF]; 198 object_thawer thawer (settings.datadir, "attackmess");
199 char filename[MAX_BUF];
200 char *cp, *p;
201 FILE *fp;
202 static int has_been_done = 0;
203 int msgnum, level, comp;
204 int mode = 0, total = 0;
205 199
206 if (has_been_done) 200 if (!thawer)
207 return;
208 else
209 has_been_done = 1;
210
211 sprintf (filename, "%s/attackmess", settings.datadir);
212 LOG (llevDebug, "Reading attack messages from %s...\n", filename);
213 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL)
214 { 201 {
215 LOG (llevError, "Can't open %s.\n", filename); 202 LOG (llevError, "Can't open %s.\n", thawer.name);
216 return; 203 return;
217 } 204 }
218 205
219 level = 0; 206 int msgnum = -1;
220 while (fgets (buf, MAX_BUF, fp) != NULL) 207 int total = 0;
208
209 while (thawer.kw)
221 { 210 {
222 if (*buf == '#') 211 if (thawer.kw != KW_type)
223 continue; 212 if (!thawer.parse_error ("attackmess file"))
213 break;
224 214
225 if ((cp = strchr (buf, '\n')) != NULL) 215 thawer.get (msgnum);
226 *cp = '\0'; 216 thawer.next ();
227 217
228 cp = buf; 218 int level = 0;
229 while (*cp == ' ') /* Skip blanks */
230 cp++;
231 219
232 if (strncmp (cp, "TYPE:", 5) == 0) 220 while (thawer.kw == KW_hp)
233 { 221 {
234 p = strtok (buf, ":"); 222 // our old friend, dog-slow sscanf
235 p = strtok (NULL, ":"); 223 int hp;
224 char buf1[1024];
225 char buf2[1024];
226 char buf3[1024];
236 227
237 if (mode == 1) 228 if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]",
229 &hp, buf1, buf2, buf3))
230 thawer.parse_error ("attackmess file");
231 else
238 { 232 {
233 if (*buf2 == '-')
234 *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
235
239 attack_mess[msgnum][level].level = -1; 236 attack_mess[msgnum][level].level = hp;
240 attack_mess[msgnum][level].buf1 = NULL; 237 attack_mess[msgnum][level].buf1 = strdup (buf1);
241 attack_mess[msgnum][level].buf2 = NULL; 238 attack_mess[msgnum][level].buf2 = strdup (buf2);
242 attack_mess[msgnum][level].buf3 = NULL; 239 attack_mess[msgnum][level].buf3 = strdup (buf3);
240
241 ++level;
242 ++total;
243 } 243 }
244 244
245 level = 0; 245 thawer.next ();
246 msgnum = atoi (p);
247 mode = 1;
248 } 246 }
249 else if (mode == 1) 247
250 {
251 p = strtok (buf, "=");
252 attack_mess[msgnum][level].level = atoi (buf); 248 attack_mess[msgnum][level].level = -1;
253 p = strtok (NULL, "=");
254
255 if (p != NULL)
256 attack_mess[msgnum][level].buf1 = strdup (p); 249 attack_mess[msgnum][level].buf1 = 0;
257 else
258 attack_mess[msgnum][level].buf1 = strdup ("");
259
260 mode = 2;
261 }
262 else if (mode == 2)
263 {
264 p = strtok (buf, "=");
265 attack_mess[msgnum][level].level = atoi (buf);
266 p = strtok (NULL, "=");
267
268 if (p != NULL)
269 attack_mess[msgnum][level].buf2 = strdup (p); 250 attack_mess[msgnum][level].buf2 = 0;
270 else
271 attack_mess[msgnum][level].buf2 = strdup ("");
272
273 mode = 3;
274 }
275 else if (mode == 3)
276 {
277 p = strtok (buf, "=");
278 attack_mess[msgnum][level].level = atoi (buf);
279 p = strtok (NULL, "=");
280
281 if (p != NULL)
282 attack_mess[msgnum][level].buf3 = strdup (p); 251 attack_mess[msgnum][level].buf3 = 0;
283 else
284 attack_mess[msgnum][level].buf3 = strdup ("");
285
286 mode = 1;
287 level++;
288 total++;
289 }
290 } 252 }
291 253
292 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1); 254 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
293 close_and_delete (fp, comp);
294} 255}
295 256

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines