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