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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines