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