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.8 by elmex, Sun Sep 3 14:33:46 2006 UTC vs.
Revision 1.9 by root, Sun Sep 10 15:59:57 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines