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.3 by root, Tue Aug 29 05:03:55 2006 UTC vs.
Revision 1.52 by root, Mon May 28 21:28:36 2007 UTC

1/* 1/*
2 * static char *rcsid_init_c = 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 * "$Id: init.C,v 1.3 2006/08/29 05:03:55 root Exp $"; 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de>
4 */ 23 */
5
6/*
7 CrossFire, A Multiplayer game for X-windows
8
9 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
10 Copyright (C) 1992 Frank Tore Johansen
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 The authors can be reached via e-mail at crossfire-devel@real-time.com
27*/
28 24
29#include <global.h> 25#include <global.h>
30#include <material.h> 26#include <material.h>
31#include <loader.h> 27#include <loader.h>
32#ifndef __CEXTRACT__
33#include <sproto.h> 28#include <sproto.h>
34#endif
35 29
36/* global weathermap */ 30void
37weathermap_t **weathermap; 31set_logfile (char *val)
32{
33 settings.logfilename = val;
34}
38 35
39void set_logfile(char *val) { settings.logfilename=val; } 36void
40void call_version(void) { version(NULL); exit(0); } 37call_version (void)
41void showscores(void) { display_high_score(NULL,9999,NULL); exit(0); } 38{
42void set_debug(void) { settings.debug=llevDebug; } 39 version (NULL);
43void unset_debug(void) { settings.debug=llevInfo; } 40 exit (0);
44void set_mondebug(void) { settings.debug=llevMonster; } 41}
45void set_dumpmon1(void) {settings.dumpvalues=1; }
46void set_dumpmon2(void) {settings.dumpvalues=2; }
47void set_dumpmon3(void) {settings.dumpvalues=3; }
48void set_dumpmon4(void) {settings.dumpvalues=4; }
49void set_dumpmon5(void) {settings.dumpvalues=5; }
50void set_dumpmon6(void) {settings.dumpvalues=6; }
51void set_dumpmon7(void) {settings.dumpvalues=7; }
52void set_dumpmon8(void) {settings.dumpvalues=8; }
53void set_dumpmon9(void) {settings.dumpvalues=9; }
54void set_dumpmont(char *name) {settings.dumpvalues=10; settings.dumparg=name; }
55void set_daemon(void) {settings.daemonmode=1; }
56void set_datadir(char *path) { settings.datadir=path; }
57void set_confdir(char *path) { settings.confdir=path; }
58void set_localdir(char *path) { settings.localdir=path; }
59void set_mapdir(char *path) { settings.mapdir=path; }
60void set_archetypes(char *path) { settings.archetypes=path; }
61void set_regions(char *path) { settings.regions=path; }
62void set_treasures(char *path) { settings.treasures=path; }
63void set_uniquedir(char *path) { settings.uniquedir=path; }
64void set_templatedir(char *path) { settings.templatedir=path; }
65void set_playerdir(char *path) { settings.playerdir=path; }
66void set_tmpdir(char *path) { settings.tmpdir=path; }
67 42
43void
44showscores (void)
45{
46 display_high_score (NULL, 9999, NULL);
47 exit (0);
48}
49
50void
51set_debug (void)
52{
53 settings.debug = llevDebug;
54}
55
56void
57unset_debug (void)
58{
59 settings.debug = llevInfo;
60}
61
62void
63set_mondebug (void)
64{
65 settings.debug = llevMonster;
66}
67
68void
69set_dumpmon1 (void)
70{
71 settings.dumpvalues = 1;
72}
73
74void
75set_dumpmon2 (void)
76{
77 settings.dumpvalues = 2;
78}
79
80void
81set_dumpmon3 (void)
82{
83 settings.dumpvalues = 3;
84}
85
86void
87set_dumpmon4 (void)
88{
89 settings.dumpvalues = 4;
90}
91
92void
93set_dumpmon5 (void)
94{
95 settings.dumpvalues = 5;
96}
97
98void
99set_dumpmon6 (void)
100{
101 settings.dumpvalues = 6;
102}
103
104void
105set_dumpmon7 (void)
106{
107 settings.dumpvalues = 7;
108}
109
110void
111set_dumpmon8 (void)
112{
113 settings.dumpvalues = 8;
114}
115
116void
117set_dumpmon9 (void)
118{
119 settings.dumpvalues = 9;
120}
121
122void
123set_dumpmont (char *name)
124{
125 settings.dumpvalues = 10;
126 settings.dumparg = name;
127}
128
129void
130set_daemon (void)
131{
132 settings.daemonmode = 1;
133}
134
135void
136set_datadir (char *path)
137{
138 settings.datadir = path;
139}
140
141void
142set_confdir (char *path)
143{
144 settings.confdir = path;
145}
146
147void
148set_localdir (char *path)
149{
150 settings.localdir = path;
151}
152
153void
154set_mapdir (char *path)
155{
156 settings.mapdir = path;
157}
158
159void
160set_archetypes (char *path)
161{
162 settings.archetypes = path;
163}
164
165void
166set_regions (char *path)
167{
168 settings.regions = path;
169}
170
171void
172set_treasures (char *path)
173{
174 settings.treasures = path;
175}
176
177void
178set_uniquedir (char *path)
179{
180 settings.uniquedir = path;
181}
182
183void
184set_templatedir (char *path)
185{
186 settings.templatedir = path;
187}
188
189void
190set_playerdir (char *path)
191{
192 settings.playerdir = path;
193}
194
195void
196set_tmpdir (char *path)
197{
198 settings.tmpdir = path;
199}
200
201void
68void showscoresparm(char *data) { 202showscoresparm (char *data)
203{
69 display_high_score(NULL,9999,data); 204 display_high_score (NULL, 9999, data);
70 exit(0); 205 exit (0);
71} 206}
72 207
208void
73void set_csport(char *val) 209set_csport (char *val)
74{ 210{
75 settings.csport=atoi(val); 211 settings.csport = atoi (val);
76#ifndef WIN32 /* ***win32: set_csport: we remove csport error secure check here, do this later */ 212 if (settings.csport <= 0 || settings.csport > 32765 || (settings.csport < 1024 && getuid () != 0))
77 if (settings.csport<=0 || settings.csport>32765 || 213 {
78 (settings.csport<1024 && getuid()!=0)) {
79 LOG(llevError, "%d is an invalid csport number.\n", settings.csport); 214 LOG (llevError, "%d is an invalid csport number.\n", settings.csport);
80 exit(1); 215 exit (1);
81 } 216 }
82#endif /* win32 */
83} 217}
84 218
85/* Most of this is shamelessly stolen from XSysStats. But since that is 219/* Most of this is shamelessly stolen from XSysStats. But since that is
86 * also my program, no problem. 220 * also my program, no problem.
87 */ 221 */
88struct Command_Line_Options { 222struct Command_Line_Options
223{
89 const char *cmd_option; /* how it is called on the command line */ 224 const char *cmd_option; /* how it is called on the command line */
90 uint8 num_args; /* Number or args it takes */ 225 uint8 num_args; /* Number or args it takes */
91 uint8 pass; /* What pass this should be processed on. */ 226 uint8 pass; /* What pass this should be processed on. */
92 void (*func)(); /* function to call when we match this. 227 void (*func) (); /* function to call when we match this.
93 * if num_args is true, than that gets passed 228 * if num_args is true, than that gets passed
94 * to the function, otherwise nothing is passed 229 * to the function, otherwise nothing is passed
95 */ 230 */
96}; 231};
97 232
98/* The way this system works is pretty simple - parse_args takes 233/* The way this system works is pretty simple - parse_args takes
99 * the options passed to the program and a pass number. If an option 234 * the options passed to the program and a pass number. If an option
100 * matches both in name and in pass (and we have enough options), 235 * matches both in name and in pass (and we have enough options),
102 * pass system very easy, and it is very easy to add in new options. 237 * pass system very easy, and it is very easy to add in new options.
103 */ 238 */
104struct Command_Line_Options options[] = { 239struct Command_Line_Options options[] = {
105 240
106/* Pass 1 functions - STuff that can/should be called before we actually 241/* Pass 1 functions - STuff that can/should be called before we actually
107 * initialize any data. 242 * initialise any data.
108 */ 243 */
109{"-h", 0, 1, help}, 244 {"-h", 0, 1, help},
245
110/* Honor -help also, since it is somewhat common */ 246/* Honor -help also, since it is somewhat common */
111{"-help", 0, 1, help}, 247 {"-help", 0, 1, help},
112{"-v", 0, 1, call_version}, 248 {"-v", 0, 1, call_version},
113{"-d", 0, 1, set_debug}, 249 {"-d", 0, 1, set_debug},
114{"+d", 0, 1, unset_debug}, 250 {"+d", 0, 1, unset_debug},
115{"-mon", 0, 1, set_mondebug}, 251 {"-mon", 0, 1, set_mondebug},
116{"-data",1,1, (void (*)())set_datadir}, 252 {"-data", 1, 1, (void (*)()) set_datadir},
117{"-conf",1,1, (void (*)())set_confdir}, 253 {"-conf", 1, 1, (void (*)()) set_confdir},
118{"-local",1,1,(void (*)()) set_localdir}, 254 {"-local", 1, 1, (void (*)()) set_localdir},
119{"-maps", 1, 1,(void (*)()) set_mapdir}, 255 {"-maps", 1, 1, (void (*)()) set_mapdir},
120{"-arch", 1, 1,(void (*)()) set_archetypes}, 256 {"-arch", 1, 1, (void (*)()) set_archetypes},
121{"-regions", 1, 1,(void (*)()) set_regions}, 257 {"-regions", 1, 1, (void (*)()) set_regions},
122{"-playerdir", 1, 1,(void (*)()) set_playerdir}, 258 {"-playerdir", 1, 1, (void (*)()) set_playerdir},
123{"-treasures", 1, 1,(void (*)()) set_treasures}, 259 {"-treasures", 1, 1, (void (*)()) set_treasures},
124{"-uniquedir", 1, 1,(void (*)()) set_uniquedir}, 260 {"-uniquedir", 1, 1, (void (*)()) set_uniquedir},
125{"-templatedir", 1, 1,(void (*)()) set_templatedir}, 261 {"-templatedir", 1, 1, (void (*)()) set_templatedir},
126{"-tmpdir", 1, 1,(void (*)()) set_tmpdir}, 262 {"-tmpdir", 1, 1, (void (*)()) set_tmpdir},
127{"-log", 1, 1,(void (*)()) set_logfile}, 263 {"-log", 1, 1, (void (*)()) set_logfile},
128
129#ifdef WIN32
130/* Windows service stuff */
131{"-regsrv", 0, 1, service_register},
132{"-unregsrv", 0, 1, service_unregister},
133{"-srv", 0, 1, service_handle},
134#endif
135 264
136/* Pass 2 functions. Most of these could probably be in pass 1, 265/* Pass 2 functions. Most of these could probably be in pass 1,
137 * as they don't require much of anything to bet set up. 266 * as they don't require much of anything to bet set up.
138 */ 267 */
139{"-csport", 1, 2,(void (*)()) set_csport}, 268 {"-csport", 1, 2, (void (*)()) set_csport},
140{"-detach", 0, 2, set_daemon}, 269 {"-detach", 0, 2, set_daemon},
141 270
142/* Start of pass 3 information. In theory, by pass 3, all data paths 271/* Start of pass 3 information. In theory, by pass 3, all data paths
143 * and defaults should have been set up. 272 * and defaults should have been set up.
144 */ 273 */
145{"-o", 0, 3, compile_info}, 274 {"-o", 0, 3, compile_info},
146{"-m", 0, 3, set_dumpmon1}, 275 {"-m", 0, 3, set_dumpmon1},
147{"-m2", 0, 3, set_dumpmon2}, 276 {"-m2", 0, 3, set_dumpmon2},
148{"-m3", 0, 3, set_dumpmon3}, 277 {"-m3", 0, 3, set_dumpmon3},
149{"-m4", 0, 3, set_dumpmon4}, 278 {"-m4", 0, 3, set_dumpmon4},
150{"-m5", 0, 3, set_dumpmon5}, 279 {"-m5", 0, 3, set_dumpmon5},
151{"-m6", 0, 3, set_dumpmon6}, 280 {"-m6", 0, 3, set_dumpmon6},
152{"-m7", 0, 3, set_dumpmon7}, 281 {"-m7", 0, 3, set_dumpmon7},
153{"-m8", 0, 3, set_dumpmon8}, 282 {"-m8", 0, 3, set_dumpmon8},
154{"-m9", 0, 3, set_dumpmon9}, 283 {"-m9", 0, 3, set_dumpmon9},
155{"-mt", 1, 3, (void (*)())set_dumpmont}, 284 {"-mt", 1, 3, (void (*)()) set_dumpmont},
156{"-mexp", 0, 3, dump_experience}, 285 {"-mexp", 0, 3, dump_experience},
157{"-s", 0, 3, showscores}, 286 {"-s", 0, 3, showscores},
158{"-score", 1, 3, (void (*)())showscoresparm} 287 {"-score", 1, 3, (void (*)()) showscoresparm}
159}; 288};
160 289
161 290
162/* Note since this may be called before the library has been set up, 291/* Note since this may be called before the library has been set up,
163 * we don't use any of crossfires built in logging functions. 292 * we don't use any of crossfires built in logging functions.
164 */ 293 */
294static void
165static void parse_args(int argc, char *argv[], int pass) 295parse_args (int argc, char *argv[], int pass)
166{ 296{
167 size_t i; 297 size_t i;
168 int on_arg=1; 298 int on_arg = 1;
169 299
170 while (on_arg<argc) { 300 while (on_arg < argc)
301 {
171 for (i=0; i<sizeof(options)/sizeof(struct Command_Line_Options); i++) { 302 for (i = 0; i < sizeof (options) / sizeof (struct Command_Line_Options); i++)
303 {
172 if (!strcmp(options[i].cmd_option, argv[on_arg])) { 304 if (!strcmp (options[i].cmd_option, argv[on_arg]))
305 {
173 /* Found a matching option, but should not be processed on 306 /* Found a matching option, but should not be processed on
174 * this pass. Just skip over it 307 * this pass. Just skip over it
175 */ 308 */
176 if (options[i].pass != pass) { 309 if (options[i].pass != pass)
310 {
177 on_arg += options[i].num_args+1; 311 on_arg += options[i].num_args + 1;
178 break; 312 break;
179 } 313 }
180 if (options[i].num_args) { 314 if (options[i].num_args)
315 {
181 if ((on_arg+options[i].num_args)>=argc) { 316 if ((on_arg + options[i].num_args) >= argc)
317 {
182 fprintf(stderr,"%s requires an argument.\n", options[i].cmd_option); 318 fprintf (stderr, "%s requires an argument.\n", options[i].cmd_option);
183 exit(1); 319 exit (1);
184 } 320 }
185 else { 321 else
186 if (options[i].num_args==1) 322 {
323 if (options[i].num_args == 1)
187 ((void (*)(char*))options[i].func)(argv[on_arg+1]); 324 ((void (*)(char *)) options[i].func) (argv[on_arg + 1]);
188 if (options[i].num_args==2) 325 if (options[i].num_args == 2)
189 ((void (*)(char*,char*))options[i].func)(argv[on_arg+1],argv[on_arg+2]); 326 ((void (*)(char *, char *)) options[i].func) (argv[on_arg + 1], argv[on_arg + 2]);
190 on_arg +=options[i].num_args+1; 327 on_arg += options[i].num_args + 1;
191 } 328 }
192 } 329 }
193 else { /* takes no args */ 330 else
194 options[i].func(); 331 { /* takes no args */
195 on_arg++; 332 options[i].func ();
196 } 333 on_arg++;
197 break; 334 }
335 break;
336 }
337 }
338 if (i == sizeof (options) / sizeof (struct Command_Line_Options))
339 {
340 fprintf (stderr, "Unknown option: %s\n", argv[on_arg]);
341 usage ();
342 exit (1);
343 }
198 } 344 }
199 }
200 if (i==sizeof(options)/sizeof(struct Command_Line_Options)) {
201 fprintf(stderr,"Unknown option: %s\n", argv[on_arg]);
202 usage();
203 exit(1);
204 }
205 }
206} 345}
207 346
208static materialtype_t *get_empty_mat(void) { 347//TODO: make this a constructor
348static materialtype_t *
349get_empty_mat (void)
350{
209 materialtype_t *mt; 351 materialtype_t *mt;
210 int i; 352 int i;
211 353
212 mt = (materialtype_t *)malloc(sizeof(materialtype_t)); 354 mt = new materialtype_t;
213 if (mt == NULL) 355
214 fatal(OUT_OF_MEMORY);
215 mt->name = NULL; 356 mt->name = NULL;
216 mt->description = NULL; 357 mt->description = NULL;
217 for (i=0; i < NROFATTACKS; i++) { 358 for (i = 0; i < NROFATTACKS; i++)
359 {
218 mt->save[i] = 0; 360 mt->save[i] = 0;
219 mt->mod[i] = 0; 361 mt->mod[i] = 0;
220 } 362 }
221 mt->chance = 0; 363 mt->chance = 0;
222 mt->difficulty = 0; 364 mt->difficulty = 0;
223 mt->magic = 0; 365 mt->magic = 0;
224 mt->damage = 0; 366 mt->damage = 0;
225 mt->wc = 0; 367 mt->wc = 0;
226 mt->ac = 0; 368 mt->ac = 0;
227 mt->sp = 0; 369 mt->sp = 0;
228 mt->weight = 100; 370 mt->weight = 100;
229 mt->value = 100; 371 mt->value = 100;
230 mt->next = NULL; 372 mt->next = NULL;
231 return mt; 373 return mt;
232} 374}
233 375
376static void
234static void load_materials(void) 377load_materials (void)
235{ 378{
236 char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; 379 char filename[MAX_BUF];
237 FILE *fp;
238 materialtype_t *mt; 380 materialtype_t *mt;
239 int i, value;
240 381
241 sprintf(filename, "%s/materials", settings.datadir); 382 sprintf (filename, "%s/materials", settings.datadir);
242 LOG(llevDebug, "Reading material type data from %s...", filename); 383 LOG (llevDebug, "Reading material type data from %s...\n", filename);
243 if ((fp = fopen(filename, "r")) == NULL) { 384
385 object_thawer thawer (filename);
386
387 if (!thawer)
388 {
244 LOG(llevError, "Cannot open %s for reading\n", filename); 389 LOG (llevError, "Cannot open %s for reading\n", filename);
245 mt = get_empty_mat(); 390 mt = get_empty_mat ();
246 mt->next = NULL; 391 mt->next = 0;
247 materialt = mt; 392 materialt = mt;
248 return; 393 return;
249 } 394 }
395
250 mt = get_empty_mat(); 396 mt = get_empty_mat ();
251 materialt = mt; 397 materialt = mt;
252 while (fgets(buf, MAX_BUF, fp) != NULL) { 398
253 if (*buf=='#') 399 for (;;)
254 continue; 400 {
255 if ((cp=strchr(buf, '\n'))!=NULL) 401 thawer.next ();
256 *cp='\0'; 402
257 cp=buf; 403 switch (thawer.kw)
258 while(*cp==' ') /* Skip blanks */ 404 {
259 cp++; 405 case KW_name:
260 if (!strncmp(cp, "name", 4)) {
261 /* clean up the previous entry */ 406 /* clean up the previous entry */
262 if (mt->next != NULL) { 407 if (mt->next)
263 if (mt->description == NULL) 408 {
264 mt->description = add_string(mt->name); 409 if (!mt->description)
265 mt = mt->next; 410 mt->description = mt->name;
411
412 mt = mt->next;
413 }
414
415 mt->next = get_empty_mat ();
416 thawer.get (mt->name);
417 break;
418
419 case KW_description:
420 thawer.get (mt->description);
421 break;
422
423 case KW_material:
424 thawer.get (mt->material);
425 break;
426
427 case KW_saves:
428 {
429 const char *cp = thawer.get_str () - 1;
430
431 for (int i = 0; i < NROFATTACKS; i++)
432 {
433 if (!cp)
434 {
435 mt->save[i] = 0;
436 continue;
437 }
438
439 int value;
440 ++cp;
441 sscanf (cp, "%d", &value);
442 mt->save[i] = (sint8) value;
443 cp = strchr (cp, ',');
444 }
445 }
446 break;
447
448 case KW_mods:
449 {
450 const char *cp = thawer.get_str () - 1;
451
452 for (int i = 0; i < NROFATTACKS; i++)
453 {
454 if (!cp)
455 {
456 mt->save[i] = 0;
457 continue;
458 }
459
460 ++cp;
461 int value;
462 sscanf (cp, "%d", &value);
463 mt->mod[i] = (sint8) value;
464 cp = strchr (cp, ',');
465 }
466 }
467 break;
468
469 case KW_chance: thawer.get (mt->chance); break;
470 case KW_difficulty: // cf+ alias, not original cf
471 case KW_diff: thawer.get (mt->difficulty); break;
472 case KW_magic: thawer.get (mt->magic); break;
473 case KW_dam: // cf+ alias, not original cf
474 case KW_damage: thawer.get (mt->damage); break;
475 case KW_wc: thawer.get (mt->wc); break;
476 case KW_ac: thawer.get (mt->ac); break;
477 case KW_sp: thawer.get (mt->sp); break;
478 case KW_weight: thawer.get (mt->weight); break;
479 case KW_value: thawer.get (mt->value); break;
480 case KW_density: thawer.get (mt->density); break;
481
482 case KW_EOF:
483 goto done;
484
485 default:
486 if (!thawer.parse_error ("materials file", "materials"))
487 goto done;
488 break;
489 }
266 } 490 }
267 mt->next = get_empty_mat(); 491
268 mt->name = add_string(strchr(cp, ' ') + 1); 492done:
269 } else if (!strncmp(cp, "description", 11)) {
270 mt->description = add_string(strchr(cp, ' ') + 1);
271 } else if (sscanf(cp, "material %d", &value)) {
272 mt->material = value;
273 } else if (!strncmp(cp, "saves", 5)) {
274 cp = strchr(cp, ' ') + 1;
275 for (i=0; i < NROFATTACKS; i++) {
276 if (cp == NULL) {
277 mt->save[i] = 0;
278 continue;
279 }
280 if ((next=strchr(cp,',')) != NULL)
281 *(next++) = '\0';
282 sscanf(cp, "%d", &value);
283 mt->save[i] = (sint8)value;
284 cp = next;
285 }
286 } else if (!strncmp(cp, "mods", 4)) {
287 cp = strchr(cp, ' ') + 1;
288 for (i=0; i < NROFATTACKS; i++) {
289 if (cp == NULL) {
290 mt->save[i] = 0;
291 continue;
292 }
293 if ((next=strchr(cp,',')) != NULL)
294 *(next++) = '\0';
295 sscanf(cp, "%d", &value);
296 mt->mod[i] = (sint8)value;
297 cp = next;
298 }
299 } else if (sscanf(cp, "chance %d\n", &value)) {
300 mt->chance = (sint8)value;
301 } else if (sscanf(cp, "diff %d\n", &value)) {
302 mt->difficulty = (sint8)value;
303 } else if (sscanf(cp, "magic %d\n", &value)) {
304 mt->magic = (sint8)value;
305 } else if (sscanf(cp, "damage %d\n", &value)) {
306 mt->damage= (sint8)value;
307 } else if (sscanf(cp, "wc %d\n", &value)) {
308 mt->wc = (sint8)value;
309 } else if (sscanf(cp, "ac %d\n", &value)) {
310 mt->ac = (sint8)value;
311 } else if (sscanf(cp, "sp %d\n", &value)) {
312 mt->sp = (sint8)value;
313 } else if (sscanf(cp, "weight %d\n", &value)) {
314 mt->weight = value;
315 } else if (sscanf(cp, "value %d\n", &value)) {
316 mt->value = value;
317 }
318 }
319 if (mt->next) 493 if (mt->next)
320 {
321 free(mt->next);
322 mt->next = NULL;
323 } 494 {
495 delete mt->next;
496
497 mt->next = 0;
498 }
499
324 LOG(llevDebug, "Done.\n"); 500 LOG (llevDebug, "Done.\n");
325 fclose(fp);
326} 501}
327 502
328/* This loads the settings file. There could be debate whether this should 503/* This loads the settings file. There could be debate whether this should
329 * be here or in the common directory - but since only the server needs this 504 * be here or in the common directory - but since only the server needs this
330 * information, having it here probably makes more sense. 505 * information, having it here probably makes more sense.
331 */ 506 */
332static void load_settings(void) 507static void
508load_settings (void)
333{ 509{
334 char buf[MAX_BUF],*cp; 510 char buf[MAX_BUF], *cp;
335 int has_val,comp; 511 int has_val, comp;
336 FILE *fp; 512 FILE *fp;
337 513
338 sprintf(buf,"%s/settings",settings.confdir); 514 sprintf (buf, "%s/settings", settings.confdir);
339 515
340 /* We don't require a settings file at current time, but down the road, 516 /* We don't require a settings file at current time, but down the road,
341 * there will probably be so many values that not having a settings file 517 * there will probably be so many values that not having a settings file
342 * will not be a good thing. 518 * will not be a good thing.
343 */ 519 */
344 if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) { 520 if (!(fp = open_and_uncompress (buf, 0, &comp)))
521 {
345 LOG(llevError,"Warning: No settings file found\n"); 522 LOG (llevError, "Error: No settings file found\n");
346 return; 523 exit (1);
347 } 524 }
525
348 while (fgets(buf, MAX_BUF-1, fp) != NULL) { 526 while (fgets (buf, MAX_BUF - 1, fp) != NULL)
349 if (buf[0] == '#') continue; 527 {
528 if (buf[0] == '#')
529 continue;
350 /* eliminate newline */ 530 /* eliminate newline */
351 if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0'; 531 if ((cp = strrchr (buf, '\n')) != NULL)
532 *cp = '\0';
352 533
353 /* Skip over empty lines */ 534 /* Skip over empty lines */
354 if (buf[0] == 0) continue; 535 if (buf[0] == 0)
536 continue;
355 537
356 /* Skip all the spaces and set them to nulls. If not space, 538 /* Skip all the spaces and set them to nulls. If not space,
357 * set cp to "" to make strcpy's and the like easier down below. 539 * set cp to "" to make strcpy's and the like easier down below.
358 */ 540 */
359 if ((cp = strchr(buf,' '))!=NULL) { 541 if ((cp = strchr (buf, ' ')) != NULL)
360 while (*cp==' ') *cp++=0; 542 {
543 while (*cp == ' ')
544 *cp++ = 0;
361 has_val=1; 545 has_val = 1;
362 } else { 546 }
363 cp="";
364 has_val=0;
365 }
366
367 if (!strcasecmp(buf,"metaserver_notification")) {
368 if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) {
369 settings.meta_on=TRUE;
370 } else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) {
371 settings.meta_on=FALSE;
372 } else {
373 LOG(llevError,"load_settings: Unknown value for metaserver_notification: %s\n",
374 cp);
375 }
376 } else if (!strcasecmp(buf,"metaserver_server")) {
377 if (has_val) strcpy(settings.meta_server, cp);
378 else 547 else
379 LOG(llevError,"load_settings: metaserver_server must have a value.\n"); 548 {
549 cp = (char *)"";
550 has_val = 0;
551 }
552
380 } else if (!strcasecmp(buf,"motd")) { 553 if (!strcasecmp (buf, "motd"))
554 {
381 if (has_val) 555 if (has_val)
382 strcpy(settings.motd, cp); 556 strcpy (settings.motd, cp);
383 else 557 else
384 LOG(llevError,"load_settings: motd must have a value.\n"); 558 LOG (llevError, "load_settings: motd must have a value.\n");
559 }
385 } else if (!strcasecmp(buf,"dm_mail")) { 560 else if (!strcasecmp (buf, "dm_mail"))
561 {
386 if (has_val) 562 if (has_val)
387 strcpy(settings.dm_mail, cp); 563 strcpy (settings.dm_mail, cp);
388 else 564 else
389 LOG(llevError,"load_settings: dm_mail must have a value.\n"); 565 LOG (llevError, "load_settings: dm_mail must have a value.\n");
390 } else if (!strcasecmp(buf,"metaserver_host")) { 566 }
391 if (has_val) strcpy(settings.meta_host, cp);
392 else
393 LOG(llevError,"load_settings: metaserver_host must have a value.\n");
394 } else if (!strcasecmp(buf,"metaserver_port")) {
395 int port = atoi(cp);
396
397 if (port<1 || port>65535)
398 LOG(llevError,"load_settings: metaserver_port must be between 1 and 65535, %d is invalid\n",
399 port);
400 else settings.meta_port = port;
401 } else if (!strcasecmp(buf,"metaserver_comment")) {
402 strcpy(settings.meta_comment, cp);
403 } else if (!strcasecmp(buf, "worldmapstartx")) { 567 else if (!strcasecmp (buf, "worldmapstartx"))
568 {
404 int size = atoi(cp); 569 int size = atoi (cp);
405 570
406 if (size < 0) 571 if (size < 0)
407 LOG(llevError, "load_settings: worldmapstartx must be at least " 572 LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size);
408 "0, %d is invalid\n", size); 573 else
409 else
410 settings.worldmapstartx = size; 574 settings.worldmapstartx = size;
575 }
411 } else if (!strcasecmp(buf, "worldmapstarty")) { 576 else if (!strcasecmp (buf, "worldmapstarty"))
577 {
412 int size = atoi(cp); 578 int size = atoi (cp);
413 579
414 if (size < 0) 580 if (size < 0)
415 LOG(llevError, "load_settings: worldmapstarty must be at least " 581 LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size);
416 "0, %d is invalid\n", size); 582 else
417 else
418 settings.worldmapstarty = size; 583 settings.worldmapstarty = size;
584 }
419 } else if (!strcasecmp(buf, "worldmaptilesx")) { 585 else if (!strcasecmp (buf, "worldmaptilesx"))
586 {
420 int size = atoi(cp); 587 int size = atoi (cp);
421 588
422 if (size < 1) 589 if (size < 1)
423 LOG(llevError, "load_settings: worldmaptilesx must be greater " 590 LOG (llevError, "load_settings: worldmaptilesx must be greater " "than 1, %d is invalid\n", size);
424 "than 1, %d is invalid\n", size); 591 else
425 else
426 settings.worldmaptilesx = size; 592 settings.worldmaptilesx = size;
593 }
427 } else if (!strcasecmp(buf, "worldmaptilesy")) { 594 else if (!strcasecmp (buf, "worldmaptilesy"))
595 {
428 int size = atoi(cp); 596 int size = atoi (cp);
429 597
430 if (size < 1) 598 if (size < 1)
431 LOG(llevError, "load_settings: worldmaptilesy must be greater " 599 LOG (llevError, "load_settings: worldmaptilesy must be greater " "than 1, %d is invalid\n", size);
432 "than 1, %d is invalid\n", size); 600 else
433 else
434 settings.worldmaptilesy = size; 601 settings.worldmaptilesy = size;
602 }
435 } else if (!strcasecmp(buf, "worldmaptilesizex")) { 603 else if (!strcasecmp (buf, "worldmaptilesizex"))
604 {
436 int size = atoi(cp); 605 int size = atoi (cp);
437 606
438 if (size < 1) 607 if (size < 1)
439 LOG(llevError, "load_settings: worldmaptilesizex must be " 608 LOG (llevError, "load_settings: worldmaptilesizex must be " "greater than 1, %d is invalid\n", size);
440 "greater than 1, %d is invalid\n", size); 609 else
441 else
442 settings.worldmaptilesizex = size; 610 settings.worldmaptilesizex = size;
611 }
443 } else if (!strcasecmp(buf, "worldmaptilesizey")) { 612 else if (!strcasecmp (buf, "worldmaptilesizey"))
613 {
444 int size = atoi(cp); 614 int size = atoi (cp);
445 615
446 if (size < 1) 616 if (size < 1)
447 LOG(llevError, "load_settings: worldmaptilesizey must be " 617 LOG (llevError, "load_settings: worldmaptilesizey must be " "greater than 1, %d is invalid\n", size);
448 "greater than 1, %d is invalid\n", size); 618 else
449 else
450 settings.worldmaptilesizey = size; 619 settings.worldmaptilesizey = size;
620 }
451 } else if (!strcasecmp(buf, "dynamiclevel")) { 621 else if (!strcasecmp (buf, "dynamiclevel"))
622 {
452 int lev = atoi(cp); 623 int lev = atoi (cp);
453 624
454 if (lev < 0) 625 if (lev < 0)
455 LOG(llevError, "load_settings: dynamiclevel must be " 626 LOG (llevError, "load_settings: dynamiclevel must be " "at least 0, %d is invalid\n", lev);
456 "at least 0, %d is invalid\n", lev); 627 else
457 else
458 settings.dynamiclevel = lev; 628 settings.dynamiclevel = lev;
629 }
459 } else if (!strcasecmp(buf, "fastclock")) { 630 else if (!strcasecmp (buf, "fastclock"))
631 {
460 int lev = atoi(cp); 632 int lev = atoi (cp);
461 633
462 if (lev < 0) 634 if (lev < 0)
463 LOG(llevError, "load_settings: fastclock must be at least 0" 635 LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev);
464 ", %d is invalid\n", lev); 636 else
465 else
466 settings.fastclock = lev; 637 settings.fastclock = lev;
638 }
467 } else if (!strcasecmp(buf, "not_permadeth")) { 639 else if (!strcasecmp (buf, "not_permadeth"))
640 {
468 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 641 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
642 {
469 settings.not_permadeth=TRUE; 643 settings.not_permadeth = TRUE;
644 }
470 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 645 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
646 {
471 settings.not_permadeth=FALSE; 647 settings.not_permadeth = FALSE;
472 } else { 648 }
649 else
650 {
473 LOG(llevError, "load_settings: Unknown value for not_permadeth" 651 LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp);
474 ": %s\n", cp); 652 }
475 } 653 }
476 } else if (!strcasecmp(buf, "resurrection")) { 654 else if (!strcasecmp (buf, "resurrection"))
655 {
477 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 656 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
657 {
478 settings.resurrection=TRUE; 658 settings.resurrection = TRUE;
659 }
479 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 660 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
661 {
480 settings.resurrection=FALSE; 662 settings.resurrection = FALSE;
481 } else { 663 }
664 else
665 {
482 LOG(llevError, "load_settings: Unknown value for resurrection" 666 LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp);
483 ": %s\n", cp); 667 }
484 } 668 }
485 } else if (!strcasecmp(buf, "set_title")) { 669 else if (!strcasecmp (buf, "set_title"))
670 {
486 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 671 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
487 settings.set_title=TRUE; 672 {
673 settings.set_title = TRUE;
674 }
488 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 675 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
489 settings.set_title=FALSE; 676 {
490 } else { 677 settings.set_title = FALSE;
678 }
679 else
680 {
491 LOG(llevError, "load_settings: Unknown value for set_title" 681 LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp);
492 ": %s\n", cp); 682 }
493 } 683 }
494 } else if (!strcasecmp(buf, "search_items")) { 684 else if (!strcasecmp (buf, "search_items"))
685 {
495 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 686 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
687 {
496 settings.search_items=TRUE; 688 settings.search_items = TRUE;
689 }
497 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 690 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
691 {
498 settings.search_items=FALSE; 692 settings.search_items = FALSE;
499 } else { 693 }
694 else
695 {
500 LOG(llevError, "load_settings: Unknown value for search_items" 696 LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp);
501 ": %s\n", cp); 697 }
502 } 698 }
503 } else if (!strcasecmp(buf, "spell_encumbrance")) { 699 else if (!strcasecmp (buf, "spell_encumbrance"))
700 {
504 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 701 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
702 {
505 settings.spell_encumbrance=TRUE; 703 settings.spell_encumbrance = TRUE;
704 }
506 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 705 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
706 {
507 settings.spell_encumbrance=FALSE; 707 settings.spell_encumbrance = FALSE;
508 } else { 708 }
509 LOG(llevError, "load_settings: Unknown value for " 709 else
510 "spell_encumbrance: %s\n", cp); 710 {
511 } 711 LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp);
712 }
713 }
512 } else if (!strcasecmp(buf, "spell_failure_effects")) { 714 else if (!strcasecmp (buf, "spell_failure_effects"))
715 {
513 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 716 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
717 {
514 settings.spell_failure_effects=TRUE; 718 settings.spell_failure_effects = TRUE;
719 }
515 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 720 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
721 {
516 settings.spell_failure_effects=FALSE; 722 settings.spell_failure_effects = FALSE;
517 } else { 723 }
518 LOG(llevError, "load_settings: Unknown value for " 724 else
519 "spell_failure_effects: %s\n", cp); 725 {
520 } 726 LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp);
521 } else if (!strcasecmp(buf, "casting_time")) { 727 }
522 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 728 }
523 settings.casting_time=TRUE;
524 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
525 settings.casting_time=FALSE;
526 } else {
527 LOG(llevError, "load_settings: Unknown value for "
528 "casting_time: %s\n", cp);
529 }
530 } else if (!strcasecmp(buf, "real_wiz")) {
531 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
532 settings.real_wiz=TRUE;
533 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
534 settings.real_wiz=FALSE;
535 } else {
536 LOG(llevError, "load_settings: Unknown value for "
537 "real_wiz: %s\n", cp);
538 }
539 } else if (!strcasecmp(buf, "recycle_tmp_maps")) {
540 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
541 settings.recycle_tmp_maps=TRUE;
542 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
543 settings.recycle_tmp_maps=FALSE;
544 } else {
545 LOG(llevError, "load_settings: Unknown value for "
546 "recycle_tmp_maps: %s\n", cp);
547 }
548 } else if (!strcasecmp(buf, "explore_mode")) {
549 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
550 settings.explore_mode=TRUE;
551 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
552 settings.explore_mode=FALSE;
553 } else {
554 LOG(llevError, "load_settings: Unknown value for "
555 "explore_mode: %s\n", cp);
556 }
557 } else if (!strcasecmp(buf,"who_format")) {
558 if (has_val)
559 strcpy(settings.who_format, cp);
560 } else if (!strcasecmp(buf,"who_wiz_format")) {
561 if (has_val)
562 strcpy(settings.who_wiz_format, cp);
563 } else if (!strcasecmp(buf, "spellpoint_level_depend")) { 729 else if (!strcasecmp (buf, "spellpoint_level_depend"))
730 {
564 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 731 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
732 {
565 settings.spellpoint_level_depend=TRUE; 733 settings.spellpoint_level_depend = TRUE;
734 }
566 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 735 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
736 {
567 settings.spellpoint_level_depend=FALSE; 737 settings.spellpoint_level_depend = FALSE;
568 } else { 738 }
569 LOG(llevError, "load_settings: Unknown value for " 739 else
570 "spellpoint_level_depend: %s\n", cp); 740 {
571 } 741 LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp);
742 }
743 }
572 } else if (!strcasecmp(buf, "stat_loss_on_death")) { 744 else if (!strcasecmp (buf, "stat_loss_on_death"))
745 {
573 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 746 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
747 {
574 settings.stat_loss_on_death=TRUE; 748 settings.stat_loss_on_death = TRUE;
749 }
575 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 750 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
751 {
576 settings.stat_loss_on_death=FALSE; 752 settings.stat_loss_on_death = FALSE;
577 } else { 753 }
578 LOG(llevError, "load_settings: Unknown value for " 754 else
579 "stat_loss_on_death: %s\n", cp); 755 {
580 } 756 LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp);
757 }
758 }
581 } else if (!strcasecmp(buf, "use_permanent_experience")) { 759 else if (!strcasecmp (buf, "use_permanent_experience"))
582 LOG(llevError, "use_permanent_experience is deprecated, use" 760 {
583 "permenent_experience_percentage instead\n"); 761 LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n");
762 }
584 } else if (!strcasecmp(buf, "permanent_experience_percentage")) { 763 else if (!strcasecmp (buf, "permanent_experience_percentage"))
764 {
585 int val = atoi(cp); 765 int val = atoi (cp);
766
586 if (val < 0 || val >100) 767 if (val < 0 || val > 100)
587 LOG(llevError, "load_settings: permenent_experience_percentage" 768 LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val);
588 "must be between 0 and 100, %d is invalid\n", val); 769 else
589 else
590 settings.permanent_exp_ratio = val; 770 settings.permanent_exp_ratio = val;
771 }
591 } else if (!strcasecmp(buf, "death_penalty_percentage")) { 772 else if (!strcasecmp (buf, "death_penalty_percentage"))
773 {
592 int val = atoi(cp); 774 int val = atoi (cp);
775
593 if (val < 0 || val >100) 776 if (val < 0 || val > 100)
594 LOG(llevError, "load_settings: death_penalty_percentage" 777 LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val);
595 "must be between 0 and 100, %d is invalid\n", val); 778 else
596 else
597 settings.death_penalty_ratio = val; 779 settings.death_penalty_ratio = val;
780 }
598 } else if (!strcasecmp(buf, "death_penalty_levels")) { 781 else if (!strcasecmp (buf, "death_penalty_levels"))
782 {
599 int val = atoi(cp); 783 int val = atoi (cp);
784
600 if (val < 0 || val > 255) 785 if (val < 0 || val > 255)
601 LOG(llevError, "load_settings: death_penalty_levels" 786 LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val);
602 "can not be negative, %d is invalid\n", val); 787 else
603 else
604 settings.death_penalty_level = val; 788 settings.death_penalty_level = val;
789 }
605 }else if (!strcasecmp(buf, "balanced_stat_loss")) { 790 else if (!strcasecmp (buf, "balanced_stat_loss"))
791 {
606 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 792 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
793 {
607 settings.balanced_stat_loss=TRUE; 794 settings.balanced_stat_loss = TRUE;
795 }
608 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 796 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
797 {
609 settings.balanced_stat_loss=FALSE; 798 settings.balanced_stat_loss = FALSE;
610 } else { 799 }
611 LOG(llevError, "load_settings: Unknown value for " 800 else
612 "balanced_stat_loss: %s\n", cp); 801 {
613 } 802 LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp);
803 }
804 }
614 } else if (!strcasecmp(buf,"simple_exp")) { 805 else if (!strcasecmp (buf, "simple_exp"))
806 {
615 if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) { 807 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
616 settings.simple_exp=TRUE; 808 {
809 settings.simple_exp = TRUE;
810 }
617 } else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) { 811 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
618 settings.simple_exp=FALSE; 812 {
619 } else { 813 settings.simple_exp = FALSE;
814 }
815 else
816 {
620 LOG(llevError,"load_settings: Unknown value for simple_exp: %s\n", 817 LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp);
621 cp); 818 }
622 } 819 }
623 } else if (!strcasecmp(buf, "item_power_factor")) { 820 else if (!strcasecmp (buf, "item_power_factor"))
821 {
624 float tmp = atof(cp); 822 float tmp = atof (cp);
823
625 if (tmp < 0) 824 if (tmp < 0)
626 LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", 825 LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp);
627 tmp); 826 else
628 else
629 settings.item_power_factor = tmp; 827 settings.item_power_factor = tmp;
828 }
630 } else if (!strcasecmp(buf, "pk_luck_penalty")) { 829 else if (!strcasecmp (buf, "pk_luck_penalty"))
830 {
631 sint16 val = atoi(cp); 831 sint16 val = atoi (cp);
632 832
633 if (val < -100 || val >100) 833 if (val < -100 || val > 100)
634 LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100" 834 LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val);
635 ", %d is invalid\n", val); 835 else
636 else
637 settings.pk_luck_penalty = val; 836 settings.pk_luck_penalty = val;
837 }
638 } else if (!strcasecmp(buf, "set_friendly_fire")) { 838 else if (!strcasecmp (buf, "set_friendly_fire"))
839 {
639 int val = atoi(cp); 840 int val = atoi (cp);
640 841
641#if COZY_SERVER
642 if (val < 0 || val >100) 842 if (val < 0 || val > 100)
643 LOG(llevError, "load_settings: set_friendly_fire must be between 0 an 100" 843 LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val);
644 ", %d is invalid\n", val); 844 else
645#else
646 if (val < 1 || val >100)
647 LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100"
648 ", %d is invalid\n", val);
649#endif
650 else
651 settings.set_friendly_fire = val; 845 settings.set_friendly_fire = val;
846 }
652 } else if ( !strcasecmp( buf, "armor_max_enchant" ) ) { 847 else if (!strcasecmp (buf, "armor_max_enchant"))
848 {
653 int max_e = atoi( cp ); 849 int max_e = atoi (cp);
850
654 if ( max_e <= 0 ) 851 if (max_e <= 0)
655 LOG( llevError, "load_settings: armor_max_enchant is %d\n", max_e ); 852 LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e);
656 else 853 else
657 settings.armor_max_enchant = max_e; 854 settings.armor_max_enchant = max_e;
855 }
658 } else if ( !strcasecmp( buf, "armor_weight_reduction" ) ) { 856 else if (!strcasecmp (buf, "armor_weight_reduction"))
857 {
659 int wr = atoi( cp ); 858 int wr = atoi (cp);
859
660 if ( wr < 0 ) 860 if (wr < 0)
661 LOG( llevError, "load_settings: armor_weight_reduction is %d\n", wr ); 861 LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr);
662 else 862 else
663 settings.armor_weight_reduction = wr; 863 settings.armor_weight_reduction = wr;
864 }
664 } else if ( !strcasecmp( buf, "armor_weight_linear" ) ) { 865 else if (!strcasecmp (buf, "armor_weight_linear"))
866 {
665 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 867 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
868 {
666 settings.armor_weight_linear=TRUE; 869 settings.armor_weight_linear = TRUE;
870 }
667 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 871 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
872 {
668 settings.armor_weight_linear=FALSE; 873 settings.armor_weight_linear = FALSE;
669 } else { 874 }
875 else
876 {
670 LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); 877 LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp);
671 } 878 }
672 879
880 }
673 } else if ( !strcasecmp( buf, "armor_speed_improvement" ) ) { 881 else if (!strcasecmp (buf, "armor_speed_improvement"))
882 {
674 int wr = atoi( cp ); 883 int wr = atoi (cp);
884
675 if ( wr < 0 ) 885 if (wr < 0)
676 LOG( llevError, "load_settings: armor_speed_improvement is %d\n", wr ); 886 LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr);
677 else 887 else
678 settings.armor_speed_improvement = wr; 888 settings.armor_speed_improvement = wr;
889 }
679 } else if ( !strcasecmp( buf, "armor_speed_linear" ) ) { 890 else if (!strcasecmp (buf, "armor_speed_linear"))
680 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
681 settings.armor_speed_linear = TRUE;
682 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
683 settings.armor_speed_linear = FALSE;
684 } else {
685 LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
686 } 891 {
687
688 } else if ( !strcasecmp( buf, "no_player_stealing" ) ) {
689 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) {
690 settings.no_player_stealing = TRUE;
691 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) {
692 settings.no_player_stealing = FALSE;
693 } else {
694 LOG(llevError, "load_settings: unknown value for no_player_stealing: %s\n", cp);
695 }
696
697 } else if ( !strcasecmp( buf, "create_home_portals" ) ) {
698 if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { 892 if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true"))
699 settings.create_home_portals = TRUE; 893 {
894 settings.armor_speed_linear = TRUE;
895 }
700 } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { 896 else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false"))
701 settings.create_home_portals = FALSE; 897 {
898 settings.armor_speed_linear = FALSE;
899 }
702 } else { 900 else
901 {
703 LOG(llevError, "load_settings: Unknown value for create_home_portals: %s\n", cp); 902 LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp);
704 } 903 }
705 904
905 }
706 } else { 906 else
707 LOG(llevError,"Unknown value in settings file: %s\n", buf); 907 LOG (llevError, "Unknown value in settings file: %s\n", buf);
708 }
709 } 908 }
909
710 close_and_delete(fp, comp); 910 close_and_delete (fp, comp);
711} 911}
712
713 912
714/* 913/*
715 * init() is called only once, when starting the program. 914 * init() is called only once, when starting the program.
716 */ 915 */
717 916void
718void init(int argc, char **argv) { 917init (int argc, char **argv)
719 918{
720 init_done=0; /* Must be done before init_signal() */ 919 init_done = 0; /* Must be done before init_signal() */
920 rndm.seed (time (0));
921
721 logfile=stderr; 922 logfile = stderr;
923 init_environ ();
722 parse_args(argc, argv, 1); /* First arg pass - right now it does 924 parse_args (argc, argv, 1); /* First arg pass - right now it does
723 * nothing, but in future specifying the 925 * nothing, but in future specifying the
724 * LibDir in this pass would be reasonable*/ 926 * LibDir in this pass would be reasonable*/
725 927
928 init_anim (); // Must be called before perl
929 cfperl_init ();
726 init_library(); /* Must be called early */ 930 init_library (); /* Must be called early */
727 load_settings(); /* Load the settings file */ 931 load_settings (); /* Load the settings file */
728 init_weather();
729 load_materials(); 932 load_materials ();
730 parse_args(argc, argv, 2); 933 parse_args (argc, argv, 2);
731 fprintf(logfile,"Welcome to CrossFire, v%s\n",VERSION); 934 fprintf (logfile, "Welcome to CrossFire, v%s\n", VERSION);
935 fprintf (logfile, "Copyright (C) 2005, 2006, 2007 Marc Lehmann.\n");
732 fprintf(logfile,"Copyright (C) 1994 Mark Wedel.\n"); 936 fprintf (logfile, "Copyright (C) 1994 Mark Wedel.\n");
733 fprintf(logfile,"Copyright (C) 1992 Frank Tore Johansen.\n"); 937 fprintf (logfile, "Copyright (C) 1992 Frank Tore Johansen.\n");
734 938
735 if (strcmp(settings.dm_mail, "") != 0) { 939 if (strcmp (settings.dm_mail, "") != 0)
940 {
736 fprintf(logfile,"Maintained locally by: %s\n", settings.dm_mail); 941 fprintf (logfile, "Maintained locally by: %s\n", settings.dm_mail);
737 fprintf(logfile,"Questions and bugs should be mailed to above address.\n"); 942 fprintf (logfile, "Questions and bugs should be mailed to above address.\n");
738 } 943 }
739 SRANDOM(time(NULL));
740 944
741 init_startup(); /* Write (C), check shutdown/forbid files */ 945 init_startup (); /* Write (C), check shutdown/forbid files */
946 init_uuid ();
742 init_signals(); /* Sets up signal interceptions */ 947 init_signals (); /* Sets up signal interceptions */
743 init_commands(); /* Sort command tables */ 948 init_commands (); /* Sort command tables */
744 read_map_log(); /* Load up the old temp map files */
745 init_skills(); 949 init_skills ();
746 950
747 parse_args(argc, argv, 3); 951 parse_args (argc, argv, 3);
748 952
749#ifndef WIN32 /* ***win32: no BecomeDaemon in windows */
750 if (settings.daemonmode)
751 logfile = BecomeDaemon(settings.logfilename[0]=='\0'?"logfile":settings.logfilename);
752#endif
753
754 init_beforeplay(); 953 init_beforeplay ();
755 init_ericserver(); 954 init_ericserver ();
756 metaserver_init();
757 init_done=1; 955 init_done = 1;
758} 956}
759 957
760void usage(void) { 958void
761 (void) fprintf(logfile, 959usage (void)
762 "Usage: crossfire [-h] [-<flags>]...\n"); 960{
961 (void) fprintf (logfile, "Usage: crossfire [-h] [-<flags>]...\n");
763} 962}
764 963
765void help(void) { 964void
965help (void)
966{
967
766/* The information in usage is redundant with what is given below, so why call it? */ 968/* The information in usage is redundant with what is given below, so why call it? */
969
767/* usage();*/ 970/* usage();*/
768 printf("Flags:\n"); 971 printf ("Flags:\n");
769 printf(" -csport <port> Specifies the port to use for the new client/server code.\n"); 972 printf (" -csport <port> Specifies the port to use for the new client/server code.\n");
770 printf(" -d Turns on some debugging.\n"); 973 printf (" -d Turns on some debugging.\n");
771 printf(" +d Turns off debugging (useful if server compiled with debugging\n"); 974 printf (" +d Turns off debugging (useful if server compiled with debugging\n");
772 printf(" as default).\n"); 975 printf (" as default).\n");
773 printf(" -detach The server will go in the background, closing all\n"); 976 printf (" -detach The server will go in the background, closing all\n");
774 printf(" connections to the tty.\n"); 977 printf (" connections to the tty.\n");
775 printf(" -h Display this information.\n"); 978 printf (" -h Display this information.\n");
776 printf(" -log <file> Specifies which file to send output to.\n"); 979 printf (" -log <file> Specifies which file to send output to.\n");
777 printf(" Only has meaning if -detach is specified.\n"); 980 printf (" Only has meaning if -detach is specified.\n");
778 printf(" -mon Turns on monster debugging.\n"); 981 printf (" -mon Turns on monster debugging.\n");
779 printf(" -o Prints out info on what was defined at compile time.\n"); 982 printf (" -o Prints out info on what was defined at compile time.\n");
780 printf(" -s Display the high-score list.\n"); 983 printf (" -s Display the high-score list.\n");
781 printf(" -score <name or class> Displays all high scores with matching name/class.\n"); 984 printf (" -score <name or class> Displays all high scores with matching name/class.\n");
782 printf(" -v Print version and contributors.\n"); 985 printf (" -v Print version and contributors.\n");
783 printf(" -data Sets the lib dir (archetypes, treasures, etc.)\n"); 986 printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n");
784 printf(" -local Read/write local data (hiscore, unique items, etc.)\n"); 987 printf (" -local Read/write local data (hiscore, unique items, etc.)\n");
785 printf(" -maps Sets the directory for maps.\n"); 988 printf (" -maps Sets the directory for maps.\n");
786 printf(" -arch Sets the archetype file to use.\n"); 989 printf (" -arch Sets the archetype file to use.\n");
787 printf(" -regions Sets the regions file to use.\n"); 990 printf (" -regions Sets the regions file to use.\n");
788 printf(" -playerdir Sets the directory for the player files.\n"); 991 printf (" -playerdir Sets the directory for the player files.\n");
789 printf(" -templatedir Sets the directory for template generate maps.\n"); 992 printf (" -templatedir Sets the directory for template generate maps.\n");
790 printf(" -treasures Sets the treasures file to use.\n"); 993 printf (" -treasures Sets the treasures file to use.\n");
791 printf(" -uniquedir Sets the unique items/maps directory.\n"); 994 printf (" -uniquedir Sets the unique items/maps directory.\n");
792 printf(" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); 995 printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n");
793 printf(" -m Lists out suggested experience for all monsters.\n"); 996 printf (" -m Lists out suggested experience for all monsters.\n");
794 printf(" -m2 Dumps out abilities.\n"); 997 printf (" -m2 Dumps out abilities.\n");
795 printf(" -m3 Dumps out artifact information.\n"); 998 printf (" -m3 Dumps out artifact information.\n");
796 printf(" -m4 Dumps out spell information.\n"); 999 printf (" -m4 Dumps out spell information.\n");
797 printf(" -m5 Dumps out skill information.\n"); 1000 printf (" -m5 Dumps out skill information.\n");
798 printf(" -m6 Dumps out race information.\n"); 1001 printf (" -m6 Dumps out race information.\n");
799 printf(" -m7 Dumps out alchemy information.\n"); 1002 printf (" -m7 Dumps out alchemy information.\n");
800 printf(" -m8 Dumps out gods information.\n"); 1003 printf (" -m8 Dumps out gods information.\n");
801 printf(" -m9 Dumps out more alchemy information (formula checking).\n"); 1004 printf (" -m9 Dumps out more alchemy information (formula checking).\n");
802 printf(" -mt <name> Dumps out list of treasures for a monster.\n"); 1005 printf (" -mt <name> Dumps out list of treasures for a monster.\n");
803 exit(0); 1006 exit (0);
804} 1007}
805 1008
1009void
806void init_beforeplay(void) { 1010init_beforeplay (void)
807 init_archetypes(); /* If not called before, reads all archetypes from file */ 1011{
808 init_artifacts(); /* If not called before, reads all artifacts from file */ 1012 init_artifacts (); /* If not called before, reads all artifacts from file */
809 init_spells(); /* If not called before, links archtypes used by spells */ 1013 init_spells (); /* If not called before, links archtypes used by spells */
810 init_regions(); /* If not called before, reads all regions from file */
811 init_archetype_pointers(); /* Setup global pointers to archetypes */ 1014 init_archetype_pointers (); /* Setup global pointers to archetypes */
812 init_races(); /* overwrite race designations using entries in lib/races file */ 1015 init_races (); /* overwrite race designations using entries in lib/races file */
813 init_gods(); /* init linked list of gods from archs*/ 1016 init_gods (); /* init linked list of gods from archs */
814 init_readable(); /* inits useful arrays for readable texts */ 1017 init_readable (); /* inits useful arrays for readable texts */
815 init_formulae(); /* If not called before, reads formulae from file */ 1018 init_formulae (); /* If not called before, reads formulae from file */
816 1019
817 switch(settings.dumpvalues) { 1020 switch (settings.dumpvalues)
1021 {
818 case 1: 1022 case 1:
819 print_monsters(); 1023 print_monsters ();
820 exit(0); 1024 exit (0);
821 case 2: 1025 case 2:
822 dump_abilities(); 1026 dump_abilities ();
823 exit(0); 1027 exit (0);
824 case 3: 1028 case 3:
825 dump_artifacts(); 1029 dump_artifacts ();
826 exit(0); 1030 exit (0);
827 case 4: 1031 case 4:
828 dump_spells(); 1032 dump_spells ();
829 exit(0); 1033 exit (0);
830 case 5: 1034 case 5:
831 exit(0); 1035 exit (0);
832 case 6: 1036 case 6:
833 dump_races(); 1037 dump_races ();
834 exit(0); 1038 exit (0);
835 case 7: 1039 case 7:
836 dump_alchemy(); 1040 dump_alchemy ();
837 exit(0); 1041 exit (0);
838 case 8:
839 dump_gods();
840 exit(0);
841 case 9: 1042 case 9:
842 dump_alchemy_costs(); 1043 dump_alchemy_costs ();
843 exit(0); 1044 exit (0);
844 case 10: 1045 case 10:
845 dump_monster_treasure(settings.dumparg); 1046 dump_monster_treasure (settings.dumparg);
846 exit(0); 1047 exit (0);
847 } 1048 }
848} 1049}
849 1050
1051void
850void init_startup(void) { 1052init_startup (void)
1053{
851 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
852 FILE *fp; 1055 FILE *fp;
853 int comp; 1056 int comp;
854 1057
855#ifdef SHUTDOWN_FILE 1058#ifdef SHUTDOWN_FILE
856 sprintf(buf,"%s/%s",settings.confdir,SHUTDOWN_FILE); 1059 sprintf (buf, "%s/%s", settings.confdir, SHUTDOWN_FILE);
857 if ((fp = open_and_uncompress(buf, 0, &comp)) != NULL) { 1060 if ((fp = open_and_uncompress (buf, 0, &comp)) != NULL)
1061 {
858 while (fgets(buf, MAX_BUF-1, fp) != NULL) 1062 while (fgets (buf, MAX_BUF - 1, fp) != NULL)
859 printf("%s", buf); 1063 printf ("%s", buf);
860 close_and_delete(fp, comp); 1064 close_and_delete (fp, comp);
861 exit(1); 1065 exit (1);
862 } 1066 }
863#endif 1067#endif
864 1068
865 if (forbid_play()) { /* Maybe showing highscore should be allowed? */ 1069 if (forbid_play ())
1070 { /* Maybe showing highscore should be allowed? */
866 LOG(llevError, "CrossFire: Playing not allowed.\n"); 1071 LOG (llevError, "CrossFire: Playing not allowed.\n");
867 exit(-1); 1072 exit (-1);
868 } 1073 }
869} 1074}
870 1075
871/* 1076/*
872 * compile_info(): activated with the -o flag. 1077 * compile_info(): activated with the -o flag.
873 * It writes out information on how Imakefile and config.h was configured 1078 * It writes out information on how Imakefile and config.h was configured
874 * at compile time. 1079 * at compile time.
875 */ 1080 */
876 1081
1082void
877void compile_info(void) { 1083compile_info (void)
1084{
878 int i=0; 1085 int i = 0;
1086
879 printf("Non-standard include files:\n"); 1087 printf ("Non-standard include files:\n");
880#if !defined (__STRICT_ANSI__) || defined (__sun__) 1088#if !defined (__STRICT_ANSI__) || defined (__sun__)
881#if !defined (Mips) 1089# if !defined (Mips)
882 printf("<stdlib.h>\n"); 1090 printf ("<stdlib.h>\n");
883 i=1; 1091 i = 1;
884#endif 1092# endif
885#if !defined (MACH) && !defined (sony) 1093# if !defined (MACH) && !defined (sony)
886 printf("<malloc.h>\n"); 1094 printf ("<malloc.h>\n");
887 i=1; 1095 i = 1;
888#endif 1096# endif
889#endif 1097#endif
890#ifndef __STRICT_ANSI__ 1098#ifndef __STRICT_ANSI__
891#ifndef MACH 1099# ifndef MACH
892 printf("<memory.h\n"); 1100 printf ("<memory.h\n");
893 i=1; 1101 i = 1;
894#endif 1102# endif
895#endif 1103#endif
896#ifndef sgi 1104#ifndef sgi
897 printf("<sys/timeb.h>\n"); 1105 printf ("<sys/timeb.h>\n");
898 i=1; 1106 i = 1;
899#endif 1107#endif
900 if(!i) 1108 if (!i)
901 printf("(none)\n"); 1109 printf ("(none)\n");
902 printf("Datadir:\t\t%s\n",settings.datadir); 1110 printf ("Datadir:\t\t%s\n", settings.datadir);
903 printf("Localdir:\t\t%s\n",settings.localdir); 1111 printf ("Localdir:\t\t%s\n", settings.localdir);
904#ifdef PERM_FILE 1112#ifdef PERM_FILE
905 printf("Perm file:\t<ETC>/%s\n",PERM_FILE); 1113 printf ("Perm file:\t<ETC>/%s\n", PERM_FILE);
906#endif 1114#endif
907#ifdef SHUTDOWN_FILE 1115#ifdef SHUTDOWN_FILE
908 printf("Shutdown file:\t<ETC>/%s\n",SHUTDOWN_FILE); 1116 printf ("Shutdown file:\t<ETC>/%s\n", SHUTDOWN_FILE);
909#endif 1117#endif
910 printf("Save player:\t<true>\n"); 1118 printf ("Save player:\t<true>\n");
911 printf("Save mode:\t%4.4o\n",SAVE_MODE); 1119 printf ("Save mode:\t%4.4o\n", SAVE_MODE);
912 printf("Playerdir:\t<VAR>/%s\n",settings.playerdir); 1120 printf ("Playerdir:\t<VAR>/%s\n", settings.playerdir);
913 printf("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); 1121 printf ("Itemsdir:\t<VAR>/%s\n", settings.uniquedir);
914 printf("Tmpdir:\t\t%s\n",settings.tmpdir); 1122 printf ("Tmpdir:\t\t%s\n", settings.tmpdir);
915 printf("Map max timeout:\t%d\n",MAP_MAXTIMEOUT);
916 printf("Max objects:\t%d\n",MAX_OBJECTS);
917#ifdef USE_CALLOC 1123#ifdef USE_CALLOC
918 printf("Use_calloc:\t<true>\n"); 1124 printf ("Use_calloc:\t<true>\n");
919#else 1125#else
920 printf("Use_calloc:\t<false>\n"); 1126 printf ("Use_calloc:\t<false>\n");
921#endif 1127#endif
922 1128
923#ifdef X_EDITOR 1129#ifdef X_EDITOR
924 printf("Editor:\t\t%s\n",X_EDITOR); 1130 printf ("Editor:\t\t%s\n", X_EDITOR);
925#endif 1131#endif
926 1132
927 printf("Max_time:\t%d\n",MAX_TIME); 1133 printf ("Max_time:\t%d\n", MAX_TIME);
928 1134
929#ifdef WIN32 /* ***win32 compile_info(): remove execl... */
930 printf("Logfilename:\t%s\n",settings.logfilename);
931 exit(0);
932#else
933 execl("/bin/uname", "uname", "-a", NULL); 1135 execl ("/bin/uname", "uname", "-a", NULL);
934 LOG(llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror_local(errno)); 1136 LOG (llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror (errno));
935 exit(-1); 1137 exit (-1);
936#endif
937} 1138}
938 1139
939/* Signal handlers: */ 1140/* Signal handlers: */
940 1141
1142static void
1143rec_sigabrt (int i)
1144{
1145 signal (SIGABRT, SIG_DFL);
1146
1147 LOG (llevError, "SIGABRT received.\n");
1148 cleanup ("SIGABRT received", 1);
1149}
1150
1151static void
941void rec_sigsegv(int i) { 1152rec_sigsegv (int i)
1153{
1154 signal (SIGSEGV, SIG_DFL);
1155
942 LOG(llevError,"\nSIGSEGV received.\n"); 1156 LOG (llevError, "SIGSEGV received.\n");
943 fatal_signal(1, 1); 1157 cleanup ("SIGSEGV received", 1);
944} 1158}
945 1159
946void rec_sigint(int i) { 1160static void
947 LOG(llevInfo,"\nSIGINT received.\n");
948 fatal_signal(0, 1);
949}
950
951void rec_sighup(int i) {
952 LOG(llevInfo,"\nSIGHUP received\n");
953 if(init_done) {
954 emergency_save(0);
955 cleanup();
956 }
957 exit(0);
958}
959
960void rec_sigquit(int i) { 1161rec_sigquit (int i)
1162{
1163 signal (SIGQUIT, SIG_IGN);
1164
961 LOG(llevInfo,"\nSIGQUIT received\n"); 1165 LOG (llevInfo, "SIGQUIT received\n");
962 fatal_signal(1, 1); 1166 cleanup ("SIGQUIT received", 1);
963} 1167}
964 1168
1169static void
965void rec_sigbus(int i) { 1170rec_sigbus (int i)
966#ifdef SIGBUS 1171{
1172 signal (SIGBUS, SIG_DFL);
1173
967 LOG(llevError,"\nSIGBUS received\n"); 1174 LOG (llevError, "SIGBUS received\n");
968 fatal_signal(1, 1); 1175 cleanup ("SIGBUS received", 1);
969#endif
970} 1176}
971 1177
972void rec_sigterm(int i) { 1178void
973 LOG(llevInfo,"\nSIGTERM received\n"); 1179reset_signals ()
974 fatal_signal(0, 1); 1180{
1181 signal (SIGABRT, SIG_DFL);
1182 signal (SIGQUIT, SIG_DFL);
1183 signal (SIGSEGV, SIG_DFL);
1184 signal (SIGBUS , SIG_DFL);
1185 signal (SIGINT , SIG_DFL);
1186 signal (SIGTERM, SIG_DFL);
975} 1187}
976 1188
977void fatal_signal(int make_core, int close_sockets) { 1189void
978 if(init_done) {
979 emergency_save(0);
980 clean_tmp_files();
981 }
982 if(make_core)
983 abort();
984 exit(0);
985}
986
987void init_signals(void) { 1190init_signals (void)
988#ifndef WIN32 /* init_signals() remove signals */ 1191{
989 signal(SIGHUP,rec_sighup); 1192 // large stack, but it's important data we want to save, and it is not usually
990 signal(SIGINT,rec_sigint); 1193 // being physically allocated anyways
991 signal(SIGQUIT,rec_sigquit); 1194 const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ;
992 signal(SIGSEGV,rec_sigsegv); 1195
993 signal(SIGPIPE,SIG_IGN); 1196 stack_t ss;
994#ifdef SIGBUS 1197 ss.ss_sp = malloc (stacksize);
995 signal(SIGBUS,rec_sigbus); 1198 ss.ss_flags = 0;
996#endif 1199 ss.ss_size = stacksize;
997 signal(SIGTERM,rec_sigterm); 1200 sigaltstack (&ss, 0);
998#endif 1201
1202 struct sigaction sa;
1203
1204 sigfillset (&sa.sa_mask);
1205 sa.sa_flags = SA_RESTART;
1206
1207 sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0);
1208 sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0);
1209 sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0);
1210 sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0);
1211
1212 sa.sa_flags |= SA_ONSTACK;
1213 sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0);
999} 1214}
1000 1215
1001/* init_races() - reads the races file in the lib/ directory, then 1216/* init_races() - reads the races file in the lib/ directory, then
1002 * overwrites old 'race' entries. This routine allow us to quickly 1217 * overwrites old 'race' entries. This routine allow us to quickly
1003 * re-configure the 'alignment' of monsters, objects. Useful for 1218 * re-configure the 'alignment' of monsters, objects. Useful for
1004 * putting together lists of creatures, etc that belong to gods. 1219 * putting together lists of creatures, etc that belong to gods.
1005 */ 1220 */
1006 1221void
1007void init_races (void) { 1222init_races (void)
1223{
1008 FILE *file; 1224 FILE *file;
1009 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; 1225 char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF];
1010 archetype *mon=NULL; 1226 archetype *mon = NULL;
1011 static int init_done=0; 1227 static int init_done = 0;
1012 1228
1013 if (init_done) return; 1229 if (init_done)
1014 init_done=1;
1015 first_race=NULL;
1016
1017 sprintf(fname,"%s/races",settings.datadir);
1018 LOG(llevDebug, "Reading races from %s...",fname);
1019 if(! (file=fopen(fname,"r"))) {
1020 LOG(llevError, "Cannot open races file %s: %s\n", fname, strerror_local(errno));
1021 return; 1230 return;
1231 init_done = 1;
1232 first_race = 0;
1233
1234 sprintf (fname, "%s/races", settings.datadir);
1235 LOG (llevDebug, "Reading races from %s...\n", fname);
1236 if (!(file = fopen (fname, "r")))
1237 {
1238 LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno));
1239 return;
1022 } 1240 }
1023 1241
1024 while(fgets(buf,MAX_BUF,file)!=NULL) { 1242 while (fgets (buf, MAX_BUF, file) != NULL)
1243 {
1025 int set_race=1,set_list=1; 1244 int set_race = 1, set_list = 1;
1026 if(*buf=='#') continue; 1245
1246 if (*buf == '#')
1247 continue;
1248
1027 if((cp=strchr(buf,'\n'))!=NULL) 1249 if ((cp = strchr (buf, '\n')) != NULL)
1028 *cp='\0'; 1250 *cp = '\0';
1251
1029 cp=buf; 1252 cp = buf;
1030 while(*cp==' '||*cp=='!'||*cp=='@') { 1253 while (*cp == ' ' || *cp == '!' || *cp == '@')
1031 if(*cp=='!') set_race=0; 1254 {
1032 if(*cp=='@') set_list=0; 1255 if (*cp == '!')
1256 set_race = 0;
1257 if (*cp == '@')
1258 set_list = 0;
1033 cp++; 1259 cp++;
1034 } 1260 }
1035 if(sscanf(cp,"RACE %s",variable)) { /* set new race value */ 1261
1262 if (sscanf (cp, "RACE %s", variable))
1263 /* set new race value */
1036 strcpy(race,variable); 1264 strcpy (race, variable);
1037 } else { 1265 else
1038 char *cp1; 1266 {
1267 char *cp1;
1268
1039 /* Take out beginning spaces */ 1269 /* Take out beginning spaces */
1040 for (cp1 = cp; *cp1==' '; cp1++); 1270 for (cp1 = cp; *cp1 == ' '; cp1++)
1271 ;
1041 /* Remove newline and trailing spaces */ 1272 /* Remove newline and trailing spaces */
1042 for (cp1 = cp + strlen(cp) -1; *cp1 == '\n' || *cp1 == ' '; cp1 --) { 1273 for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--)
1043 *cp1='\0'; 1274 {
1044 if (cp==cp1) break; 1275 *cp1 = '\0';
1045 } 1276 if (cp == cp1)
1046 1277 break;
1047 if (cp[strlen(cp)-1]=='\n') cp[strlen(cp)-1]='\0'; 1278 }
1279
1280 if (cp[strlen (cp) - 1] == '\n')
1281 cp[strlen (cp) - 1] = '\0';
1282
1048 /* set creature race to race value */ 1283 /* set creature race to race value */
1049 if((mon=find_archetype(cp))==NULL) 1284 if ((mon = archetype::find (cp)) == NULL)
1050 LOG(llevError,"\nCreature %s in race file lacks archetype",cp); 1285 LOG (llevError, "Creature %s in race file lacks archetype\n", cp);
1051 else { 1286 else
1287 {
1052 if(set_race&&(!mon->clone.race||strcmp(mon->clone.race,race))) { 1288 if (set_race && (!mon->clone.race || strcmp (mon->clone.race, race)))
1289 {
1053 if(mon->clone.race) { 1290 if (mon->clone.race)
1054 LOG(llevDebug,"\n Resetting race to %s from %s for archetype %s", 1291 LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->clone.race, &mon->name);
1055 race,mon->clone.race,mon->name); 1292
1056 free_string(mon->clone.race); 1293 mon->clone.race = race;
1057 } 1294 }
1058 mon->clone.race=add_string(race); 1295
1059 }
1060 /* if the arch is a monster, add it to the race list */ 1296 /* if the arch is a monster, add it to the race list */
1061 if(set_list&&QUERY_FLAG(&mon->clone,FLAG_MONSTER)) 1297 if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER))
1062 add_to_racelist(race, &mon->clone); 1298 add_to_racelist (race, &mon->clone);
1063 } 1299 }
1064 } 1300 }
1065 } 1301 }
1302
1066 fclose(file); 1303 fclose (file);
1067 LOG(llevDebug,"done.\n"); 1304 LOG (llevDebug, "done.\n");
1068} 1305}
1069 1306
1307void
1070void dump_races(void) 1308dump_races (void)
1071{ 1309{
1072 racelink *list; 1310 racelink *list;
1073 objectlink *tmp; 1311 objectlink *tmp;
1312
1074 for(list=first_race;list;list=list->next) { 1313 for (list = first_race; list; list = list->next)
1314 {
1075 fprintf(stderr,"\nRACE %s:\t",list->name); 1315 fprintf (stderr, "\nRACE %s:\t", &list->name);
1076 for(tmp=list->member;tmp;tmp=tmp->next) 1316 for (tmp = list->member; tmp; tmp = tmp->next)
1077 fprintf(stderr,"%s(%d), ",tmp->ob->arch->name,tmp->ob->level); 1317 fprintf (stderr, "%s(%d), ", &tmp->ob->arch->name, tmp->ob->level);
1078 } 1318 }
1319
1079 fprintf(stderr,"\n"); 1320 fprintf (stderr, "\n");
1080} 1321}
1081 1322
1323void
1082void add_to_racelist (const char *race_name, object *op) { 1324add_to_racelist (const char *race_name, object *op)
1325{
1083 racelink *race; 1326 racelink *race;
1084 1327
1085 if(!op||!race_name) return; 1328 if (!op || !race_name)
1329 return;
1330
1086 race=find_racelink(race_name); 1331 race = find_racelink (race_name);
1087 1332
1088 if(!race) { /* add in a new race list */ 1333 if (!race)
1334 { /* add in a new race list */
1089 race = get_racelist(); 1335 race = get_racelist ();
1090 race->next = first_race; 1336 race->next = first_race;
1091 first_race = race; 1337 first_race = race;
1092 race->name=add_string(race_name); 1338 race->name = race_name;
1093 } 1339 }
1094 1340
1095 if(race->member->ob) { 1341 if (race->member->ob)
1342 {
1096 objectlink *tmp = get_objectlink(); 1343 objectlink *tmp = get_objectlink ();
1344
1097 tmp->next=race->member; 1345 tmp->next = race->member;
1098 race->member = tmp; 1346 race->member = tmp;
1099 } 1347 }
1348
1100 race->nrof++; 1349 race->nrof++;
1101 race->member->ob = op; 1350 race->member->ob = op;
1102} 1351}
1103 1352
1104racelink * get_racelist ( ) { 1353racelink *
1105 racelink *list; 1354get_racelist ()
1106 1355{
1107 list = (racelink *) malloc(sizeof(racelink )); 1356 racelink *list = new racelink;
1357
1108 list->name=NULL; 1358 list->name = 0;
1109 list->nrof=0; 1359 list->nrof = 0;
1360 list->next = 0;
1110 list->member=get_objectlink(); 1361 list->member = get_objectlink ();
1111 list->next=NULL;
1112 1362
1113 return list; 1363 return list;
1114} 1364}
1115 1365
1366racelink *
1116racelink * find_racelink( const char *name ) { 1367find_racelink (const char *name)
1117 racelink *test=NULL; 1368{
1118 1369 if (name)
1119 if(name&&first_race) 1370 for (racelink *link = first_race; link; link = link->next)
1120 for(test=first_race;test&&test!=test->next;test=test->next) 1371 if (!link->name || !strcmp (name, link->name))
1121 if(!test->name||!strcmp(name,test->name)) break; 1372 return link;
1122 1373
1123 return test; 1374 return 0;
1124} 1375}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines