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