ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/init.C
(Generate patch)

Comparing deliantra/server/server/init.C (file contents):
Revision 1.3 by root, Tue Aug 29 05:03:55 2006 UTC vs.
Revision 1.22 by root, Tue Dec 26 08:55:00 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines