1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * "$Id: init.C,v 1.8 2006/09/03 14:33:46 elmex Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify |
|
|
9 | * it under the terms of the GNU General Public License as published by |
|
|
10 | * the Free Software Foundation, either version 3 of the License, or |
|
|
11 | * (at your option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License |
|
|
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
20 | * |
|
|
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
4 | */ |
22 | */ |
5 | |
|
|
6 | /* |
|
|
7 | CrossFire, A Multiplayer game for X-windows |
|
|
8 | |
|
|
9 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
|
|
10 | Copyright (C) 1992 Frank Tore Johansen |
|
|
11 | |
|
|
12 | This program is free software; you can redistribute it and/or modify |
|
|
13 | it under the terms of the GNU General Public License as published by |
|
|
14 | the Free Software Foundation; either version 2 of the License, or |
|
|
15 | (at your option) any later version. |
|
|
16 | |
|
|
17 | This program is distributed in the hope that it will be useful, |
|
|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
20 | GNU General Public License for more details. |
|
|
21 | |
|
|
22 | You should have received a copy of the GNU General Public License |
|
|
23 | along with this program; if not, write to the Free Software |
|
|
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
|
25 | |
|
|
26 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
|
|
27 | */ |
|
|
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}, |
|
|
146 | {"-m", 0, 3, set_dumpmon1}, |
273 | {"-m", 0, 3, set_dumpmon1}, |
147 | {"-m2", 0, 3, set_dumpmon2}, |
274 | {"-m2", 0, 3, set_dumpmon2}, |
148 | {"-m3", 0, 3, set_dumpmon3}, |
275 | {"-m3", 0, 3, set_dumpmon3}, |
149 | {"-m4", 0, 3, set_dumpmon4}, |
276 | {"-m4", 0, 3, set_dumpmon4}, |
150 | {"-m5", 0, 3, set_dumpmon5}, |
277 | {"-m5", 0, 3, set_dumpmon5}, |
151 | {"-m6", 0, 3, set_dumpmon6}, |
278 | {"-m6", 0, 3, set_dumpmon6}, |
152 | {"-m7", 0, 3, set_dumpmon7}, |
279 | {"-m7", 0, 3, set_dumpmon7}, |
153 | {"-m8", 0, 3, set_dumpmon8}, |
280 | {"-m8", 0, 3, set_dumpmon8}, |
154 | {"-m9", 0, 3, set_dumpmon9}, |
281 | {"-m9", 0, 3, set_dumpmon9}, |
155 | {"-mt", 1, 3, (void (*)())set_dumpmont}, |
282 | {"-mt", 1, 3, (void (*)()) set_dumpmont}, |
156 | {"-mexp", 0, 3, dump_experience}, |
|
|
157 | {"-s", 0, 3, showscores}, |
283 | {"-s", 0, 3, showscores}, |
158 | {"-score", 1, 3, (void (*)())showscoresparm} |
284 | {"-score", 1, 3, (void (*)()) showscoresparm} |
159 | }; |
285 | }; |
160 | |
286 | |
161 | |
287 | |
162 | /* Note since this may be called before the library has been set up, |
288 | /* 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. |
289 | * we don't use any of deliantras built in logging functions. |
164 | */ |
290 | */ |
|
|
291 | static void |
165 | static void parse_args(int argc, char *argv[], int pass) |
292 | parse_args (int argc, char *argv[], int pass) |
166 | { |
293 | { |
167 | size_t i; |
294 | size_t i; |
168 | int on_arg=1; |
295 | int on_arg = 1; |
169 | |
296 | |
170 | while (on_arg<argc) { |
297 | while (on_arg < argc) |
|
|
298 | { |
171 | for (i=0; i<sizeof(options)/sizeof(struct Command_Line_Options); i++) { |
299 | for (i = 0; i < sizeof (options) / sizeof (struct Command_Line_Options); i++) |
|
|
300 | { |
172 | if (!strcmp(options[i].cmd_option, argv[on_arg])) { |
301 | if (!strcmp (options[i].cmd_option, argv[on_arg])) |
|
|
302 | { |
173 | /* Found a matching option, but should not be processed on |
303 | /* Found a matching option, but should not be processed on |
174 | * this pass. Just skip over it |
304 | * this pass. Just skip over it |
175 | */ |
305 | */ |
176 | if (options[i].pass != pass) { |
306 | if (options[i].pass != pass) |
|
|
307 | { |
177 | on_arg += options[i].num_args+1; |
308 | on_arg += options[i].num_args + 1; |
178 | break; |
309 | break; |
179 | } |
310 | } |
180 | if (options[i].num_args) { |
311 | if (options[i].num_args) |
|
|
312 | { |
181 | if ((on_arg+options[i].num_args)>=argc) { |
313 | if ((on_arg + options[i].num_args) >= argc) |
|
|
314 | { |
182 | fprintf(stderr,"%s requires an argument.\n", options[i].cmd_option); |
315 | fprintf (stderr, "%s requires an argument.\n", options[i].cmd_option); |
183 | exit(1); |
316 | exit (1); |
184 | } |
317 | } |
185 | else { |
318 | else |
|
|
319 | { |
186 | if (options[i].num_args==1) |
320 | if (options[i].num_args == 1) |
187 | ((void (*)(char*))options[i].func)(argv[on_arg+1]); |
321 | ((void (*)(char *)) options[i].func) (argv[on_arg + 1]); |
188 | if (options[i].num_args==2) |
322 | if (options[i].num_args == 2) |
189 | ((void (*)(char*,char*))options[i].func)(argv[on_arg+1],argv[on_arg+2]); |
323 | ((void (*)(char *, char *)) options[i].func) (argv[on_arg + 1], argv[on_arg + 2]); |
190 | on_arg +=options[i].num_args+1; |
324 | on_arg += options[i].num_args + 1; |
191 | } |
325 | } |
192 | } |
326 | } |
|
|
327 | else |
193 | else { /* takes no args */ |
328 | { /* takes no args */ |
194 | options[i].func(); |
329 | options[i].func (); |
195 | on_arg++; |
330 | on_arg++; |
196 | } |
331 | } |
197 | break; |
332 | break; |
198 | } |
|
|
199 | } |
333 | } |
|
|
334 | } |
200 | if (i==sizeof(options)/sizeof(struct Command_Line_Options)) { |
335 | if (i == sizeof (options) / sizeof (struct Command_Line_Options)) |
|
|
336 | { |
201 | fprintf(stderr,"Unknown option: %s\n", argv[on_arg]); |
337 | fprintf (stderr, "Unknown option: %s\n", argv[on_arg]); |
202 | usage(); |
338 | usage (); |
203 | exit(1); |
339 | exit (1); |
204 | } |
340 | } |
205 | } |
341 | } |
206 | } |
342 | } |
207 | |
343 | |
208 | //TODO: make this a constructor |
344 | //TODO: make this a constructor |
209 | static materialtype_t *get_empty_mat(void) { |
345 | static materialtype_t * |
|
|
346 | get_empty_mat (void) |
|
|
347 | { |
210 | materialtype_t *mt; |
348 | materialtype_t *mt; |
211 | int i; |
349 | int i; |
212 | |
350 | |
213 | mt = new materialtype_t; |
351 | mt = new materialtype_t; |
214 | |
352 | |
215 | mt->name = NULL; |
353 | mt->name = NULL; |
216 | mt->description = NULL; |
354 | mt->description = NULL; |
217 | for (i=0; i < NROFATTACKS; i++) { |
355 | for (i = 0; i < NROFATTACKS; i++) |
|
|
356 | { |
218 | mt->save[i] = 0; |
357 | mt->save[i] = 0; |
219 | mt->mod[i] = 0; |
358 | mt->mod[i] = 0; |
220 | } |
359 | } |
221 | mt->chance = 0; |
360 | mt->chance = 0; |
222 | mt->difficulty = 0; |
361 | mt->difficulty = 0; |
223 | mt->magic = 0; |
362 | mt->magic = 0; |
224 | mt->damage = 0; |
363 | mt->damage = 0; |
225 | mt->wc = 0; |
364 | mt->wc = 0; |
226 | mt->ac = 0; |
365 | mt->ac = 0; |
227 | mt->sp = 0; |
366 | mt->sp = 0; |
228 | mt->weight = 100; |
367 | mt->weight = 100; |
229 | mt->value = 100; |
368 | mt->value = 100; |
230 | mt->next = NULL; |
369 | mt->next = NULL; |
231 | return mt; |
370 | return mt; |
232 | } |
371 | } |
233 | |
372 | |
|
|
373 | static void |
234 | static void load_materials(void) |
374 | load_materials (void) |
235 | { |
375 | { |
236 | char buf[MAX_BUF], filename[MAX_BUF], *cp, *next; |
376 | char filename[MAX_BUF]; |
237 | FILE *fp; |
|
|
238 | materialtype_t *mt; |
377 | materialtype_t *mt; |
239 | int i, value; |
|
|
240 | |
378 | |
241 | sprintf(filename, "%s/materials", settings.datadir); |
379 | sprintf (filename, "%s/materials", settings.datadir); |
242 | LOG(llevDebug, "Reading material type data from %s...", filename); |
380 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
243 | if ((fp = fopen(filename, "r")) == NULL) { |
381 | |
|
|
382 | object_thawer thawer (filename); |
|
|
383 | |
|
|
384 | if (!thawer) |
|
|
385 | { |
244 | LOG(llevError, "Cannot open %s for reading\n", filename); |
386 | LOG (llevError, "Cannot open %s for reading\n", filename); |
245 | mt = get_empty_mat(); |
387 | mt = get_empty_mat (); |
246 | mt->next = NULL; |
388 | mt->next = 0; |
247 | materialt = mt; |
389 | materialt = mt; |
248 | return; |
390 | return; |
249 | } |
391 | } |
|
|
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 | |
253 | if (*buf=='#') |
396 | for (;;) |
254 | continue; |
397 | { |
255 | if ((cp=strchr(buf, '\n'))!=NULL) |
398 | thawer.next (); |
256 | *cp='\0'; |
399 | |
257 | cp=buf; |
400 | switch (thawer.kw) |
258 | while(*cp==' ') /* Skip blanks */ |
401 | { |
259 | cp++; |
402 | case KW_name: |
260 | if (!strncmp(cp, "name", 4)) { |
|
|
261 | /* clean up the previous entry */ |
403 | /* clean up the previous entry */ |
262 | if (mt->next != NULL) { |
404 | if (mt->next) |
|
|
405 | { |
263 | if (mt->description == NULL) |
406 | if (!mt->description) |
264 | mt->description = mt->name; |
407 | mt->description = mt->name; |
|
|
408 | |
265 | mt = mt->next; |
409 | mt = mt->next; |
266 | } |
410 | } |
|
|
411 | |
267 | mt->next = get_empty_mat (); |
412 | mt->next = get_empty_mat (); |
268 | mt->name = strchr(cp, ' ') + 1; |
413 | thawer.get (mt->name); |
269 | } else if (!strncmp(cp, "description", 11)) { |
414 | break; |
270 | mt->description = strchr(cp, ' ') + 1; |
415 | |
271 | } else if (sscanf(cp, "material %d", &value)) { |
416 | case KW_description: |
272 | mt->material = value; |
417 | thawer.get (mt->description); |
273 | } else if (!strncmp(cp, "saves", 5)) { |
418 | break; |
274 | cp = strchr(cp, ' ') + 1; |
419 | |
|
|
420 | case KW_material: |
|
|
421 | thawer.get (mt->material); |
|
|
422 | break; |
|
|
423 | |
|
|
424 | case KW_saves: |
|
|
425 | { |
|
|
426 | const char *cp = thawer.get_str () - 1; |
|
|
427 | |
275 | for (i=0; i < NROFATTACKS; i++) { |
428 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
429 | { |
276 | if (cp == NULL) { |
430 | if (!cp) |
|
|
431 | { |
277 | mt->save[i] = 0; |
432 | mt->save[i] = 0; |
278 | continue; |
433 | continue; |
|
|
434 | } |
|
|
435 | |
|
|
436 | int value; |
|
|
437 | ++cp; |
|
|
438 | sscanf (cp, "%d", &value); |
|
|
439 | mt->save[i] = (sint8) value; |
|
|
440 | cp = strchr (cp, ','); |
279 | } |
441 | } |
280 | if ((next=strchr(cp,',')) != NULL) |
442 | } |
281 | *(next++) = '\0'; |
443 | break; |
282 | sscanf(cp, "%d", &value); |
444 | |
283 | mt->save[i] = (sint8)value; |
445 | case KW_mods: |
284 | cp = next; |
|
|
285 | } |
446 | { |
286 | } else if (!strncmp(cp, "mods", 4)) { |
447 | const char *cp = thawer.get_str () - 1; |
287 | cp = strchr(cp, ' ') + 1; |
448 | |
288 | for (i=0; i < NROFATTACKS; i++) { |
449 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
450 | { |
289 | if (cp == NULL) { |
451 | if (!cp) |
|
|
452 | { |
290 | mt->save[i] = 0; |
453 | mt->save[i] = 0; |
291 | continue; |
454 | continue; |
292 | } |
455 | } |
293 | if ((next=strchr(cp,',')) != NULL) |
456 | |
294 | *(next++) = '\0'; |
457 | ++cp; |
|
|
458 | int value; |
295 | sscanf(cp, "%d", &value); |
459 | sscanf (cp, "%d", &value); |
296 | mt->mod[i] = (sint8)value; |
460 | mt->mod[i] = (sint8) value; |
297 | cp = next; |
461 | cp = strchr (cp, ','); |
298 | } |
462 | } |
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 | } |
463 | } |
|
|
464 | break; |
|
|
465 | |
|
|
466 | case KW_chance: thawer.get (mt->chance); break; |
|
|
467 | case KW_difficulty: // cf+ alias, not original cf |
|
|
468 | case KW_diff: thawer.get (mt->difficulty); break; |
|
|
469 | case KW_magic: thawer.get (mt->magic); break; |
|
|
470 | case KW_dam: // cf+ alias, not original cf |
|
|
471 | case KW_damage: thawer.get (mt->damage); break; |
|
|
472 | case KW_wc: thawer.get (mt->wc); break; |
|
|
473 | case KW_ac: thawer.get (mt->ac); break; |
|
|
474 | case KW_sp: thawer.get (mt->sp); break; |
|
|
475 | case KW_weight: thawer.get (mt->weight); break; |
|
|
476 | case KW_value: thawer.get (mt->value); break; |
|
|
477 | case KW_density: thawer.get (mt->density); break; |
|
|
478 | |
|
|
479 | case KW_EOF: |
|
|
480 | goto done; |
|
|
481 | |
|
|
482 | default: |
|
|
483 | if (!thawer.parse_error ("materials file", "materials")) |
|
|
484 | goto done; |
|
|
485 | break; |
|
|
486 | } |
318 | } |
487 | } |
|
|
488 | |
|
|
489 | done: |
319 | if (mt->next) |
490 | if (mt->next) |
320 | { |
491 | { |
321 | delete mt->next; |
492 | delete mt->next; |
|
|
493 | |
322 | mt->next = NULL; |
494 | mt->next = 0; |
323 | } |
495 | } |
|
|
496 | |
324 | LOG(llevDebug, "Done.\n"); |
497 | LOG (llevDebug, "Done.\n"); |
325 | fclose(fp); |
|
|
326 | } |
498 | } |
327 | |
499 | |
328 | /* This loads the settings file. There could be debate whether this should |
500 | /* 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 |
501 | * be here or in the common directory - but since only the server needs this |
330 | * information, having it here probably makes more sense. |
502 | * information, having it here probably makes more sense. |
331 | */ |
503 | */ |
332 | static void load_settings(void) |
504 | static void |
|
|
505 | load_settings (void) |
333 | { |
506 | { |
334 | char buf[MAX_BUF],*cp; |
507 | char buf[MAX_BUF], *cp; |
335 | int has_val,comp; |
508 | int has_val, comp; |
336 | FILE *fp; |
509 | FILE *fp; |
337 | |
510 | |
338 | sprintf(buf,"%s/settings",settings.confdir); |
511 | sprintf (buf, "%s/settings", settings.confdir); |
339 | |
512 | |
340 | /* We don't require a settings file at current time, but down the road, |
513 | /* 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 |
514 | * there will probably be so many values that not having a settings file |
342 | * will not be a good thing. |
515 | * will not be a good thing. |
343 | */ |
516 | */ |
344 | if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) { |
517 | if (!(fp = open_and_uncompress (buf, 0, &comp))) |
|
|
518 | { |
345 | LOG(llevError,"Warning: No settings file found\n"); |
519 | LOG (llevError, "Error: No settings file found\n"); |
346 | return; |
520 | exit (1); |
347 | } |
521 | } |
|
|
522 | |
348 | while (fgets(buf, MAX_BUF-1, fp) != NULL) { |
523 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
|
|
524 | { |
349 | if (buf[0] == '#') continue; |
525 | if (buf[0] == '#') |
|
|
526 | continue; |
350 | /* eliminate newline */ |
527 | /* eliminate newline */ |
351 | if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0'; |
528 | if ((cp = strrchr (buf, '\n')) != NULL) |
|
|
529 | *cp = '\0'; |
352 | |
530 | |
353 | /* Skip over empty lines */ |
531 | /* Skip over empty lines */ |
354 | if (buf[0] == 0) continue; |
532 | if (buf[0] == 0) |
|
|
533 | continue; |
355 | |
534 | |
356 | /* Skip all the spaces and set them to nulls. If not space, |
535 | /* 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. |
536 | * set cp to "" to make strcpy's and the like easier down below. |
358 | */ |
537 | */ |
359 | if ((cp = strchr(buf,' '))!=NULL) { |
538 | if ((cp = strchr (buf, ' ')) != NULL) |
|
|
539 | { |
360 | while (*cp==' ') *cp++=0; |
540 | while (*cp == ' ') |
|
|
541 | *cp++ = 0; |
361 | has_val=1; |
542 | has_val = 1; |
|
|
543 | } |
362 | } else { |
544 | else |
363 | cp=""; |
545 | { |
|
|
546 | cp = (char *)""; |
364 | has_val=0; |
547 | has_val = 0; |
|
|
548 | } |
|
|
549 | |
|
|
550 | if (!strcasecmp (buf, "motd")) |
365 | } |
551 | { |
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) |
552 | if (has_val) |
382 | strcpy(settings.motd, cp); |
553 | strcpy (settings.motd, cp); |
383 | else |
554 | else |
384 | LOG(llevError,"load_settings: motd must have a value.\n"); |
555 | LOG (llevError, "load_settings: motd must have a value.\n"); |
|
|
556 | } |
385 | } else if (!strcasecmp(buf,"dm_mail")) { |
557 | else if (!strcasecmp (buf, "dm_mail")) |
|
|
558 | { |
386 | if (has_val) |
559 | if (has_val) |
387 | strcpy(settings.dm_mail, cp); |
560 | strcpy (settings.dm_mail, cp); |
388 | else |
561 | else |
389 | LOG(llevError,"load_settings: dm_mail must have a value.\n"); |
562 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
390 | } else if (!strcasecmp(buf,"metaserver_host")) { |
563 | } |
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")) { |
564 | else if (!strcasecmp (buf, "worldmapstartx")) |
|
|
565 | { |
404 | int size = atoi(cp); |
566 | int size = atoi (cp); |
405 | |
567 | |
406 | if (size < 0) |
568 | if (size < 0) |
407 | LOG(llevError, "load_settings: worldmapstartx must be at least " |
569 | LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size); |
408 | "0, %d is invalid\n", size); |
|
|
409 | else |
570 | else |
410 | settings.worldmapstartx = size; |
571 | settings.worldmapstartx = size; |
|
|
572 | } |
411 | } else if (!strcasecmp(buf, "worldmapstarty")) { |
573 | else if (!strcasecmp (buf, "worldmapstarty")) |
|
|
574 | { |
412 | int size = atoi(cp); |
575 | int size = atoi (cp); |
413 | |
576 | |
414 | if (size < 0) |
577 | if (size < 0) |
415 | LOG(llevError, "load_settings: worldmapstarty must be at least " |
578 | LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size); |
416 | "0, %d is invalid\n", size); |
|
|
417 | else |
579 | else |
418 | settings.worldmapstarty = size; |
580 | settings.worldmapstarty = size; |
|
|
581 | } |
419 | } else if (!strcasecmp(buf, "worldmaptilesx")) { |
582 | else if (!strcasecmp (buf, "worldmaptilesx")) |
|
|
583 | { |
420 | int size = atoi(cp); |
584 | int size = atoi (cp); |
421 | |
585 | |
422 | if (size < 1) |
586 | if (size < 1) |
423 | LOG(llevError, "load_settings: worldmaptilesx must be greater " |
587 | 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 |
588 | else |
426 | settings.worldmaptilesx = size; |
589 | settings.worldmaptilesx = size; |
|
|
590 | } |
427 | } else if (!strcasecmp(buf, "worldmaptilesy")) { |
591 | else if (!strcasecmp (buf, "worldmaptilesy")) |
|
|
592 | { |
428 | int size = atoi(cp); |
593 | int size = atoi (cp); |
429 | |
594 | |
430 | if (size < 1) |
595 | if (size < 1) |
431 | LOG(llevError, "load_settings: worldmaptilesy must be greater " |
596 | 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 |
597 | else |
434 | settings.worldmaptilesy = size; |
598 | settings.worldmaptilesy = size; |
|
|
599 | } |
435 | } else if (!strcasecmp(buf, "worldmaptilesizex")) { |
600 | else if (!strcasecmp (buf, "worldmaptilesizex")) |
|
|
601 | { |
436 | int size = atoi(cp); |
602 | int size = atoi (cp); |
437 | |
603 | |
438 | if (size < 1) |
604 | if (size < 1) |
439 | LOG(llevError, "load_settings: worldmaptilesizex must be " |
605 | 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 |
606 | else |
442 | settings.worldmaptilesizex = size; |
607 | settings.worldmaptilesizex = size; |
|
|
608 | } |
443 | } else if (!strcasecmp(buf, "worldmaptilesizey")) { |
609 | else if (!strcasecmp (buf, "worldmaptilesizey")) |
|
|
610 | { |
444 | int size = atoi(cp); |
611 | int size = atoi (cp); |
445 | |
612 | |
446 | if (size < 1) |
613 | if (size < 1) |
447 | LOG(llevError, "load_settings: worldmaptilesizey must be " |
614 | 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 |
615 | else |
450 | settings.worldmaptilesizey = size; |
616 | settings.worldmaptilesizey = size; |
|
|
617 | } |
451 | } else if (!strcasecmp(buf, "dynamiclevel")) { |
618 | else if (!strcasecmp (buf, "dynamiclevel")) |
|
|
619 | { |
452 | int lev = atoi(cp); |
620 | int lev = atoi (cp); |
453 | |
621 | |
454 | if (lev < 0) |
622 | if (lev < 0) |
455 | LOG(llevError, "load_settings: dynamiclevel must be " |
623 | 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 |
624 | else |
458 | settings.dynamiclevel = lev; |
625 | settings.dynamiclevel = lev; |
|
|
626 | } |
459 | } else if (!strcasecmp(buf, "fastclock")) { |
627 | else if (!strcasecmp (buf, "fastclock")) |
|
|
628 | { |
460 | int lev = atoi(cp); |
629 | int lev = atoi (cp); |
461 | |
630 | |
462 | if (lev < 0) |
631 | if (lev < 0) |
463 | LOG(llevError, "load_settings: fastclock must be at least 0" |
632 | LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev); |
464 | ", %d is invalid\n", lev); |
|
|
465 | else |
633 | else |
466 | settings.fastclock = lev; |
634 | settings.fastclock = lev; |
|
|
635 | } |
467 | } else if (!strcasecmp(buf, "not_permadeth")) { |
636 | else if (!strcasecmp (buf, "not_permadeth")) |
|
|
637 | { |
468 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
638 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
639 | { |
469 | settings.not_permadeth=TRUE; |
640 | settings.not_permadeth = TRUE; |
|
|
641 | } |
470 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
642 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
643 | { |
471 | settings.not_permadeth=FALSE; |
644 | settings.not_permadeth = FALSE; |
|
|
645 | } |
472 | } else { |
646 | else |
473 | LOG(llevError, "load_settings: Unknown value for not_permadeth" |
|
|
474 | ": %s\n", cp); |
|
|
475 | } |
647 | { |
|
|
648 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
|
|
649 | } |
|
|
650 | } |
476 | } else if (!strcasecmp(buf, "resurrection")) { |
651 | else if (!strcasecmp (buf, "resurrection")) |
|
|
652 | { |
477 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
653 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
654 | { |
478 | settings.resurrection=TRUE; |
655 | settings.resurrection = TRUE; |
|
|
656 | } |
479 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
657 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
658 | { |
480 | settings.resurrection=FALSE; |
659 | settings.resurrection = FALSE; |
|
|
660 | } |
481 | } else { |
661 | else |
482 | LOG(llevError, "load_settings: Unknown value for resurrection" |
|
|
483 | ": %s\n", cp); |
|
|
484 | } |
662 | { |
|
|
663 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
|
|
664 | } |
|
|
665 | } |
485 | } else if (!strcasecmp(buf, "set_title")) { |
666 | else if (!strcasecmp (buf, "set_title")) |
|
|
667 | { |
486 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
668 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
669 | { |
487 | settings.set_title=TRUE; |
670 | settings.set_title = TRUE; |
|
|
671 | } |
488 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
672 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
673 | { |
489 | settings.set_title=FALSE; |
674 | settings.set_title = FALSE; |
|
|
675 | } |
490 | } else { |
676 | else |
491 | LOG(llevError, "load_settings: Unknown value for set_title" |
|
|
492 | ": %s\n", cp); |
|
|
493 | } |
677 | { |
|
|
678 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
|
|
679 | } |
|
|
680 | } |
494 | } else if (!strcasecmp(buf, "search_items")) { |
681 | else if (!strcasecmp (buf, "search_items")) |
|
|
682 | { |
495 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
683 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
684 | { |
496 | settings.search_items=TRUE; |
685 | settings.search_items = TRUE; |
|
|
686 | } |
497 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
687 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
688 | { |
498 | settings.search_items=FALSE; |
689 | settings.search_items = FALSE; |
|
|
690 | } |
499 | } else { |
691 | else |
500 | LOG(llevError, "load_settings: Unknown value for search_items" |
|
|
501 | ": %s\n", cp); |
|
|
502 | } |
692 | { |
|
|
693 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
|
|
694 | } |
|
|
695 | } |
503 | } else if (!strcasecmp(buf, "spell_encumbrance")) { |
696 | else if (!strcasecmp (buf, "spell_encumbrance")) |
|
|
697 | { |
504 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
698 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
699 | { |
505 | settings.spell_encumbrance=TRUE; |
700 | settings.spell_encumbrance = TRUE; |
|
|
701 | } |
506 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
702 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
703 | { |
507 | settings.spell_encumbrance=FALSE; |
704 | settings.spell_encumbrance = FALSE; |
|
|
705 | } |
508 | } else { |
706 | else |
509 | LOG(llevError, "load_settings: Unknown value for " |
|
|
510 | "spell_encumbrance: %s\n", cp); |
|
|
511 | } |
707 | { |
|
|
708 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
|
|
709 | } |
|
|
710 | } |
512 | } else if (!strcasecmp(buf, "spell_failure_effects")) { |
711 | else if (!strcasecmp (buf, "spell_failure_effects")) |
|
|
712 | { |
513 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
713 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
714 | { |
514 | settings.spell_failure_effects=TRUE; |
715 | settings.spell_failure_effects = TRUE; |
|
|
716 | } |
515 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
717 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
718 | { |
516 | settings.spell_failure_effects=FALSE; |
719 | settings.spell_failure_effects = FALSE; |
|
|
720 | } |
517 | } else { |
721 | else |
518 | LOG(llevError, "load_settings: Unknown value for " |
|
|
519 | "spell_failure_effects: %s\n", cp); |
|
|
520 | } |
722 | { |
521 | } else if (!strcasecmp(buf, "casting_time")) { |
723 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
|
|
724 | } |
|
|
725 | } |
|
|
726 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
|
|
727 | { |
522 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
728 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
523 | settings.casting_time=TRUE; |
|
|
524 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
|
|
525 | settings.casting_time=FALSE; |
|
|
526 | } else { |
|
|
527 | LOG(llevError, "load_settings: Unknown value for " |
|
|
528 | "casting_time: %s\n", cp); |
|
|
529 | } |
729 | { |
530 | } else if (!strcasecmp(buf, "real_wiz")) { |
|
|
531 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
|
|
532 | settings.real_wiz=TRUE; |
|
|
533 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
|
|
534 | settings.real_wiz=FALSE; |
|
|
535 | } else { |
|
|
536 | LOG(llevError, "load_settings: Unknown value for " |
|
|
537 | "real_wiz: %s\n", cp); |
|
|
538 | } |
|
|
539 | } else if (!strcasecmp(buf, "recycle_tmp_maps")) { |
|
|
540 | 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 | } |
|
|
548 | } else if (!strcasecmp(buf, "explore_mode")) { |
|
|
549 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
|
|
550 | settings.explore_mode=TRUE; |
|
|
551 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
|
|
552 | settings.explore_mode=FALSE; |
|
|
553 | } else { |
|
|
554 | LOG(llevError, "load_settings: Unknown value for " |
|
|
555 | "explore_mode: %s\n", cp); |
|
|
556 | } |
|
|
557 | } else if (!strcasecmp(buf,"who_format")) { |
|
|
558 | if (has_val) |
|
|
559 | strcpy(settings.who_format, cp); |
|
|
560 | } else if (!strcasecmp(buf,"who_wiz_format")) { |
|
|
561 | if (has_val) |
|
|
562 | strcpy(settings.who_wiz_format, cp); |
|
|
563 | } else if (!strcasecmp(buf, "spellpoint_level_depend")) { |
|
|
564 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
|
|
565 | settings.spellpoint_level_depend=TRUE; |
730 | settings.spellpoint_level_depend = TRUE; |
|
|
731 | } |
566 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
732 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
733 | { |
567 | settings.spellpoint_level_depend=FALSE; |
734 | settings.spellpoint_level_depend = FALSE; |
|
|
735 | } |
568 | } else { |
736 | else |
569 | LOG(llevError, "load_settings: Unknown value for " |
|
|
570 | "spellpoint_level_depend: %s\n", cp); |
|
|
571 | } |
737 | { |
|
|
738 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
|
|
739 | } |
|
|
740 | } |
572 | } else if (!strcasecmp(buf, "stat_loss_on_death")) { |
741 | else if (!strcasecmp (buf, "stat_loss_on_death")) |
|
|
742 | { |
573 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
743 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
744 | { |
574 | settings.stat_loss_on_death=TRUE; |
745 | settings.stat_loss_on_death = TRUE; |
|
|
746 | } |
575 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
747 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
748 | { |
576 | settings.stat_loss_on_death=FALSE; |
749 | settings.stat_loss_on_death = FALSE; |
|
|
750 | } |
577 | } else { |
751 | else |
578 | LOG(llevError, "load_settings: Unknown value for " |
|
|
579 | "stat_loss_on_death: %s\n", cp); |
|
|
580 | } |
752 | { |
|
|
753 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
|
|
754 | } |
|
|
755 | } |
581 | } else if (!strcasecmp(buf, "use_permanent_experience")) { |
756 | else if (!strcasecmp (buf, "use_permanent_experience")) |
582 | LOG(llevError, "use_permanent_experience is deprecated, use" |
757 | { |
583 | "permenent_experience_percentage instead\n"); |
758 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
|
|
759 | } |
584 | } else if (!strcasecmp(buf, "permanent_experience_percentage")) { |
760 | else if (!strcasecmp (buf, "permanent_experience_percentage")) |
|
|
761 | { |
585 | int val = atoi(cp); |
762 | int val = atoi (cp); |
|
|
763 | |
586 | if (val < 0 || val >100) |
764 | if (val < 0 || val > 100) |
587 | LOG(llevError, "load_settings: permenent_experience_percentage" |
765 | 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 |
766 | else |
590 | settings.permanent_exp_ratio = val; |
767 | settings.permanent_exp_ratio = val; |
|
|
768 | } |
591 | } else if (!strcasecmp(buf, "death_penalty_percentage")) { |
769 | else if (!strcasecmp (buf, "death_penalty_percentage")) |
|
|
770 | { |
592 | int val = atoi(cp); |
771 | int val = atoi (cp); |
|
|
772 | |
593 | if (val < 0 || val >100) |
773 | if (val < 0 || val > 100) |
594 | LOG(llevError, "load_settings: death_penalty_percentage" |
774 | 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 |
775 | else |
597 | settings.death_penalty_ratio = val; |
776 | settings.death_penalty_ratio = val; |
|
|
777 | } |
598 | } else if (!strcasecmp(buf, "death_penalty_levels")) { |
778 | else if (!strcasecmp (buf, "death_penalty_levels")) |
|
|
779 | { |
599 | int val = atoi(cp); |
780 | int val = atoi (cp); |
|
|
781 | |
600 | if (val < 0 || val > 255) |
782 | if (val < 0 || val > 255) |
601 | LOG(llevError, "load_settings: death_penalty_levels" |
783 | 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 |
784 | else |
604 | settings.death_penalty_level = val; |
785 | settings.death_penalty_level = val; |
|
|
786 | } |
605 | }else if (!strcasecmp(buf, "balanced_stat_loss")) { |
787 | else if (!strcasecmp (buf, "balanced_stat_loss")) |
|
|
788 | { |
606 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
789 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
790 | { |
607 | settings.balanced_stat_loss=TRUE; |
791 | settings.balanced_stat_loss = TRUE; |
|
|
792 | } |
608 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
793 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
794 | { |
609 | settings.balanced_stat_loss=FALSE; |
795 | settings.balanced_stat_loss = FALSE; |
|
|
796 | } |
610 | } else { |
797 | else |
611 | LOG(llevError, "load_settings: Unknown value for " |
|
|
612 | "balanced_stat_loss: %s\n", cp); |
|
|
613 | } |
798 | { |
|
|
799 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
|
|
800 | } |
|
|
801 | } |
614 | } else if (!strcasecmp(buf,"simple_exp")) { |
802 | else if (!strcasecmp (buf, "simple_exp")) |
|
|
803 | { |
615 | if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) { |
804 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
805 | { |
616 | settings.simple_exp=TRUE; |
806 | settings.simple_exp = TRUE; |
|
|
807 | } |
617 | } else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) { |
808 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
809 | { |
618 | settings.simple_exp=FALSE; |
810 | settings.simple_exp = FALSE; |
|
|
811 | } |
619 | } else { |
812 | else |
|
|
813 | { |
620 | LOG(llevError,"load_settings: Unknown value for simple_exp: %s\n", |
814 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
621 | cp); |
815 | } |
622 | } |
816 | } |
623 | } else if (!strcasecmp(buf, "item_power_factor")) { |
817 | else if (!strcasecmp (buf, "item_power_factor")) |
|
|
818 | { |
624 | float tmp = atof(cp); |
819 | float tmp = atof (cp); |
|
|
820 | |
625 | if (tmp < 0) |
821 | if (tmp < 0) |
626 | LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", |
822 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
627 | tmp); |
|
|
628 | else |
823 | else |
629 | settings.item_power_factor = tmp; |
824 | settings.item_power_factor = tmp; |
|
|
825 | } |
630 | } else if (!strcasecmp(buf, "pk_luck_penalty")) { |
826 | else if (!strcasecmp (buf, "pk_luck_penalty")) |
|
|
827 | { |
631 | sint16 val = atoi(cp); |
828 | sint16 val = atoi (cp); |
632 | |
829 | |
633 | if (val < -100 || val >100) |
830 | if (val < -100 || val > 100) |
634 | LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100" |
831 | 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 |
832 | else |
637 | settings.pk_luck_penalty = val; |
833 | settings.pk_luck_penalty = val; |
|
|
834 | } |
638 | } else if (!strcasecmp(buf, "set_friendly_fire")) { |
835 | else if (!strcasecmp (buf, "set_friendly_fire")) |
|
|
836 | { |
639 | int val = atoi(cp); |
837 | int val = atoi (cp); |
640 | |
838 | |
641 | #if COZY_SERVER |
|
|
642 | if (val < 0 || val >100) |
839 | if (val < 0 || val > 100) |
643 | LOG(llevError, "load_settings: set_friendly_fire must be between 0 an 100" |
840 | 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 |
|
|
646 | if (val < 1 || val >100) |
|
|
647 | LOG(llevError, "load_settings: set_friendly_fire must be between 1 an 100" |
|
|
648 | ", %d is invalid\n", val); |
|
|
649 | #endif |
|
|
650 | else |
841 | else |
651 | settings.set_friendly_fire = val; |
842 | settings.set_friendly_fire = val; |
|
|
843 | } |
652 | } else if ( !strcasecmp( buf, "armor_max_enchant" ) ) { |
844 | else if (!strcasecmp (buf, "armor_max_enchant")) |
|
|
845 | { |
653 | int max_e = atoi( cp ); |
846 | int max_e = atoi (cp); |
|
|
847 | |
654 | if ( max_e <= 0 ) |
848 | if (max_e <= 0) |
655 | LOG( llevError, "load_settings: armor_max_enchant is %d\n", max_e ); |
849 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
656 | else |
850 | else |
657 | settings.armor_max_enchant = max_e; |
851 | settings.armor_max_enchant = max_e; |
|
|
852 | } |
658 | } else if ( !strcasecmp( buf, "armor_weight_reduction" ) ) { |
853 | else if (!strcasecmp (buf, "armor_weight_reduction")) |
|
|
854 | { |
659 | int wr = atoi( cp ); |
855 | int wr = atoi (cp); |
|
|
856 | |
660 | if ( wr < 0 ) |
857 | if (wr < 0) |
661 | LOG( llevError, "load_settings: armor_weight_reduction is %d\n", wr ); |
858 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
662 | else |
859 | else |
663 | settings.armor_weight_reduction = wr; |
860 | settings.armor_weight_reduction = wr; |
|
|
861 | } |
664 | } else if ( !strcasecmp( buf, "armor_weight_linear" ) ) { |
862 | else if (!strcasecmp (buf, "armor_weight_linear")) |
|
|
863 | { |
665 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
864 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
865 | { |
666 | settings.armor_weight_linear=TRUE; |
866 | settings.armor_weight_linear = TRUE; |
|
|
867 | } |
667 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
868 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
869 | { |
668 | settings.armor_weight_linear=FALSE; |
870 | settings.armor_weight_linear = FALSE; |
|
|
871 | } |
669 | } else { |
872 | else |
|
|
873 | { |
670 | LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
874 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
671 | } |
875 | } |
672 | |
876 | |
|
|
877 | } |
673 | } else if ( !strcasecmp( buf, "armor_speed_improvement" ) ) { |
878 | else if (!strcasecmp (buf, "armor_speed_improvement")) |
|
|
879 | { |
674 | int wr = atoi( cp ); |
880 | int wr = atoi (cp); |
|
|
881 | |
675 | if ( wr < 0 ) |
882 | if (wr < 0) |
676 | LOG( llevError, "load_settings: armor_speed_improvement is %d\n", wr ); |
883 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
677 | else |
884 | else |
678 | settings.armor_speed_improvement = wr; |
885 | settings.armor_speed_improvement = wr; |
|
|
886 | } |
679 | } else if ( !strcasecmp( buf, "armor_speed_linear" ) ) { |
887 | else if (!strcasecmp (buf, "armor_speed_linear")) |
|
|
888 | { |
680 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
889 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
890 | { |
681 | settings.armor_speed_linear = TRUE; |
891 | settings.armor_speed_linear = TRUE; |
|
|
892 | } |
682 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
893 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
894 | { |
683 | settings.armor_speed_linear = FALSE; |
895 | settings.armor_speed_linear = FALSE; |
|
|
896 | } |
684 | } else { |
897 | else |
|
|
898 | { |
685 | LOG(llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
899 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
686 | } |
900 | } |
687 | |
901 | |
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 | } |
902 | } |
696 | |
|
|
697 | } else if ( !strcasecmp( buf, "create_home_portals" ) ) { |
|
|
698 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
|
|
699 | settings.create_home_portals = TRUE; |
|
|
700 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
|
|
701 | settings.create_home_portals = FALSE; |
|
|
702 | } else { |
|
|
703 | LOG(llevError, "load_settings: Unknown value for create_home_portals: %s\n", cp); |
|
|
704 | } |
|
|
705 | |
|
|
706 | } else { |
903 | else |
707 | LOG(llevError,"Unknown value in settings file: %s\n", buf); |
904 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
708 | } |
|
|
709 | } |
905 | } |
|
|
906 | |
710 | close_and_delete(fp, comp); |
907 | close_and_delete (fp, comp); |
711 | } |
908 | } |
712 | |
|
|
713 | |
909 | |
714 | /* |
910 | /* |
715 | * init() is called only once, when starting the program. |
911 | * init() is called only once, when starting the program. |
716 | */ |
912 | */ |
717 | |
913 | void |
718 | void init(int argc, char **argv) { |
914 | init (int argc, char **argv) |
719 | |
915 | { |
720 | init_done=0; /* Must be done before init_signal() */ |
916 | init_done = 0; /* Must be done before init_signal() */ |
721 | logfile=stderr; |
917 | rndm.seed (time (0)); |
|
|
918 | |
|
|
919 | init_environ (); |
722 | parse_args(argc, argv, 1); /* First arg pass - right now it does |
920 | parse_args (argc, argv, 1); /* First arg pass - right now it does |
723 | * nothing, but in future specifying the |
921 | * nothing, but in future specifying the |
724 | * LibDir in this pass would be reasonable*/ |
922 | * LibDir in this pass would be reasonable*/ |
725 | |
923 | |
726 | init_library(); /* Must be called early */ |
924 | init_anim (); // Must be called before perl |
|
|
925 | init_globals (); |
|
|
926 | init_experience (); |
|
|
927 | init_attackmess (); |
|
|
928 | init_dynamic (); |
|
|
929 | init_block (); |
|
|
930 | cfperl_init (); |
727 | load_settings(); /* Load the settings file */ |
931 | load_settings (); /* Load the settings file */ |
728 | init_weather(); |
|
|
729 | load_materials(); |
932 | load_materials (); |
730 | parse_args(argc, argv, 2); |
933 | parse_args (argc, argv, 2); |
731 | fprintf(logfile,"Welcome to CrossFire, v%s\n",VERSION); |
934 | LOG (llevInfo, "Welcome to Deliantra, v" VERSION); |
|
|
935 | LOG (llevInfo, "Copyright (C) Marc Alexander Lehmann / Robin Redeker / the Deliantra team."); |
732 | fprintf(logfile,"Copyright (C) 1994 Mark Wedel.\n"); |
936 | LOG (llevInfo, "Copyright (C) 1994 Mark Wedel."); |
733 | fprintf(logfile,"Copyright (C) 1992 Frank Tore Johansen.\n"); |
937 | LOG (llevInfo, "Copyright (C) 1992 Frank Tore Johansen."); |
734 | |
938 | |
735 | if (strcmp(settings.dm_mail, "") != 0) { |
939 | if (strcmp (settings.dm_mail, "") != 0) |
|
|
940 | { |
736 | fprintf(logfile,"Maintained locally by: %s\n", settings.dm_mail); |
941 | LOG (llevInfo, "Maintained locally by: %s\n", settings.dm_mail); |
737 | fprintf(logfile,"Questions and bugs should be mailed to above address.\n"); |
942 | LOG (llevInfo, "Questions and bugs should be mailed to above address.\n"); |
738 | } |
943 | } |
739 | SRANDOM(time(NULL)); |
|
|
740 | |
944 | |
741 | init_startup(); /* Write (C), check shutdown/forbid files */ |
945 | UUID::init (); |
742 | init_signals(); /* Sets up signal interceptions */ |
946 | init_signals (); /* Sets up signal interceptions */ |
743 | init_commands(); /* Sort command tables */ |
947 | init_commands (); /* Sort command tables */ |
744 | read_map_log(); /* Load up the old temp map files */ |
|
|
745 | init_skills(); |
948 | init_skills (); |
746 | |
949 | |
747 | parse_args(argc, argv, 3); |
950 | parse_args (argc, argv, 3); |
748 | |
951 | |
749 | #ifndef WIN32 /* ***win32: no BecomeDaemon in windows */ |
|
|
750 | if (settings.daemonmode) |
|
|
751 | logfile = BecomeDaemon(settings.logfilename[0]=='\0'?"logfile":settings.logfilename); |
|
|
752 | #endif |
|
|
753 | |
|
|
754 | init_beforeplay(); |
952 | init_beforeplay (); |
755 | init_ericserver(); |
|
|
756 | metaserver_init(); |
|
|
757 | init_done=1; |
953 | init_done = 1; |
758 | } |
954 | } |
759 | |
955 | |
760 | void usage(void) { |
956 | void |
761 | (void) fprintf(logfile, |
957 | usage (void) |
762 | "Usage: crossfire [-h] [-<flags>]...\n"); |
958 | { |
|
|
959 | fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
763 | } |
960 | } |
764 | |
961 | |
765 | void help(void) { |
962 | void |
|
|
963 | help (void) |
|
|
964 | { |
|
|
965 | |
766 | /* The information in usage is redundant with what is given below, so why call it? */ |
966 | /* The information in usage is redundant with what is given below, so why call it? */ |
|
|
967 | |
767 | /* usage();*/ |
968 | /* usage();*/ |
768 | printf("Flags:\n"); |
969 | printf ("Flags:\n"); |
769 | printf(" -csport <port> Specifies the port to use for the new client/server code.\n"); |
970 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
770 | printf(" -d Turns on some debugging.\n"); |
971 | printf (" -d Turns on some debugging.\n"); |
771 | printf(" +d Turns off debugging (useful if server compiled with debugging\n"); |
972 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
772 | printf(" as default).\n"); |
973 | printf (" as default).\n"); |
773 | printf(" -detach The server will go in the background, closing all\n"); |
974 | printf (" -detach The server will go in the background, closing all\n"); |
774 | printf(" connections to the tty.\n"); |
975 | printf (" connections to the tty.\n"); |
775 | printf(" -h Display this information.\n"); |
976 | printf (" -h Display this information.\n"); |
776 | printf(" -log <file> Specifies which file to send output to.\n"); |
977 | printf (" -log <file> Specifies which file to send output to.\n"); |
777 | printf(" Only has meaning if -detach is specified.\n"); |
978 | printf (" Only has meaning if -detach is specified.\n"); |
778 | printf(" -mon Turns on monster debugging.\n"); |
979 | printf (" -mon Turns on monster debugging.\n"); |
779 | printf(" -o Prints out info on what was defined at compile time.\n"); |
980 | printf (" -o Prints out info on what was defined at compile time.\n"); |
780 | printf(" -s Display the high-score list.\n"); |
981 | printf (" -s Display the high-score list.\n"); |
781 | printf(" -score <name or class> Displays all high scores with matching name/class.\n"); |
982 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
782 | printf(" -v Print version and contributors.\n"); |
983 | printf (" -v Print version and contributors.\n"); |
783 | printf(" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
984 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
784 | printf(" -local Read/write local data (hiscore, unique items, etc.)\n"); |
985 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
785 | printf(" -maps Sets the directory for maps.\n"); |
986 | printf (" -maps Sets the directory for maps.\n"); |
786 | printf(" -arch Sets the archetype file to use.\n"); |
987 | printf (" -arch Sets the archetype file to use.\n"); |
787 | printf(" -regions Sets the regions file to use.\n"); |
988 | printf (" -regions Sets the regions file to use.\n"); |
788 | printf(" -playerdir Sets the directory for the player files.\n"); |
989 | printf (" -playerdir Sets the directory for the player files.\n"); |
789 | printf(" -templatedir Sets the directory for template generate maps.\n"); |
990 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
790 | printf(" -treasures Sets the treasures file to use.\n"); |
991 | printf (" -treasures Sets the treasures file to use.\n"); |
791 | printf(" -uniquedir Sets the unique items/maps directory.\n"); |
992 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
792 | printf(" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
993 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
793 | printf(" -m Lists out suggested experience for all monsters.\n"); |
994 | printf (" -m Lists out suggested experience for all monsters.\n"); |
794 | printf(" -m2 Dumps out abilities.\n"); |
995 | printf (" -m2 Dumps out abilities.\n"); |
795 | printf(" -m3 Dumps out artifact information.\n"); |
996 | printf (" -m3 Dumps out artifact information.\n"); |
796 | printf(" -m4 Dumps out spell information.\n"); |
997 | printf (" -m4 Dumps out spell information.\n"); |
797 | printf(" -m5 Dumps out skill information.\n"); |
998 | printf (" -m5 Dumps out skill information.\n"); |
798 | printf(" -m6 Dumps out race information.\n"); |
999 | printf (" -m6 Dumps out race information.\n"); |
799 | printf(" -m7 Dumps out alchemy information.\n"); |
1000 | printf (" -m7 Dumps out alchemy information.\n"); |
800 | printf(" -m8 Dumps out gods information.\n"); |
1001 | printf (" -m8 Dumps out gods information.\n"); |
801 | printf(" -m9 Dumps out more alchemy information (formula checking).\n"); |
1002 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
802 | printf(" -mt <name> Dumps out list of treasures for a monster.\n"); |
1003 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
803 | exit(0); |
|
|
804 | } |
|
|
805 | |
|
|
806 | void init_beforeplay(void) { |
|
|
807 | init_archetypes(); /* If not called before, reads all archetypes from file */ |
|
|
808 | init_artifacts(); /* If not called before, reads all artifacts from file */ |
|
|
809 | init_spells(); /* If not called before, links archtypes used by spells */ |
|
|
810 | init_regions(); /* If not called before, reads all regions from file */ |
|
|
811 | init_archetype_pointers(); /* Setup global pointers to archetypes */ |
|
|
812 | init_races(); /* overwrite race designations using entries in lib/races file */ |
|
|
813 | init_gods(); /* init linked list of gods from archs*/ |
|
|
814 | init_readable(); /* inits useful arrays for readable texts */ |
|
|
815 | init_formulae(); /* If not called before, reads formulae from file */ |
|
|
816 | |
|
|
817 | switch(settings.dumpvalues) { |
|
|
818 | case 1: |
|
|
819 | print_monsters(); |
|
|
820 | exit(0); |
|
|
821 | case 2: |
|
|
822 | dump_abilities(); |
|
|
823 | exit(0); |
|
|
824 | case 3: |
|
|
825 | dump_artifacts(); |
|
|
826 | exit(0); |
|
|
827 | case 4: |
|
|
828 | dump_spells(); |
|
|
829 | exit(0); |
|
|
830 | case 5: |
|
|
831 | exit(0); |
|
|
832 | case 6: |
|
|
833 | dump_races(); |
|
|
834 | exit(0); |
|
|
835 | case 7: |
|
|
836 | dump_alchemy(); |
|
|
837 | exit(0); |
|
|
838 | case 9: |
|
|
839 | dump_alchemy_costs(); |
|
|
840 | exit(0); |
|
|
841 | case 10: |
|
|
842 | dump_monster_treasure(settings.dumparg); |
|
|
843 | exit(0); |
|
|
844 | } |
|
|
845 | } |
|
|
846 | |
|
|
847 | void init_startup(void) { |
|
|
848 | char buf[MAX_BUF]; |
|
|
849 | FILE *fp; |
|
|
850 | int comp; |
|
|
851 | |
|
|
852 | #ifdef SHUTDOWN_FILE |
|
|
853 | sprintf(buf,"%s/%s",settings.confdir,SHUTDOWN_FILE); |
|
|
854 | if ((fp = open_and_uncompress(buf, 0, &comp)) != NULL) { |
|
|
855 | while (fgets(buf, MAX_BUF-1, fp) != NULL) |
|
|
856 | printf("%s", buf); |
|
|
857 | close_and_delete(fp, comp); |
|
|
858 | exit(1); |
|
|
859 | } |
|
|
860 | #endif |
|
|
861 | |
|
|
862 | if (forbid_play()) { /* Maybe showing highscore should be allowed? */ |
|
|
863 | LOG(llevError, "CrossFire: Playing not allowed.\n"); |
|
|
864 | exit(-1); |
|
|
865 | } |
|
|
866 | } |
|
|
867 | |
|
|
868 | /* |
|
|
869 | * compile_info(): activated with the -o flag. |
|
|
870 | * It writes out information on how Imakefile and config.h was configured |
|
|
871 | * at compile time. |
|
|
872 | */ |
|
|
873 | |
|
|
874 | void compile_info(void) { |
|
|
875 | int i=0; |
|
|
876 | printf("Non-standard include files:\n"); |
|
|
877 | #if !defined (__STRICT_ANSI__) || defined (__sun__) |
|
|
878 | #if !defined (Mips) |
|
|
879 | printf("<stdlib.h>\n"); |
|
|
880 | i=1; |
|
|
881 | #endif |
|
|
882 | #if !defined (MACH) && !defined (sony) |
|
|
883 | printf("<malloc.h>\n"); |
|
|
884 | i=1; |
|
|
885 | #endif |
|
|
886 | #endif |
|
|
887 | #ifndef __STRICT_ANSI__ |
|
|
888 | #ifndef MACH |
|
|
889 | printf("<memory.h\n"); |
|
|
890 | i=1; |
|
|
891 | #endif |
|
|
892 | #endif |
|
|
893 | #ifndef sgi |
|
|
894 | printf("<sys/timeb.h>\n"); |
|
|
895 | i=1; |
|
|
896 | #endif |
|
|
897 | if(!i) |
|
|
898 | printf("(none)\n"); |
|
|
899 | printf("Datadir:\t\t%s\n",settings.datadir); |
|
|
900 | printf("Localdir:\t\t%s\n",settings.localdir); |
|
|
901 | #ifdef PERM_FILE |
|
|
902 | printf("Perm file:\t<ETC>/%s\n",PERM_FILE); |
|
|
903 | #endif |
|
|
904 | #ifdef SHUTDOWN_FILE |
|
|
905 | printf("Shutdown file:\t<ETC>/%s\n",SHUTDOWN_FILE); |
|
|
906 | #endif |
|
|
907 | printf("Save player:\t<true>\n"); |
|
|
908 | printf("Save mode:\t%4.4o\n",SAVE_MODE); |
|
|
909 | printf("Playerdir:\t<VAR>/%s\n",settings.playerdir); |
|
|
910 | printf("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
|
|
911 | printf("Tmpdir:\t\t%s\n",settings.tmpdir); |
|
|
912 | printf("Map max timeout:\t%d\n",MAP_MAXTIMEOUT); |
|
|
913 | printf("Max objects:\t%d\n",MAX_OBJECTS); |
|
|
914 | #ifdef USE_CALLOC |
|
|
915 | printf("Use_calloc:\t<true>\n"); |
|
|
916 | #else |
|
|
917 | printf("Use_calloc:\t<false>\n"); |
|
|
918 | #endif |
|
|
919 | |
|
|
920 | #ifdef X_EDITOR |
|
|
921 | printf("Editor:\t\t%s\n",X_EDITOR); |
|
|
922 | #endif |
|
|
923 | |
|
|
924 | printf("Max_time:\t%d\n",MAX_TIME); |
|
|
925 | |
|
|
926 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
927 | printf("Logfilename:\t%s\n",settings.logfilename); |
|
|
928 | exit(0); |
1004 | exit (0); |
929 | #else |
1005 | } |
930 | execl("/bin/uname", "uname", "-a", NULL); |
1006 | |
931 | LOG(llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror(errno)); |
1007 | void |
932 | exit(-1); |
1008 | init_beforeplay (void) |
933 | #endif |
1009 | { |
|
|
1010 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
|
|
1011 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
1012 | init_gods (); /* init linked list of gods from archs */ |
|
|
1013 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
1014 | init_formulae (); /* If not called before, reads formulae from file */ |
934 | } |
1015 | } |
935 | |
1016 | |
936 | /* Signal handlers: */ |
1017 | /* Signal handlers: */ |
937 | |
1018 | |
|
|
1019 | static void |
|
|
1020 | rec_sigabrt (int i) |
|
|
1021 | { |
|
|
1022 | signal (SIGABRT, SIG_DFL); |
|
|
1023 | |
|
|
1024 | LOG (llevError, "SIGABRT received.\n"); |
|
|
1025 | cleanup ("SIGABRT received", 1); |
|
|
1026 | } |
|
|
1027 | |
|
|
1028 | static void |
938 | void rec_sigsegv(int i) { |
1029 | rec_sigsegv (int i) |
|
|
1030 | { |
|
|
1031 | signal (SIGSEGV, SIG_DFL); |
|
|
1032 | |
939 | LOG(llevError,"\nSIGSEGV received.\n"); |
1033 | LOG (llevError, "SIGSEGV received.\n"); |
940 | fatal_signal(1, 1); |
1034 | cleanup ("SIGSEGV received", 1); |
941 | } |
1035 | } |
942 | |
1036 | |
943 | void rec_sigint(int i) { |
1037 | static void |
944 | LOG(llevInfo,"\nSIGINT received.\n"); |
|
|
945 | fatal_signal(0, 1); |
|
|
946 | } |
|
|
947 | |
|
|
948 | void rec_sighup(int i) { |
|
|
949 | LOG(llevInfo,"\nSIGHUP received\n"); |
|
|
950 | if(init_done) { |
|
|
951 | emergency_save(0); |
|
|
952 | cleanup(); |
|
|
953 | } |
|
|
954 | exit(0); |
|
|
955 | } |
|
|
956 | |
|
|
957 | void rec_sigquit(int i) { |
1038 | rec_sigquit (int i) |
|
|
1039 | { |
|
|
1040 | signal (SIGQUIT, SIG_IGN); |
|
|
1041 | |
958 | LOG(llevInfo,"\nSIGQUIT received\n"); |
1042 | LOG (llevInfo, "SIGQUIT received\n"); |
959 | fatal_signal(1, 1); |
1043 | cleanup ("SIGQUIT received", 1); |
960 | } |
1044 | } |
961 | |
1045 | |
|
|
1046 | static void |
962 | void rec_sigbus(int i) { |
1047 | rec_sigbus (int i) |
963 | #ifdef SIGBUS |
1048 | { |
|
|
1049 | signal (SIGBUS, SIG_DFL); |
|
|
1050 | |
964 | LOG(llevError,"\nSIGBUS received\n"); |
1051 | LOG (llevError, "SIGBUS received\n"); |
965 | fatal_signal(1, 1); |
1052 | cleanup ("SIGBUS received", 1); |
966 | #endif |
|
|
967 | } |
1053 | } |
968 | |
1054 | |
969 | void rec_sigterm(int i) { |
1055 | void |
970 | LOG(llevInfo,"\nSIGTERM received\n"); |
1056 | reset_signals () |
971 | fatal_signal(0, 1); |
1057 | { |
|
|
1058 | signal (SIGABRT, SIG_DFL); |
|
|
1059 | signal (SIGQUIT, SIG_DFL); |
|
|
1060 | signal (SIGSEGV, SIG_DFL); |
|
|
1061 | signal (SIGBUS , SIG_DFL); |
|
|
1062 | signal (SIGINT , SIG_DFL); |
|
|
1063 | signal (SIGTERM, SIG_DFL); |
972 | } |
1064 | } |
973 | |
1065 | |
974 | void fatal_signal(int make_core, int close_sockets) { |
1066 | void |
975 | if(init_done) { |
|
|
976 | emergency_save(0); |
|
|
977 | clean_tmp_files(); |
|
|
978 | } |
|
|
979 | if(make_core) |
|
|
980 | abort(); |
|
|
981 | exit(0); |
|
|
982 | } |
|
|
983 | |
|
|
984 | void init_signals(void) { |
1067 | init_signals (void) |
985 | #ifndef WIN32 /* init_signals() remove signals */ |
1068 | { |
986 | signal(SIGHUP,rec_sighup); |
1069 | // large stack, but it's important data we want to save, and it is not usually |
987 | signal(SIGINT,rec_sigint); |
1070 | // being physically allocated anyways |
988 | signal(SIGQUIT,rec_sigquit); |
1071 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
989 | signal(SIGSEGV,rec_sigsegv); |
1072 | |
990 | signal(SIGPIPE,SIG_IGN); |
1073 | stack_t ss; |
991 | #ifdef SIGBUS |
1074 | ss.ss_sp = malloc (stacksize); |
992 | signal(SIGBUS,rec_sigbus); |
1075 | ss.ss_flags = 0; |
993 | #endif |
1076 | ss.ss_size = stacksize; |
994 | signal(SIGTERM,rec_sigterm); |
1077 | sigaltstack (&ss, 0); |
995 | #endif |
1078 | |
|
|
1079 | struct sigaction sa; |
|
|
1080 | |
|
|
1081 | sigfillset (&sa.sa_mask); |
|
|
1082 | sa.sa_flags = SA_RESTART; |
|
|
1083 | |
|
|
1084 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
1085 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
|
|
1086 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
1087 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
|
|
1088 | |
|
|
1089 | sa.sa_flags |= SA_ONSTACK; |
|
|
1090 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
996 | } |
1091 | } |
997 | |
1092 | |
998 | /* init_races() - reads the races file in the lib/ directory, then |
1093 | /* init_races() - reads the races file in the lib/ directory, then |
999 | * overwrites old 'race' entries. This routine allow us to quickly |
1094 | * overwrites old 'race' entries. This routine allow us to quickly |
1000 | * re-configure the 'alignment' of monsters, objects. Useful for |
1095 | * re-configure the 'alignment' of monsters, objects. Useful for |
1001 | * putting together lists of creatures, etc that belong to gods. |
1096 | * putting together lists of creatures, etc that belong to gods. |
1002 | */ |
1097 | */ |
1003 | |
1098 | void |
1004 | void init_races (void) |
1099 | init_races (void) |
1005 | { |
1100 | { |
1006 | FILE *file; |
1101 | FILE *file; |
1007 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1102 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1008 | archetype *mon = NULL; |
1103 | archetype *mon = NULL; |
1009 | static int init_done = 0; |
1104 | static int init_done = 0; |
1010 | |
1105 | |
1011 | if (init_done) |
1106 | if (init_done) |
1012 | return; |
1107 | return; |
1013 | init_done = 1; |
1108 | init_done = 1; |
1014 | first_race = NULL; |
1109 | first_race = 0; |
1015 | |
1110 | |
1016 | sprintf (fname, "%s/races", settings.datadir); |
1111 | sprintf (fname, "%s/races", settings.datadir); |
1017 | LOG (llevDebug, "Reading races from %s...", fname); |
1112 | LOG (llevDebug, "Reading races from %s...\n", fname); |
1018 | if (!(file = fopen (fname, "r"))) |
1113 | if (!(file = fopen (fname, "r"))) |
1019 | { |
1114 | { |
1020 | LOG (llevError, "Cannot open races file %s: %s\n", fname, |
1115 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
1021 | strerror (errno)); |
|
|
1022 | return; |
1116 | return; |
1023 | } |
1117 | } |
1024 | |
1118 | |
1025 | while (fgets (buf, MAX_BUF, file) != NULL) |
1119 | while (fgets (buf, MAX_BUF, file) != NULL) |
1026 | { |
1120 | { |
1027 | int set_race = 1, set_list = 1; |
1121 | int set_race = 1, set_list = 1; |
|
|
1122 | |
1028 | if (*buf == '#') |
1123 | if (*buf == '#') |
1029 | continue; |
1124 | continue; |
|
|
1125 | |
1030 | if ((cp = strchr (buf, '\n')) != NULL) |
1126 | if ((cp = strchr (buf, '\n')) != NULL) |
1031 | *cp = '\0'; |
1127 | *cp = '\0'; |
|
|
1128 | |
1032 | cp = buf; |
1129 | cp = buf; |
1033 | while (*cp == ' ' || *cp == '!' || *cp == '@') |
1130 | while (*cp == ' ' || *cp == '!' || *cp == '@') |
1034 | { |
1131 | { |
1035 | if (*cp == '!') |
1132 | if (*cp == '!') |
1036 | set_race = 0; |
1133 | set_race = 0; |
1037 | if (*cp == '@') |
1134 | if (*cp == '@') |
1038 | set_list = 0; |
1135 | set_list = 0; |
1039 | cp++; |
1136 | cp++; |
1040 | } |
1137 | } |
|
|
1138 | |
1041 | if (sscanf (cp, "RACE %s", variable)) |
1139 | if (sscanf (cp, "RACE %s", variable)) |
1042 | { /* set new race value */ |
1140 | /* set new race value */ |
1043 | strcpy (race, variable); |
1141 | strcpy (race, variable); |
1044 | } |
|
|
1045 | else |
1142 | else |
1046 | { |
1143 | { |
1047 | char *cp1; |
1144 | char *cp1; |
|
|
1145 | |
1048 | /* Take out beginning spaces */ |
1146 | /* Take out beginning spaces */ |
1049 | for (cp1 = cp; *cp1 == ' '; cp1++) |
1147 | for (cp1 = cp; *cp1 == ' '; cp1++) |
1050 | ; |
1148 | ; |
1051 | /* Remove newline and trailing spaces */ |
1149 | /* Remove newline and trailing spaces */ |
1052 | for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
1150 | for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
… | |
… | |
1056 | break; |
1154 | break; |
1057 | } |
1155 | } |
1058 | |
1156 | |
1059 | if (cp[strlen (cp) - 1] == '\n') |
1157 | if (cp[strlen (cp) - 1] == '\n') |
1060 | cp[strlen (cp) - 1] = '\0'; |
1158 | cp[strlen (cp) - 1] = '\0'; |
|
|
1159 | |
1061 | /* set creature race to race value */ |
1160 | /* set creature race to race value */ |
1062 | if ((mon = find_archetype (cp)) == NULL) |
1161 | if ((mon = archetype::find (cp)) == NULL) |
1063 | LOG (llevError, "\nCreature %s in race file lacks archetype", cp); |
1162 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1064 | else |
1163 | else |
1065 | { |
1164 | { |
1066 | if (set_race |
|
|
1067 | && (!mon->clone.race || strcmp (mon->clone.race, race))) |
1165 | if (set_race && (!mon->race || strcmp (mon->race, race))) |
1068 | { |
1166 | { |
1069 | if (mon->clone.race) |
1167 | if (mon->race) |
1070 | { |
1168 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname); |
1071 | LOG (llevDebug, |
1169 | |
1072 | "\n Resetting race to %s from %s for archetype %s", |
|
|
1073 | race, &mon->clone.race, &mon->name); |
|
|
1074 | } |
|
|
1075 | mon->clone.race = race; |
1170 | mon->race = race; |
1076 | } |
1171 | } |
|
|
1172 | |
1077 | /* if the arch is a monster, add it to the race list */ |
1173 | /* if the arch is a monster, add it to the race list */ |
1078 | if (set_list && QUERY_FLAG (&mon->clone, FLAG_MONSTER)) |
1174 | if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) |
1079 | add_to_racelist (race, &mon->clone); |
1175 | add_to_racelist (race, mon); |
1080 | } |
|
|
1081 | } |
1176 | } |
|
|
1177 | } |
1082 | } |
1178 | } |
|
|
1179 | |
1083 | fclose (file); |
1180 | fclose (file); |
1084 | LOG (llevDebug, "done.\n"); |
1181 | LOG (llevDebug, "done.\n"); |
1085 | } |
1182 | } |
1086 | |
1183 | |
|
|
1184 | void |
1087 | void dump_races(void) |
1185 | dump_races (void) |
1088 | { |
1186 | { |
1089 | racelink *list; |
1187 | racelink *list; |
1090 | objectlink *tmp; |
1188 | objectlink *tmp; |
|
|
1189 | |
1091 | for(list=first_race;list;list=list->next) { |
1190 | for (list = first_race; list; list = list->next) |
|
|
1191 | { |
1092 | fprintf(stderr,"\nRACE %s:\t",list->name); |
1192 | fprintf (stderr, "\nRACE %s:\t", &list->name); |
1093 | for(tmp=list->member;tmp;tmp=tmp->next) |
1193 | for (tmp = list->member; tmp; tmp = tmp->next) |
1094 | fprintf(stderr,"%s(%d), ",&tmp->ob->arch->name,tmp->ob->level); |
1194 | fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level); |
1095 | } |
1195 | } |
|
|
1196 | |
1096 | fprintf(stderr,"\n"); |
1197 | fprintf (stderr, "\n"); |
1097 | } |
1198 | } |
1098 | |
1199 | |
|
|
1200 | void |
1099 | void add_to_racelist (const char *race_name, object *op) { |
1201 | add_to_racelist (const char *race_name, object *op) |
|
|
1202 | { |
1100 | racelink *race; |
1203 | racelink *race; |
1101 | |
1204 | |
1102 | if(!op||!race_name) return; |
1205 | if (!op || !race_name) |
|
|
1206 | return; |
|
|
1207 | |
1103 | race=find_racelink(race_name); |
1208 | race = find_racelink (race_name); |
1104 | |
1209 | |
1105 | if(!race) { /* add in a new race list */ |
1210 | if (!race) |
|
|
1211 | { /* add in a new race list */ |
1106 | race = get_racelist(); |
1212 | race = get_racelist (); |
1107 | race->next = first_race; |
1213 | race->next = first_race; |
1108 | first_race = race; |
1214 | first_race = race; |
1109 | race->name = race_name; |
1215 | race->name = race_name; |
1110 | } |
1216 | } |
1111 | |
1217 | |
1112 | if(race->member->ob) { |
1218 | if (race->member->ob) |
|
|
1219 | { |
1113 | objectlink *tmp = get_objectlink(); |
1220 | objectlink *tmp = get_objectlink (); |
|
|
1221 | |
1114 | tmp->next=race->member; |
1222 | tmp->next = race->member; |
1115 | race->member = tmp; |
1223 | race->member = tmp; |
1116 | } |
1224 | } |
|
|
1225 | |
1117 | race->nrof++; |
1226 | race->nrof++; |
1118 | race->member->ob = op; |
1227 | race->member->ob = op; |
1119 | } |
1228 | } |
1120 | |
1229 | |
1121 | racelink * get_racelist ( ) { |
1230 | racelink * |
1122 | racelink *list; |
1231 | get_racelist () |
1123 | |
1232 | { |
1124 | list = (racelink *) malloc(sizeof(racelink )); |
1233 | racelink *list = new racelink; |
|
|
1234 | |
1125 | list->name=NULL; |
1235 | list->name = 0; |
1126 | list->nrof=0; |
1236 | list->nrof = 0; |
|
|
1237 | list->next = 0; |
1127 | list->member=get_objectlink(); |
1238 | list->member = get_objectlink (); |
1128 | list->next=NULL; |
|
|
1129 | |
1239 | |
1130 | return list; |
1240 | return list; |
1131 | } |
1241 | } |
1132 | |
1242 | |
|
|
1243 | racelink * |
1133 | racelink * find_racelink( const char *name ) { |
1244 | find_racelink (const char *name) |
1134 | racelink *test=NULL; |
1245 | { |
1135 | |
1246 | if (name) |
1136 | if(name&&first_race) |
1247 | for (racelink *link = first_race; link; link = link->next) |
1137 | for(test=first_race;test&&test!=test->next;test=test->next) |
1248 | if (!link->name || !strcmp (name, link->name)) |
1138 | if(!test->name||!strcmp(name,test->name)) break; |
1249 | return link; |
1139 | |
1250 | |
1140 | return test; |
1251 | return 0; |
1141 | } |
1252 | } |