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

Comparing deliantra/server/server/init.C (file contents):
Revision 1.69 by root, Tue Dec 30 07:24:16 2008 UTC vs.
Revision 1.83 by root, Sat Apr 23 04:56:56 2011 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,2011 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 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <material.h> 26#include <material.h>
26#include <loader.h>
27#include <sproto.h> 27#include <sproto.h>
28
29//TODO: make this a constructor
30static materialtype_t *
31get_empty_mat (void)
32{
33 materialtype_t *mt;
34 int i;
35
36 mt = new materialtype_t;
37
38 mt->name = shstr_unknown;
39 mt->description = 0;
40
41 for (i = 0; i < NROFATTACKS; i++)
42 {
43 mt->save[i] = 0;
44 mt->mod[i] = 0;
45 }
46
47 mt->chance = 0;
48 mt->difficulty = 0;
49 mt->magic = 0;
50 mt->damage = 0;
51 mt->wc = 0;
52 mt->ac = 0;
53 mt->sp = 0;
54 mt->weight = 100;
55 mt->value = 100;
56 mt->density = 1;
57 mt->next = 0;
58
59 return mt;
60}
61
62void
63load_materials (void)
64{
65 char filename[MAX_BUF];
66
67 sprintf (filename, "%s/materials", settings.datadir);
68 LOG (llevDebug, "Reading material type data from %s...\n", filename);
69
70 //TODO: somehow free old materials, or update them in-place
71 materialt = 0;
72
73 object_thawer thawer (filename);
74
75 if (!thawer)
76 {
77 LOG (llevError, "Cannot open %s for reading\n", filename);
78 goto done;
79 }
80
81 while (thawer.kw != KW_name)
82 {
83 thawer.next ();
84
85 if (thawer.kw == KW_EOF)
86 goto done;
87 }
88
89 materialtype_t *mt;
90
91 for (;;)
92 {
93 switch (thawer.kw)
94 {
95 case KW_name:
96 mt = get_empty_mat ();
97 mt->next = materialt;
98 materialt = mt;
99
100 thawer.get (mt->name);
101 mt->description = mt->name;
102 break;
103
104 case KW_description:
105 thawer.get (mt->description);
106 break;
107
108 case KW_material:
109 thawer.get (mt->material);
110 break;
111
112 case KW_saves:
113 {
114 const char *cp = thawer.get_str () - 1;
115
116 for (int i = 0; i < NROFATTACKS; i++)
117 {
118 if (!cp)
119 {
120 mt->save[i] = 0;
121 continue;
122 }
123
124 int value;
125 ++cp;
126 sscanf (cp, "%d", &value);
127 mt->save[i] = (sint8) value;
128 cp = strchr (cp, ',');
129 }
130 }
131 break;
132
133 case KW_mods:
134 {
135 const char *cp = thawer.get_str () - 1;
136
137 for (int i = 0; i < NROFATTACKS; i++)
138 {
139 if (!cp)
140 {
141 mt->save[i] = 0;
142 continue;
143 }
144
145 ++cp;
146 int value;
147 sscanf (cp, "%d", &value);
148 mt->mod[i] = (sint8) value;
149 cp = strchr (cp, ',');
150 }
151 }
152 break;
153
154 case KW_chance: thawer.get (mt->chance); break;
155 case KW_difficulty: // cf+ alias, not original cf
156 case KW_diff: thawer.get (mt->difficulty); break;
157 case KW_magic: thawer.get (mt->magic); break;
158 case KW_dam: // cf+ alias, not original cf
159 case KW_damage: thawer.get (mt->damage); break;
160 case KW_wc: thawer.get (mt->wc); break;
161 case KW_ac: thawer.get (mt->ac); break;
162 case KW_sp: thawer.get (mt->sp); break;
163 case KW_weight: thawer.get (mt->weight); break;
164 case KW_value: thawer.get (mt->value); break;
165 case KW_density: thawer.get (mt->density); break;
166
167 case KW_EOF:
168 goto done;
169
170 default:
171 if (!thawer.parse_error ("materials file", "materials"))
172 goto done;
173 break;
174 }
175
176 thawer.next ();
177 }
178
179done:
180 if (!materialt)
181 materialt = get_empty_mat ();
182
183 LOG (llevDebug, "Done.\n");
184}
185 28
186/* This loads the settings file. There could be debate whether this should 29/* This loads the settings file. There could be debate whether this should
187 * be here or in the common directory - but since only the server needs this 30 * be here or in the common directory - but since only the server needs this
188 * information, having it here probably makes more sense. 31 * information, having it here probably makes more sense.
189 */ 32 */
190void 33void
191load_settings (void) 34load_settings ()
192{ 35{
193 char buf[MAX_BUF], *cp; 36 object_thawer thawer (settings.confdir, "settings");
194 int has_val, comp;
195 FILE *fp;
196 37
197 sprintf (buf, "%s/settings", settings.confdir); 38 if (!thawer)
198
199 /* We don't require a settings file at current time, but down the road,
200 * there will probably be so many values that not having a settings file
201 * will not be a good thing.
202 */
203 if (!(fp = open_and_uncompress (buf, 0, &comp)))
204 { 39 {
205 LOG (llevError, "Error: No settings file found\n"); 40 LOG (llevError, "Error: No settings file found\n");
206 exit (1); 41 exit (1);
207 } 42 }
208 43
209 while (fgets (buf, MAX_BUF - 1, fp) != NULL) 44 while (thawer.kw)
210 { 45 {
211 if (buf[0] == '#') 46 const char *buf = thawer.kw_str;
212 continue; 47 const char *cp = thawer.value_nn;
213 /* eliminate newline */
214 if ((cp = strrchr (buf, '\n')) != NULL)
215 *cp = '\0';
216 48
217 /* Skip over empty lines */
218 if (buf[0] == 0)
219 continue;
220
221 /* Skip all the spaces and set them to nulls. If not space,
222 * set cp to "" to make strcpy's and the like easier down below.
223 */
224 if ((cp = strchr (buf, ' ')) != NULL)
225 {
226 while (*cp == ' ')
227 *cp++ = 0;
228 has_val = 1;
229 }
230 else
231 {
232 cp = (char *)"";
233 has_val = 0;
234 }
235
236 if (!strcasecmp (buf, "motd"))
237 {
238 if (has_val)
239 strcpy (settings.motd, cp);
240 else
241 LOG (llevError, "load_settings: motd must have a value.\n");
242 }
243 else if (!strcasecmp (buf, "dm_mail"))
244 {
245 if (has_val)
246 strcpy (settings.dm_mail, cp);
247 else
248 LOG (llevError, "load_settings: dm_mail must have a value.\n");
249 }
250 else if (!strcasecmp (buf, "worldmapstartx"))
251 {
252 int size = atoi (cp);
253
254 if (size < 0)
255 LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size);
256 else
257 settings.worldmapstartx = size;
258 }
259 else if (!strcasecmp (buf, "worldmapstarty"))
260 {
261 int size = atoi (cp);
262
263 if (size < 0)
264 LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size);
265 else
266 settings.worldmapstarty = size;
267 }
268 else if (!strcasecmp (buf, "worldmaptilesx"))
269 {
270 int size = atoi (cp);
271
272 if (size < 1)
273 LOG (llevError, "load_settings: worldmaptilesx must be greater " "than 1, %d is invalid\n", size);
274 else
275 settings.worldmaptilesx = size;
276 }
277 else if (!strcasecmp (buf, "worldmaptilesy"))
278 {
279 int size = atoi (cp);
280
281 if (size < 1)
282 LOG (llevError, "load_settings: worldmaptilesy must be greater " "than 1, %d is invalid\n", size);
283 else
284 settings.worldmaptilesy = size;
285 }
286 else if (!strcasecmp (buf, "worldmaptilesizex"))
287 {
288 int size = atoi (cp);
289
290 if (size < 1)
291 LOG (llevError, "load_settings: worldmaptilesizex must be " "greater than 1, %d is invalid\n", size);
292 else
293 settings.worldmaptilesizex = size;
294 }
295 else if (!strcasecmp (buf, "worldmaptilesizey"))
296 {
297 int size = atoi (cp);
298
299 if (size < 1)
300 LOG (llevError, "load_settings: worldmaptilesizey must be " "greater than 1, %d is invalid\n", size);
301 else
302 settings.worldmaptilesizey = size;
303 }
304 else if (!strcasecmp (buf, "dynamiclevel"))
305 {
306 int lev = atoi (cp);
307
308 if (lev < 0)
309 LOG (llevError, "load_settings: dynamiclevel must be " "at least 0, %d is invalid\n", lev);
310 else
311 settings.dynamiclevel = lev;
312 }
313 else if (!strcasecmp (buf, "fastclock"))
314 {
315 int lev = atoi (cp);
316
317 if (lev < 0)
318 LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev);
319 else
320 settings.fastclock = lev;
321 }
322 else if (!strcasecmp (buf, "not_permadeth")) 49 if (!strcmp (buf, "not_permadeth"))
323 { 50 {
324 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 51 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
325 { 52 {
326 settings.not_permadeth = TRUE; 53 settings.not_permadeth = TRUE;
327 } 54 }
328 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 55 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
329 { 56 {
330 settings.not_permadeth = FALSE; 57 settings.not_permadeth = FALSE;
331 } 58 }
332 else 59 else
333 { 60 {
334 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); 61 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp);
335 } 62 }
336 } 63 }
337 else if (!strcasecmp (buf, "resurrection")) 64 else if (!strcmp (buf, "resurrection"))
338 { 65 {
339 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 66 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
340 { 67 {
341 settings.resurrection = TRUE; 68 settings.resurrection = TRUE;
342 } 69 }
343 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 70 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
344 { 71 {
345 settings.resurrection = FALSE; 72 settings.resurrection = FALSE;
346 } 73 }
347 else 74 else
348 { 75 {
349 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); 76 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp);
350 } 77 }
351 } 78 }
352 else if (!strcasecmp (buf, "set_title")) 79 else if (!strcmp (buf, "set_title"))
353 { 80 {
354 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 81 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
355 { 82 {
356 settings.set_title = TRUE; 83 settings.set_title = TRUE;
357 } 84 }
358 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 85 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
359 { 86 {
360 settings.set_title = FALSE; 87 settings.set_title = FALSE;
361 } 88 }
362 else 89 else
363 { 90 {
364 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); 91 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp);
365 } 92 }
366 } 93 }
367 else if (!strcasecmp (buf, "search_items")) 94 else if (!strcmp (buf, "search_items"))
368 { 95 {
369 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 96 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
370 { 97 {
371 settings.search_items = TRUE; 98 settings.search_items = TRUE;
372 } 99 }
373 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 100 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
374 { 101 {
375 settings.search_items = FALSE; 102 settings.search_items = FALSE;
376 } 103 }
377 else 104 else
378 { 105 {
379 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); 106 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp);
380 } 107 }
381 } 108 }
382 else if (!strcasecmp (buf, "spell_encumbrance")) 109 else if (!strcmp (buf, "spell_encumbrance"))
383 { 110 {
384 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 111 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
385 { 112 {
386 settings.spell_encumbrance = TRUE; 113 settings.spell_encumbrance = TRUE;
387 } 114 }
388 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 115 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
389 { 116 {
390 settings.spell_encumbrance = FALSE; 117 settings.spell_encumbrance = FALSE;
391 } 118 }
392 else 119 else
393 { 120 {
394 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); 121 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp);
395 } 122 }
396 } 123 }
397 else if (!strcasecmp (buf, "spell_failure_effects")) 124 else if (!strcmp (buf, "spell_failure_effects"))
398 { 125 {
399 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 126 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
400 { 127 {
401 settings.spell_failure_effects = TRUE; 128 settings.spell_failure_effects = TRUE;
402 } 129 }
403 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 130 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
404 { 131 {
405 settings.spell_failure_effects = FALSE; 132 settings.spell_failure_effects = FALSE;
406 } 133 }
407 else 134 else
408 { 135 {
409 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); 136 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp);
410 } 137 }
411 } 138 }
412 else if (!strcasecmp (buf, "spellpoint_level_depend")) 139 else if (!strcmp (buf, "spellpoint_level_depend"))
413 { 140 {
414 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 141 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
415 { 142 {
416 settings.spellpoint_level_depend = TRUE; 143 settings.spellpoint_level_depend = TRUE;
417 } 144 }
418 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 145 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
419 { 146 {
420 settings.spellpoint_level_depend = FALSE; 147 settings.spellpoint_level_depend = FALSE;
421 } 148 }
422 else 149 else
423 { 150 {
424 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); 151 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp);
425 } 152 }
426 } 153 }
427 else if (!strcasecmp (buf, "stat_loss_on_death")) 154 else if (!strcmp (buf, "stat_loss_on_death"))
428 { 155 {
429 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 156 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
430 { 157 {
431 settings.stat_loss_on_death = TRUE; 158 settings.stat_loss_on_death = TRUE;
432 } 159 }
433 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 160 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
434 { 161 {
435 settings.stat_loss_on_death = FALSE; 162 settings.stat_loss_on_death = FALSE;
436 } 163 }
437 else 164 else
438 { 165 {
439 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); 166 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp);
440 } 167 }
441 } 168 }
442 else if (!strcasecmp (buf, "use_permanent_experience")) 169 else if (!strcmp (buf, "use_permanent_experience"))
443 { 170 {
444 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); 171 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n");
445 } 172 }
446 else if (!strcasecmp (buf, "permanent_experience_percentage")) 173 else if (!strcmp (buf, "permanent_experience_percentage"))
447 { 174 {
448 int val = atoi (cp); 175 int val = atoi (cp);
449 176
450 if (val < 0 || val > 100) 177 if (val < 0 || val > 100)
451 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); 178 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val);
452 else 179 else
453 settings.permanent_exp_ratio = val; 180 settings.permanent_exp_ratio = val;
454 } 181 }
455 else if (!strcasecmp (buf, "death_penalty_percentage")) 182 else if (!strcmp (buf, "death_penalty_percentage"))
456 { 183 {
457 int val = atoi (cp); 184 int val = atoi (cp);
458 185
459 if (val < 0 || val > 100) 186 if (val < 0 || val > 100)
460 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); 187 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val);
461 else 188 else
462 settings.death_penalty_ratio = val; 189 settings.death_penalty_ratio = val;
463 } 190 }
464 else if (!strcasecmp (buf, "death_penalty_levels")) 191 else if (!strcmp (buf, "death_penalty_levels"))
465 { 192 {
466 int val = atoi (cp); 193 int val = atoi (cp);
467 194
468 if (val < 0 || val > 255) 195 if (val < 0 || val > 255)
469 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); 196 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val);
470 else 197 else
471 settings.death_penalty_level = val; 198 settings.death_penalty_level = val;
472 } 199 }
473 else if (!strcasecmp (buf, "balanced_stat_loss")) 200 else if (!strcmp (buf, "balanced_stat_loss"))
474 { 201 {
475 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 202 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
476 { 203 {
477 settings.balanced_stat_loss = TRUE; 204 settings.balanced_stat_loss = TRUE;
478 } 205 }
479 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 206 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
480 { 207 {
481 settings.balanced_stat_loss = FALSE; 208 settings.balanced_stat_loss = FALSE;
482 } 209 }
483 else 210 else
484 { 211 {
485 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); 212 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp);
486 } 213 }
487 } 214 }
488 else if (!strcasecmp (buf, "simple_exp")) 215 else if (!strcmp (buf, "simple_exp"))
489 { 216 {
490 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 217 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
491 { 218 {
492 settings.simple_exp = TRUE; 219 settings.simple_exp = TRUE;
493 } 220 }
494 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 221 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
495 { 222 {
496 settings.simple_exp = FALSE; 223 settings.simple_exp = FALSE;
497 } 224 }
498 else 225 else
499 { 226 {
500 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); 227 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
501 } 228 }
502 } 229 }
503 else if (!strcasecmp (buf, "item_power_factor")) 230 else if (!strcmp (buf, "item_power_factor"))
504 { 231 {
505 float tmp = atof (cp); 232 float tmp = atof (cp);
506 233
507 if (tmp < 0) 234 if (tmp < 0)
508 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); 235 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
509 else 236 else
510 settings.item_power_factor = tmp; 237 settings.item_power_factor = tmp;
511 } 238 }
512 else if (!strcasecmp (buf, "pk_luck_penalty")) 239 else if (!strcmp (buf, "pk_luck_penalty"))
513 { 240 {
514 sint16 val = atoi (cp); 241 sint16 val = atoi (cp);
515 242
516 if (val < -100 || val > 100) 243 if (val < -100 || val > 100)
517 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); 244 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val);
518 else 245 else
519 settings.pk_luck_penalty = val; 246 settings.pk_luck_penalty = val;
520 } 247 }
521 else if (!strcasecmp (buf, "set_friendly_fire")) 248 else if (!strcmp (buf, "set_friendly_fire"))
522 { 249 {
523 int val = atoi (cp); 250 int val = atoi (cp);
524 251
525 if (val < 0 || val > 100) 252 if (val < 0 || val > 100)
526 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); 253 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val);
527 else 254 else
528 settings.set_friendly_fire = val; 255 settings.set_friendly_fire = val;
529 } 256 }
530 else if (!strcasecmp (buf, "armor_max_enchant")) 257 else if (!strcmp (buf, "armor_max_enchant"))
531 { 258 {
532 int max_e = atoi (cp); 259 int max_e = atoi (cp);
533 260
534 if (max_e <= 0) 261 if (max_e <= 0)
535 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); 262 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e);
536 else 263 else
537 settings.armor_max_enchant = max_e; 264 settings.armor_max_enchant = max_e;
538 } 265 }
539 else if (!strcasecmp (buf, "armor_weight_reduction")) 266 else if (!strcmp (buf, "armor_weight_reduction"))
540 { 267 {
541 int wr = atoi (cp); 268 int wr = atoi (cp);
542 269
543 if (wr < 0) 270 if (wr < 0)
544 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); 271 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr);
545 else 272 else
546 settings.armor_weight_reduction = wr; 273 settings.armor_weight_reduction = wr;
547 } 274 }
548 else if (!strcasecmp (buf, "armor_weight_linear")) 275 else if (!strcmp (buf, "armor_weight_linear"))
549 { 276 {
550 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 277 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
551 { 278 {
552 settings.armor_weight_linear = TRUE; 279 settings.armor_weight_linear = TRUE;
553 } 280 }
554 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 281 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
555 { 282 {
556 settings.armor_weight_linear = FALSE; 283 settings.armor_weight_linear = FALSE;
557 } 284 }
558 else 285 else
559 { 286 {
560 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); 287 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
561 } 288 }
562 289
563 } 290 }
564 else if (!strcasecmp (buf, "armor_speed_improvement")) 291 else if (!strcmp (buf, "armor_speed_improvement"))
565 { 292 {
566 int wr = atoi (cp); 293 int wr = atoi (cp);
567 294
568 if (wr < 0) 295 if (wr < 0)
569 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); 296 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr);
570 else 297 else
571 settings.armor_speed_improvement = wr; 298 settings.armor_speed_improvement = wr;
572 } 299 }
573 else if (!strcasecmp (buf, "armor_speed_linear")) 300 else if (!strcmp (buf, "armor_speed_linear"))
574 { 301 {
575 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) 302 if (!strcmp (cp, "on") || !strcmp (cp, "true"))
576 { 303 {
577 settings.armor_speed_linear = TRUE; 304 settings.armor_speed_linear = TRUE;
578 } 305 }
579 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) 306 else if (!strcmp (cp, "off") || !strcmp (cp, "false"))
580 { 307 {
581 settings.armor_speed_linear = FALSE; 308 settings.armor_speed_linear = FALSE;
582 } 309 }
583 else 310 else
584 { 311 {
585 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); 312 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
586 } 313 }
587 314
588 } 315 }
589 else 316 else
590 LOG (llevError, "Unknown value in settings file: %s\n", buf); 317 thawer.parse_error ("settings file");
318
319 thawer.next ();
591 } 320 }
592
593 close_and_delete (fp, comp);
594} 321}
595 322
596/* 323/*
597 * init() is called only once, when starting the program. 324 * init() is called only once, when starting the program.
598 */ 325 */
602 init_done = 0; /* Must be done before init_signal() */ 329 init_done = 0; /* Must be done before init_signal() */
603 330
604 init_environ (); 331 init_environ ();
605 cfperl_init (); 332 cfperl_init ();
606 init_done = 1; 333 init_done = 1;
607}
608
609void
610usage (void)
611{
612 fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n");
613}
614
615void
616help (void)
617{
618
619/* The information in usage is redundant with what is given below, so why call it? */
620
621/* usage();*/
622 printf ("Flags:\n");
623 printf (" -csport <port> Specifies the port to use for the new client/server code.\n");
624 printf (" -d Turns on some debugging.\n");
625 printf (" +d Turns off debugging (useful if server compiled with debugging\n");
626 printf (" as default).\n");
627 printf (" -detach The server will go in the background, closing all\n");
628 printf (" connections to the tty.\n");
629 printf (" -h Display this information.\n");
630 printf (" -log <file> Specifies which file to send output to.\n");
631 printf (" Only has meaning if -detach is specified.\n");
632 printf (" -mon Turns on monster debugging.\n");
633 printf (" -o Prints out info on what was defined at compile time.\n");
634 printf (" -s Display the high-score list.\n");
635 printf (" -score <name or class> Displays all high scores with matching name/class.\n");
636 printf (" -v Print version and contributors.\n");
637 printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n");
638 printf (" -local Read/write local data (hiscore, unique items, etc.)\n");
639 printf (" -maps Sets the directory for maps.\n");
640 printf (" -arch Sets the archetype file to use.\n");
641 printf (" -regions Sets the regions file to use.\n");
642 printf (" -playerdir Sets the directory for the player files.\n");
643 printf (" -templatedir Sets the directory for template generate maps.\n");
644 printf (" -treasures Sets the treasures file to use.\n");
645 printf (" -uniquedir Sets the unique items/maps directory.\n");
646 printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n");
647 printf (" -m Lists out suggested experience for all monsters.\n");
648 printf (" -m2 Dumps out abilities.\n");
649 printf (" -m3 Dumps out artifact information.\n");
650 printf (" -m4 Dumps out spell information.\n");
651 printf (" -m5 Dumps out skill information.\n");
652 printf (" -m6 Dumps out race information.\n");
653 printf (" -m7 Dumps out alchemy information.\n");
654 printf (" -m8 Dumps out gods information.\n");
655 printf (" -m9 Dumps out more alchemy information (formula checking).\n");
656 printf (" -mt <name> Dumps out list of treasures for a monster.\n");
657 exit (0);
658}
659
660void
661init_beforeplay (void)
662{
663 init_artifacts (); /* If not called before, reads all artifacts from file */
664 init_races (); /* overwrite race designations using entries in lib/races file */
665 init_gods (); /* init linked list of gods from archs */
666 init_readable (); /* inits useful arrays for readable texts */
667 init_formulae (); /* If not called before, reads formulae from file */
668} 334}
669 335
670/* Signal handlers: */ 336/* Signal handlers: */
671 337
672static void 338static void
715 signal (SIGINT , SIG_DFL); 381 signal (SIGINT , SIG_DFL);
716 signal (SIGTERM, SIG_DFL); 382 signal (SIGTERM, SIG_DFL);
717} 383}
718 384
719void 385void
720init_signals (void) 386init_signals ()
721{ 387{
722 // large stack, but it's important data we want to save, and it is not usually 388 // large stack, but it's important data we want to save, and it is not usually
723 // being physically allocated anyways 389 // being physically allocated anyways
724 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; 390 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ;
725 391
741 407
742 sa.sa_flags |= SA_ONSTACK; 408 sa.sa_flags |= SA_ONSTACK;
743 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); 409 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0);
744} 410}
745 411
412static racelink *
413get_racelist ()
414{
415 racelink *list = new racelink;
416
417 list->name = 0;
418 list->nrof = 0;
419 list->next = 0;
420 list->member = get_objectlink ();
421
422 return list;
423}
424
425 racelink *
426find_racelink (const char *name)
427{
428 if (name)
429 for (racelink *link = first_race; link; link = link->next)
430 if (!link->name || !strcmp (name, link->name))
431 return link;
432
433 return 0;
434}
435
436static void
437add_to_racelist (const char *race_name, object *op)
438{
439 racelink *race;
440
441 if (!op || !race_name)
442 return;
443
444 race = find_racelink (race_name);
445
446 if (!race)
447 { /* add in a new race list */
448 race = get_racelist ();
449 race->next = first_race;
450 first_race = race;
451 race->name = race_name;
452 }
453
454 if (race->member->ob)
455 {
456 objectlink *tmp = get_objectlink ();
457
458 tmp->next = race->member;
459 race->member = tmp;
460 }
461
462 race->nrof++;
463 race->member->ob = op;
464}
465
746/* init_races() - reads the races file in the lib/ directory, then 466/* init_races() - reads the races file in the lib/ directory, then
747 * overwrites old 'race' entries. This routine allow us to quickly 467 * overwrites old 'race' entries. This routine allow us to quickly
748 * re-configure the 'alignment' of monsters, objects. Useful for 468 * re-configure the 'alignment' of monsters, objects. Useful for
749 * putting together lists of creatures, etc that belong to gods. 469 * putting together lists of creatures, etc that belong to gods.
750 */ 470 */
751void 471static void
752init_races (void) 472init_races ()
753{ 473{
754 FILE *file; 474 FILE *file;
755 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; 475 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
756 archetype *mon = NULL; 476 archetype *mon = NULL;
757 static int init_done = 0; 477 static int init_done = 0;
812 /* set creature race to race value */ 532 /* set creature race to race value */
813 if ((mon = archetype::find (cp)) == NULL) 533 if ((mon = archetype::find (cp)) == NULL)
814 LOG (llevError, "Creature %s in race file lacks archetype\n", cp); 534 LOG (llevError, "Creature %s in race file lacks archetype\n", cp);
815 else 535 else
816 { 536 {
817 if (set_race && (!mon->race || strcmp (mon->race, race))) 537 if (set_race && (!mon->race || strcmp (&mon->race, race)))
818 { 538 {
819 if (mon->race) 539 if (mon->race)
820 LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname); 540 LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname);
821 541
822 mon->race = race; 542 mon->race = race;
823 } 543 }
824 544
825 /* if the arch is a monster, add it to the race list */ 545 /* if the arch is a monster, add it to the race list */
826 if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) 546 if (set_list && mon->flag [FLAG_MONSTER])
827 add_to_racelist (race, mon); 547 add_to_racelist (race, mon);
828 } 548 }
829 } 549 }
830 } 550 }
831 551
832 fclose (file); 552 fclose (file);
833 LOG (llevDebug, "done.\n"); 553 LOG (llevDebug, "done.\n");
834} 554}
835 555
836void 556void
837dump_races (void) 557init_beforeplay ()
838{ 558{
839 racelink *list; 559 init_artifacts (); /* If not called before, reads all artifacts from file */
840 objectlink *tmp; 560 init_races (); /* overwrite race designations using entries in lib/races file */
841 561 init_gods (); /* init linked list of gods from archs */
842 for (list = first_race; list; list = list->next) 562 init_readable (); /* inits useful arrays for readable texts */
843 { 563 init_formulae (); /* If not called before, reads formulae from file */
844 fprintf (stderr, "\nRACE %s:\t", &list->name);
845 for (tmp = list->member; tmp; tmp = tmp->next)
846 fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level);
847 }
848
849 fprintf (stderr, "\n");
850} 564}
851 565
852void
853add_to_racelist (const char *race_name, object *op)
854{
855 racelink *race;
856
857 if (!op || !race_name)
858 return;
859
860 race = find_racelink (race_name);
861
862 if (!race)
863 { /* add in a new race list */
864 race = get_racelist ();
865 race->next = first_race;
866 first_race = race;
867 race->name = race_name;
868 }
869
870 if (race->member->ob)
871 {
872 objectlink *tmp = get_objectlink ();
873
874 tmp->next = race->member;
875 race->member = tmp;
876 }
877
878 race->nrof++;
879 race->member->ob = op;
880}
881
882racelink *
883get_racelist ()
884{
885 racelink *list = new racelink;
886
887 list->name = 0;
888 list->nrof = 0;
889 list->next = 0;
890 list->member = get_objectlink ();
891
892 return list;
893}
894
895racelink *
896find_racelink (const char *name)
897{
898 if (name)
899 for (racelink *link = first_race; link; link = link->next)
900 if (!link->name || !strcmp (name, link->name))
901 return link;
902
903 return 0;
904}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines