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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines