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