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.57 by root, Thu Apr 15 06:05:52 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];
199 char filename[MAX_BUF]; 198 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
206 if (has_been_done)
207 return;
208 else
209 has_been_done = 1;
210 199
211 sprintf (filename, "%s/attackmess", settings.datadir); 200 sprintf (filename, "%s/attackmess", settings.datadir);
212 LOG (llevDebug, "Reading attack messages from %s...\n", filename); 201 LOG (llevDebug, "Reading attack messages from %s...\n", filename);
213 if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) 202
203 object_thawer thawer (filename);
204
205 if (!thawer)
214 { 206 {
215 LOG (llevError, "Can't open %s.\n", filename); 207 LOG (llevError, "Can't open %s.\n", filename);
216 return; 208 return;
217 } 209 }
218 210
219 level = 0; 211 int msgnum = -1;
220 while (fgets (buf, MAX_BUF, fp) != NULL) 212 int total = 0;
213
214 while (thawer.kw)
221 { 215 {
222 if (*buf == '#') 216 if (thawer.kw != KW_type)
223 continue; 217 if (!thawer.parse_error ("attackmess file"))
218 break;
224 219
225 if ((cp = strchr (buf, '\n')) != NULL) 220 thawer.get (msgnum);
226 *cp = '\0'; 221 thawer.next ();
227 222
228 cp = buf; 223 int level = 0;
229 while (*cp == ' ') /* Skip blanks */
230 cp++;
231 224
232 if (strncmp (cp, "TYPE:", 5) == 0) 225 while (thawer.kw == KW_hp)
233 { 226 {
234 p = strtok (buf, ":"); 227 // our old friend, dog-slow sscanf
235 p = strtok (NULL, ":"); 228 int hp;
229 char buf1[1024];
230 char buf2[1024];
231 char buf3[1024];
236 232
237 if (mode == 1) 233 if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]",
234 &hp, buf1, buf2, buf3))
235 thawer.parse_error ("attackmess file");
236 else
238 { 237 {
238 if (*buf2 == '-')
239 *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
240
239 attack_mess[msgnum][level].level = -1; 241 attack_mess[msgnum][level].level = hp;
240 attack_mess[msgnum][level].buf1 = NULL; 242 attack_mess[msgnum][level].buf1 = strdup (buf1);
241 attack_mess[msgnum][level].buf2 = NULL; 243 attack_mess[msgnum][level].buf2 = strdup (buf2);
242 attack_mess[msgnum][level].buf3 = NULL; 244 attack_mess[msgnum][level].buf3 = strdup (buf3);
245
246 ++level;
247 ++total;
243 } 248 }
244 249
245 level = 0; 250 thawer.next ();
246 msgnum = atoi (p);
247 mode = 1;
248 } 251 }
249 else if (mode == 1) 252
250 {
251 p = strtok (buf, "=");
252 attack_mess[msgnum][level].level = atoi (buf); 253 attack_mess[msgnum][level].level = -1;
253 p = strtok (NULL, "=");
254
255 if (p != NULL)
256 attack_mess[msgnum][level].buf1 = strdup (p); 254 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); 255 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); 256 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 } 257 }
291 258
292 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1); 259 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
293 close_and_delete (fp, comp);
294} 260}
295 261

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines