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.1 by elmex, Sun Aug 13 17:16:04 2006 UTC vs.
Revision 1.21 by root, Wed Dec 20 09:14:22 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines