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