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.53 by root, Sun Jan 31 03:46:20 2010 UTC vs.
Revision 1.60 by root, Fri Jun 18 17:31:01 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
57 * correspond to. 57 * correspond to.
58 */ 58 */
59struct Settings settings = { 59struct Settings settings = {
60 LOGFILE, /* Logfile */ 60 LOGFILE, /* Logfile */
61 CSPORT, /* Client/server port */ 61 CSPORT, /* Client/server port */
62 62 llevTrace, /* Log level */
63/* Debug level */
64#ifdef DEBUG
65 llevDebug,
66#else
67 llevInfo,
68#endif
69
70 0, NULL, 0, /* dumpvalues, dumparg, daemonmode */ 63 0, NULL, 0, /* dumpvalues, dumparg, daemonmode */
71 0, /* argc */ 64 0, /* argc */
72 NULL, /* argv */ 65 NULL, /* argv */
73 CONFDIR, 66 CONFDIR,
74 DATADIR, 67 DATADIR,
93 0, 86 0,
94 0, 87 0,
95 EXPLORE_MODE, 88 EXPLORE_MODE,
96 SPELLPOINT_LEVEL_DEPEND, 89 SPELLPOINT_LEVEL_DEPEND,
97 0, 90 0,
98 1.0, 91 1.25,
99 92
100/* Armor enchantment stuff */ 93/* Armor enchantment stuff */
101 ARMOR_MAX_ENCHANT, 94 ARMOR_MAX_ENCHANT,
102 ARMOR_WEIGHT_REDUCTION, 95 ARMOR_WEIGHT_REDUCTION,
103 ARMOR_WEIGHT_LINEAR, 96 ARMOR_WEIGHT_LINEAR,
161 */ 154 */
162void 155void
163init_globals () 156init_globals ()
164{ 157{
165 if (settings.logfilename[0] == 0) 158 if (settings.logfilename[0] == 0)
166 set_logfd (-1); 159 log_setfd (-1);
167 else 160 else
168 { 161 {
169 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666); 162 int logfd = open (settings.logfilename, O_CREAT|O_WRONLY|O_APPEND, 0666);
170 163
171 if (logfd >= 0) 164 if (logfd >= 0)
172 set_logfd (logfd); 165 log_setfd (logfd);
173 else 166 else
174 { 167 {
175 set_logfd (-1); 168 log_setfd (-1);
176 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename); 169 LOG (llevError, "Unable to open %s as the logfile - will use stderr instead", settings.logfilename);
177 } 170 }
178 } 171 }
179} 172}
180 173
193//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS]; 186//attackmess_t attack_mess[NROFATTACKMESS][MAXATTACKMESS];
194 187
195void 188void
196init_attackmess () 189init_attackmess ()
197{ 190{
198 char buf[MAX_BUF]; 191 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 192
206 if (has_been_done) 193 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 { 194 {
215 LOG (llevError, "Can't open %s.\n", filename); 195 LOG (llevError, "Can't open %s.\n", thawer.name);
216 return; 196 return;
217 } 197 }
218 198
219 level = 0; 199 int msgnum = -1;
220 while (fgets (buf, MAX_BUF, fp) != NULL) 200 int total = 0;
201
202 while (thawer.kw)
221 { 203 {
222 if (*buf == '#') 204 if (thawer.kw != KW_type)
223 continue; 205 if (!thawer.parse_error ("attackmess file"))
206 break;
224 207
225 if ((cp = strchr (buf, '\n')) != NULL) 208 thawer.get (msgnum);
226 *cp = '\0'; 209 thawer.next ();
227 210
228 cp = buf; 211 int level = 0;
229 while (*cp == ' ') /* Skip blanks */
230 cp++;
231 212
232 if (strncmp (cp, "TYPE:", 5) == 0) 213 while (thawer.kw == KW_hp)
233 { 214 {
234 p = strtok (buf, ":"); 215 // our old friend, dog-slow sscanf
235 p = strtok (NULL, ":"); 216 int hp;
217 char buf1[1024];
218 char buf2[1024];
219 char buf3[1024];
236 220
237 if (mode == 1) 221 if (4 != sscanf (thawer.value_nn, "%d %1023[^|]|%1023[^|]|%1023[^|]",
222 &hp, buf1, buf2, buf3))
223 thawer.parse_error ("attackmess file");
224 else
238 { 225 {
226 if (*buf2 == '-')
227 *buf2 = 0; // sscanf can't parse empty fields, so use "-" as marker
228
239 attack_mess[msgnum][level].level = -1; 229 attack_mess[msgnum][level].level = hp;
240 attack_mess[msgnum][level].buf1 = NULL; 230 attack_mess[msgnum][level].buf1 = strdup (buf1);
241 attack_mess[msgnum][level].buf2 = NULL; 231 attack_mess[msgnum][level].buf2 = strdup (buf2);
242 attack_mess[msgnum][level].buf3 = NULL; 232 attack_mess[msgnum][level].buf3 = strdup (buf3);
233
234 ++level;
235 ++total;
243 } 236 }
244 237
245 level = 0; 238 thawer.next ();
246 msgnum = atoi (p);
247 mode = 1;
248 } 239 }
249 else if (mode == 1) 240
250 {
251 p = strtok (buf, "=");
252 attack_mess[msgnum][level].level = atoi (buf); 241 attack_mess[msgnum][level].level = -1;
253 p = strtok (NULL, "=");
254
255 if (p != NULL)
256 attack_mess[msgnum][level].buf1 = strdup (p); 242 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); 243 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); 244 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 } 245 }
291 246
292 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1); 247 LOG (llevDebug, "got %d messages in %d categories.\n", total, msgnum + 1);
293 close_and_delete (fp, comp);
294} 248}
295 249

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines