1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * "$Id: init.C,v 1.3 2006/08/29 05:03:55 root Exp $"; |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
|
|
9 | * the terms of the Affero GNU General Public License as published by the |
|
|
10 | * Free Software Foundation, either version 3 of the License, or (at your |
|
|
11 | * 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 Affero GNU General Public License |
|
|
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
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 | //TODO: make this a constructor |
37 | weathermap_t **weathermap; |
31 | static materialtype_t * |
38 | |
32 | get_empty_mat (void) |
39 | void set_logfile(char *val) { settings.logfilename=val; } |
|
|
40 | void call_version(void) { version(NULL); exit(0); } |
|
|
41 | void showscores(void) { display_high_score(NULL,9999,NULL); exit(0); } |
|
|
42 | void set_debug(void) { settings.debug=llevDebug; } |
|
|
43 | void unset_debug(void) { settings.debug=llevInfo; } |
|
|
44 | void set_mondebug(void) { settings.debug=llevMonster; } |
|
|
45 | void set_dumpmon1(void) {settings.dumpvalues=1; } |
|
|
46 | void set_dumpmon2(void) {settings.dumpvalues=2; } |
|
|
47 | void set_dumpmon3(void) {settings.dumpvalues=3; } |
|
|
48 | void set_dumpmon4(void) {settings.dumpvalues=4; } |
|
|
49 | void set_dumpmon5(void) {settings.dumpvalues=5; } |
|
|
50 | void set_dumpmon6(void) {settings.dumpvalues=6; } |
|
|
51 | void set_dumpmon7(void) {settings.dumpvalues=7; } |
|
|
52 | void set_dumpmon8(void) {settings.dumpvalues=8; } |
|
|
53 | void set_dumpmon9(void) {settings.dumpvalues=9; } |
|
|
54 | void set_dumpmont(char *name) {settings.dumpvalues=10; settings.dumparg=name; } |
|
|
55 | void set_daemon(void) {settings.daemonmode=1; } |
|
|
56 | void set_datadir(char *path) { settings.datadir=path; } |
|
|
57 | void set_confdir(char *path) { settings.confdir=path; } |
|
|
58 | void set_localdir(char *path) { settings.localdir=path; } |
|
|
59 | void set_mapdir(char *path) { settings.mapdir=path; } |
|
|
60 | void set_archetypes(char *path) { settings.archetypes=path; } |
|
|
61 | void set_regions(char *path) { settings.regions=path; } |
|
|
62 | void set_treasures(char *path) { settings.treasures=path; } |
|
|
63 | void set_uniquedir(char *path) { settings.uniquedir=path; } |
|
|
64 | void set_templatedir(char *path) { settings.templatedir=path; } |
|
|
65 | void set_playerdir(char *path) { settings.playerdir=path; } |
|
|
66 | void set_tmpdir(char *path) { settings.tmpdir=path; } |
|
|
67 | |
|
|
68 | void showscoresparm(char *data) { |
|
|
69 | display_high_score(NULL,9999,data); |
|
|
70 | exit(0); |
|
|
71 | } |
|
|
72 | |
|
|
73 | void set_csport(char *val) |
|
|
74 | { |
|
|
75 | settings.csport=atoi(val); |
|
|
76 | #ifndef WIN32 /* ***win32: set_csport: we remove csport error secure check here, do this later */ |
|
|
77 | if (settings.csport<=0 || settings.csport>32765 || |
|
|
78 | (settings.csport<1024 && getuid()!=0)) { |
|
|
79 | LOG(llevError, "%d is an invalid csport number.\n", settings.csport); |
|
|
80 | exit(1); |
|
|
81 | } |
|
|
82 | #endif /* win32 */ |
|
|
83 | } |
|
|
84 | |
|
|
85 | /* Most of this is shamelessly stolen from XSysStats. But since that is |
|
|
86 | * also my program, no problem. |
|
|
87 | */ |
|
|
88 | struct Command_Line_Options { |
|
|
89 | const char *cmd_option; /* how it is called on the command line */ |
|
|
90 | uint8 num_args; /* Number or args it takes */ |
|
|
91 | uint8 pass; /* What pass this should be processed on. */ |
|
|
92 | void (*func)(); /* function to call when we match this. |
|
|
93 | * if num_args is true, than that gets passed |
|
|
94 | * to the function, otherwise nothing is passed |
|
|
95 | */ |
|
|
96 | }; |
|
|
97 | |
|
|
98 | /* 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 |
|
|
100 | * matches both in name and in pass (and we have enough options), |
|
|
101 | * we call the associated function. This makes writing a multi |
|
|
102 | * pass system very easy, and it is very easy to add in new options. |
|
|
103 | */ |
|
|
104 | struct Command_Line_Options options[] = { |
|
|
105 | |
|
|
106 | /* Pass 1 functions - STuff that can/should be called before we actually |
|
|
107 | * initialize any data. |
|
|
108 | */ |
|
|
109 | {"-h", 0, 1, help}, |
|
|
110 | /* Honor -help also, since it is somewhat common */ |
|
|
111 | {"-help", 0, 1, help}, |
|
|
112 | {"-v", 0, 1, call_version}, |
|
|
113 | {"-d", 0, 1, set_debug}, |
|
|
114 | {"+d", 0, 1, unset_debug}, |
|
|
115 | {"-mon", 0, 1, set_mondebug}, |
|
|
116 | {"-data",1,1, (void (*)())set_datadir}, |
|
|
117 | {"-conf",1,1, (void (*)())set_confdir}, |
|
|
118 | {"-local",1,1,(void (*)()) set_localdir}, |
|
|
119 | {"-maps", 1, 1,(void (*)()) set_mapdir}, |
|
|
120 | {"-arch", 1, 1,(void (*)()) set_archetypes}, |
|
|
121 | {"-regions", 1, 1,(void (*)()) set_regions}, |
|
|
122 | {"-playerdir", 1, 1,(void (*)()) set_playerdir}, |
|
|
123 | {"-treasures", 1, 1,(void (*)()) set_treasures}, |
|
|
124 | {"-uniquedir", 1, 1,(void (*)()) set_uniquedir}, |
|
|
125 | {"-templatedir", 1, 1,(void (*)()) set_templatedir}, |
|
|
126 | {"-tmpdir", 1, 1,(void (*)()) set_tmpdir}, |
|
|
127 | {"-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 | |
|
|
136 | /* 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. |
|
|
138 | */ |
|
|
139 | {"-csport", 1, 2,(void (*)()) set_csport}, |
|
|
140 | {"-detach", 0, 2, set_daemon}, |
|
|
141 | |
|
|
142 | /* Start of pass 3 information. In theory, by pass 3, all data paths |
|
|
143 | * and defaults should have been set up. |
|
|
144 | */ |
|
|
145 | {"-o", 0, 3, compile_info}, |
|
|
146 | {"-m", 0, 3, set_dumpmon1}, |
|
|
147 | {"-m2", 0, 3, set_dumpmon2}, |
|
|
148 | {"-m3", 0, 3, set_dumpmon3}, |
|
|
149 | {"-m4", 0, 3, set_dumpmon4}, |
|
|
150 | {"-m5", 0, 3, set_dumpmon5}, |
|
|
151 | {"-m6", 0, 3, set_dumpmon6}, |
|
|
152 | {"-m7", 0, 3, set_dumpmon7}, |
|
|
153 | {"-m8", 0, 3, set_dumpmon8}, |
|
|
154 | {"-m9", 0, 3, set_dumpmon9}, |
|
|
155 | {"-mt", 1, 3, (void (*)())set_dumpmont}, |
|
|
156 | {"-mexp", 0, 3, dump_experience}, |
|
|
157 | {"-s", 0, 3, showscores}, |
|
|
158 | {"-score", 1, 3, (void (*)())showscoresparm} |
|
|
159 | }; |
|
|
160 | |
|
|
161 | |
|
|
162 | /* 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. |
|
|
164 | */ |
|
|
165 | static void parse_args(int argc, char *argv[], int pass) |
|
|
166 | { |
33 | { |
167 | size_t i; |
|
|
168 | int on_arg=1; |
|
|
169 | |
|
|
170 | 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; |
34 | materialtype_t *mt; |
210 | int i; |
35 | int i; |
211 | |
36 | |
212 | mt = (materialtype_t *)malloc(sizeof(materialtype_t)); |
37 | mt = new materialtype_t; |
213 | if (mt == NULL) |
38 | |
214 | fatal(OUT_OF_MEMORY); |
39 | mt->name = shstr_unknown; |
215 | mt->name = NULL; |
|
|
216 | mt->description = NULL; |
40 | mt->description = 0; |
|
|
41 | |
217 | for (i=0; i < NROFATTACKS; i++) { |
42 | 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 | { |
43 | { |
321 | free(mt->next); |
44 | mt->save[i] = 0; |
322 | mt->next = NULL; |
45 | mt->mod[i] = 0; |
|
|
46 | } |
|
|
47 | |
|
|
48 | mt->chance = 0; |
|
|
49 | mt->difficulty = 0; |
|
|
50 | mt->magic = 0; |
|
|
51 | mt->damage = 0; |
|
|
52 | mt->wc = 0; |
|
|
53 | mt->ac = 0; |
|
|
54 | mt->sp = 0; |
|
|
55 | mt->weight = 100; |
|
|
56 | mt->value = 100; |
|
|
57 | mt->density = 1; |
|
|
58 | mt->next = 0; |
|
|
59 | |
|
|
60 | return mt; |
|
|
61 | } |
|
|
62 | |
|
|
63 | void |
|
|
64 | load_materials (void) |
|
|
65 | { |
|
|
66 | char filename[MAX_BUF]; |
|
|
67 | |
|
|
68 | sprintf (filename, "%s/materials", settings.datadir); |
|
|
69 | LOG (llevDebug, "Reading material type data from %s...\n", filename); |
|
|
70 | |
|
|
71 | //TODO: somehow free old materials, or update them in-place |
|
|
72 | materialt = 0; |
|
|
73 | |
|
|
74 | object_thawer thawer (filename); |
|
|
75 | |
|
|
76 | if (!thawer) |
323 | } |
77 | { |
|
|
78 | LOG (llevError, "Cannot open %s for reading\n", filename); |
|
|
79 | goto done; |
|
|
80 | } |
|
|
81 | |
|
|
82 | while (thawer.kw != KW_name) |
|
|
83 | { |
|
|
84 | thawer.next (); |
|
|
85 | |
|
|
86 | if (thawer.kw == KW_EOF) |
|
|
87 | goto done; |
|
|
88 | } |
|
|
89 | |
|
|
90 | materialtype_t *mt; |
|
|
91 | |
|
|
92 | for (;;) |
|
|
93 | { |
|
|
94 | switch (thawer.kw) |
|
|
95 | { |
|
|
96 | case KW_name: |
|
|
97 | mt = get_empty_mat (); |
|
|
98 | mt->next = materialt; |
|
|
99 | materialt = mt; |
|
|
100 | |
|
|
101 | thawer.get (mt->name); |
|
|
102 | mt->description = mt->name; |
|
|
103 | break; |
|
|
104 | |
|
|
105 | case KW_description: |
|
|
106 | thawer.get (mt->description); |
|
|
107 | break; |
|
|
108 | |
|
|
109 | case KW_material: |
|
|
110 | thawer.get (mt->material); |
|
|
111 | break; |
|
|
112 | |
|
|
113 | case KW_saves: |
|
|
114 | { |
|
|
115 | const char *cp = thawer.get_str () - 1; |
|
|
116 | |
|
|
117 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
118 | { |
|
|
119 | if (!cp) |
|
|
120 | { |
|
|
121 | mt->save[i] = 0; |
|
|
122 | continue; |
|
|
123 | } |
|
|
124 | |
|
|
125 | int value; |
|
|
126 | ++cp; |
|
|
127 | sscanf (cp, "%d", &value); |
|
|
128 | mt->save[i] = (sint8) value; |
|
|
129 | cp = strchr (cp, ','); |
|
|
130 | } |
|
|
131 | } |
|
|
132 | break; |
|
|
133 | |
|
|
134 | case KW_mods: |
|
|
135 | { |
|
|
136 | const char *cp = thawer.get_str () - 1; |
|
|
137 | |
|
|
138 | for (int i = 0; i < NROFATTACKS; i++) |
|
|
139 | { |
|
|
140 | if (!cp) |
|
|
141 | { |
|
|
142 | mt->save[i] = 0; |
|
|
143 | continue; |
|
|
144 | } |
|
|
145 | |
|
|
146 | ++cp; |
|
|
147 | int value; |
|
|
148 | sscanf (cp, "%d", &value); |
|
|
149 | mt->mod[i] = (sint8) value; |
|
|
150 | cp = strchr (cp, ','); |
|
|
151 | } |
|
|
152 | } |
|
|
153 | break; |
|
|
154 | |
|
|
155 | case KW_chance: thawer.get (mt->chance); break; |
|
|
156 | case KW_difficulty: // cf+ alias, not original cf |
|
|
157 | case KW_diff: thawer.get (mt->difficulty); break; |
|
|
158 | case KW_magic: thawer.get (mt->magic); break; |
|
|
159 | case KW_dam: // cf+ alias, not original cf |
|
|
160 | case KW_damage: thawer.get (mt->damage); break; |
|
|
161 | case KW_wc: thawer.get (mt->wc); break; |
|
|
162 | case KW_ac: thawer.get (mt->ac); break; |
|
|
163 | case KW_sp: thawer.get (mt->sp); break; |
|
|
164 | case KW_weight: thawer.get (mt->weight); break; |
|
|
165 | case KW_value: thawer.get (mt->value); break; |
|
|
166 | case KW_density: thawer.get (mt->density); break; |
|
|
167 | |
|
|
168 | case KW_EOF: |
|
|
169 | goto done; |
|
|
170 | |
|
|
171 | default: |
|
|
172 | if (!thawer.parse_error ("materials file", "materials")) |
|
|
173 | goto done; |
|
|
174 | break; |
|
|
175 | } |
|
|
176 | |
|
|
177 | thawer.next (); |
|
|
178 | } |
|
|
179 | |
|
|
180 | done: |
|
|
181 | if (!materialt) |
|
|
182 | materialt = get_empty_mat (); |
|
|
183 | |
324 | LOG(llevDebug, "Done.\n"); |
184 | LOG (llevDebug, "Done.\n"); |
325 | fclose(fp); |
|
|
326 | } |
185 | } |
327 | |
186 | |
328 | /* This loads the settings file. There could be debate whether this should |
187 | /* 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 |
188 | * be here or in the common directory - but since only the server needs this |
330 | * information, having it here probably makes more sense. |
189 | * information, having it here probably makes more sense. |
331 | */ |
190 | */ |
332 | static void load_settings(void) |
191 | void |
|
|
192 | load_settings (void) |
333 | { |
193 | { |
334 | char buf[MAX_BUF],*cp; |
194 | char buf[MAX_BUF], *cp; |
335 | int has_val,comp; |
195 | int has_val, comp; |
336 | FILE *fp; |
196 | FILE *fp; |
337 | |
197 | |
338 | sprintf(buf,"%s/settings",settings.confdir); |
198 | sprintf (buf, "%s/settings", settings.confdir); |
339 | |
199 | |
340 | /* We don't require a settings file at current time, but down the road, |
200 | /* 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 |
201 | * there will probably be so many values that not having a settings file |
342 | * will not be a good thing. |
202 | * will not be a good thing. |
343 | */ |
203 | */ |
344 | if ((fp = open_and_uncompress(buf, 0, &comp)) == NULL) { |
204 | if (!(fp = open_and_uncompress (buf, 0, &comp))) |
|
|
205 | { |
345 | LOG(llevError,"Warning: No settings file found\n"); |
206 | LOG (llevError, "Error: No settings file found\n"); |
346 | return; |
207 | exit (1); |
347 | } |
208 | } |
|
|
209 | |
348 | while (fgets(buf, MAX_BUF-1, fp) != NULL) { |
210 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
349 | if (buf[0] == '#') continue; |
211 | { |
|
|
212 | if (buf[0] == '#') |
|
|
213 | continue; |
350 | /* eliminate newline */ |
214 | /* eliminate newline */ |
351 | if ((cp=strrchr(buf,'\n'))!=NULL) *cp='\0'; |
215 | if ((cp = strrchr (buf, '\n')) != NULL) |
|
|
216 | *cp = '\0'; |
352 | |
217 | |
353 | /* Skip over empty lines */ |
218 | /* Skip over empty lines */ |
354 | if (buf[0] == 0) continue; |
219 | if (buf[0] == 0) |
|
|
220 | continue; |
355 | |
221 | |
356 | /* Skip all the spaces and set them to nulls. If not space, |
222 | /* 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. |
223 | * set cp to "" to make strcpy's and the like easier down below. |
358 | */ |
224 | */ |
359 | if ((cp = strchr(buf,' '))!=NULL) { |
225 | if ((cp = strchr (buf, ' ')) != NULL) |
360 | while (*cp==' ') *cp++=0; |
226 | { |
|
|
227 | while (*cp == ' ') |
|
|
228 | *cp++ = 0; |
361 | has_val=1; |
229 | has_val = 1; |
362 | } else { |
230 | } |
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 |
231 | else |
379 | LOG(llevError,"load_settings: metaserver_server must have a value.\n"); |
232 | { |
|
|
233 | cp = (char *)""; |
|
|
234 | has_val = 0; |
|
|
235 | } |
|
|
236 | |
380 | } else if (!strcasecmp(buf,"motd")) { |
237 | if (!strcasecmp (buf, "motd")) |
|
|
238 | { |
381 | if (has_val) |
239 | if (has_val) |
382 | strcpy(settings.motd, cp); |
240 | strcpy (settings.motd, cp); |
383 | else |
241 | else |
384 | LOG(llevError,"load_settings: motd must have a value.\n"); |
242 | LOG (llevError, "load_settings: motd must have a value.\n"); |
|
|
243 | } |
385 | } else if (!strcasecmp(buf,"dm_mail")) { |
244 | else if (!strcasecmp (buf, "dm_mail")) |
|
|
245 | { |
386 | if (has_val) |
246 | if (has_val) |
387 | strcpy(settings.dm_mail, cp); |
247 | strcpy (settings.dm_mail, cp); |
388 | else |
248 | else |
389 | LOG(llevError,"load_settings: dm_mail must have a value.\n"); |
249 | LOG (llevError, "load_settings: dm_mail must have a value.\n"); |
390 | } else if (!strcasecmp(buf,"metaserver_host")) { |
250 | } |
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")) { |
251 | else if (!strcasecmp (buf, "worldmapstartx")) |
|
|
252 | { |
404 | int size = atoi(cp); |
253 | int size = atoi (cp); |
405 | |
254 | |
406 | if (size < 0) |
255 | if (size < 0) |
407 | LOG(llevError, "load_settings: worldmapstartx must be at least " |
256 | LOG (llevError, "load_settings: worldmapstartx must be at least " "0, %d is invalid\n", size); |
408 | "0, %d is invalid\n", size); |
257 | else |
409 | else |
|
|
410 | settings.worldmapstartx = size; |
258 | settings.worldmapstartx = size; |
|
|
259 | } |
411 | } else if (!strcasecmp(buf, "worldmapstarty")) { |
260 | else if (!strcasecmp (buf, "worldmapstarty")) |
|
|
261 | { |
412 | int size = atoi(cp); |
262 | int size = atoi (cp); |
413 | |
263 | |
414 | if (size < 0) |
264 | if (size < 0) |
415 | LOG(llevError, "load_settings: worldmapstarty must be at least " |
265 | LOG (llevError, "load_settings: worldmapstarty must be at least " "0, %d is invalid\n", size); |
416 | "0, %d is invalid\n", size); |
266 | else |
417 | else |
|
|
418 | settings.worldmapstarty = size; |
267 | settings.worldmapstarty = size; |
|
|
268 | } |
419 | } else if (!strcasecmp(buf, "worldmaptilesx")) { |
269 | else if (!strcasecmp (buf, "worldmaptilesx")) |
|
|
270 | { |
420 | int size = atoi(cp); |
271 | int size = atoi (cp); |
421 | |
272 | |
422 | if (size < 1) |
273 | if (size < 1) |
423 | LOG(llevError, "load_settings: worldmaptilesx must be greater " |
274 | LOG (llevError, "load_settings: worldmaptilesx must be greater " "than 1, %d is invalid\n", size); |
424 | "than 1, %d is invalid\n", size); |
275 | else |
425 | else |
|
|
426 | settings.worldmaptilesx = size; |
276 | settings.worldmaptilesx = size; |
|
|
277 | } |
427 | } else if (!strcasecmp(buf, "worldmaptilesy")) { |
278 | else if (!strcasecmp (buf, "worldmaptilesy")) |
|
|
279 | { |
428 | int size = atoi(cp); |
280 | int size = atoi (cp); |
429 | |
281 | |
430 | if (size < 1) |
282 | if (size < 1) |
431 | LOG(llevError, "load_settings: worldmaptilesy must be greater " |
283 | LOG (llevError, "load_settings: worldmaptilesy must be greater " "than 1, %d is invalid\n", size); |
432 | "than 1, %d is invalid\n", size); |
284 | else |
433 | else |
|
|
434 | settings.worldmaptilesy = size; |
285 | settings.worldmaptilesy = size; |
|
|
286 | } |
435 | } else if (!strcasecmp(buf, "worldmaptilesizex")) { |
287 | else if (!strcasecmp (buf, "worldmaptilesizex")) |
|
|
288 | { |
436 | int size = atoi(cp); |
289 | int size = atoi (cp); |
437 | |
290 | |
438 | if (size < 1) |
291 | if (size < 1) |
439 | LOG(llevError, "load_settings: worldmaptilesizex must be " |
292 | LOG (llevError, "load_settings: worldmaptilesizex must be " "greater than 1, %d is invalid\n", size); |
440 | "greater than 1, %d is invalid\n", size); |
293 | else |
441 | else |
|
|
442 | settings.worldmaptilesizex = size; |
294 | settings.worldmaptilesizex = size; |
|
|
295 | } |
443 | } else if (!strcasecmp(buf, "worldmaptilesizey")) { |
296 | else if (!strcasecmp (buf, "worldmaptilesizey")) |
|
|
297 | { |
444 | int size = atoi(cp); |
298 | int size = atoi (cp); |
445 | |
299 | |
446 | if (size < 1) |
300 | if (size < 1) |
447 | LOG(llevError, "load_settings: worldmaptilesizey must be " |
301 | LOG (llevError, "load_settings: worldmaptilesizey must be " "greater than 1, %d is invalid\n", size); |
448 | "greater than 1, %d is invalid\n", size); |
302 | else |
449 | else |
|
|
450 | settings.worldmaptilesizey = size; |
303 | settings.worldmaptilesizey = size; |
|
|
304 | } |
451 | } else if (!strcasecmp(buf, "dynamiclevel")) { |
305 | else if (!strcasecmp (buf, "dynamiclevel")) |
|
|
306 | { |
452 | int lev = atoi(cp); |
307 | int lev = atoi (cp); |
453 | |
308 | |
454 | if (lev < 0) |
309 | if (lev < 0) |
455 | LOG(llevError, "load_settings: dynamiclevel must be " |
310 | LOG (llevError, "load_settings: dynamiclevel must be " "at least 0, %d is invalid\n", lev); |
456 | "at least 0, %d is invalid\n", lev); |
311 | else |
457 | else |
|
|
458 | settings.dynamiclevel = lev; |
312 | settings.dynamiclevel = lev; |
|
|
313 | } |
459 | } else if (!strcasecmp(buf, "fastclock")) { |
314 | else if (!strcasecmp (buf, "fastclock")) |
|
|
315 | { |
460 | int lev = atoi(cp); |
316 | int lev = atoi (cp); |
461 | |
317 | |
462 | if (lev < 0) |
318 | if (lev < 0) |
463 | LOG(llevError, "load_settings: fastclock must be at least 0" |
319 | LOG (llevError, "load_settings: fastclock must be at least 0" ", %d is invalid\n", lev); |
464 | ", %d is invalid\n", lev); |
320 | else |
465 | else |
|
|
466 | settings.fastclock = lev; |
321 | settings.fastclock = lev; |
|
|
322 | } |
467 | } else if (!strcasecmp(buf, "not_permadeth")) { |
323 | else if (!strcasecmp (buf, "not_permadeth")) |
|
|
324 | { |
468 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
325 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
326 | { |
469 | settings.not_permadeth=TRUE; |
327 | settings.not_permadeth = TRUE; |
|
|
328 | } |
470 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
329 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
330 | { |
471 | settings.not_permadeth=FALSE; |
331 | settings.not_permadeth = FALSE; |
472 | } else { |
332 | } |
|
|
333 | else |
|
|
334 | { |
473 | LOG(llevError, "load_settings: Unknown value for not_permadeth" |
335 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
474 | ": %s\n", cp); |
336 | } |
475 | } |
337 | } |
476 | } else if (!strcasecmp(buf, "resurrection")) { |
338 | else if (!strcasecmp (buf, "resurrection")) |
|
|
339 | { |
477 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
340 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
341 | { |
478 | settings.resurrection=TRUE; |
342 | settings.resurrection = TRUE; |
|
|
343 | } |
479 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
344 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
345 | { |
480 | settings.resurrection=FALSE; |
346 | settings.resurrection = FALSE; |
481 | } else { |
347 | } |
|
|
348 | else |
|
|
349 | { |
482 | LOG(llevError, "load_settings: Unknown value for resurrection" |
350 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
483 | ": %s\n", cp); |
351 | } |
484 | } |
352 | } |
485 | } else if (!strcasecmp(buf, "set_title")) { |
353 | else if (!strcasecmp (buf, "set_title")) |
|
|
354 | { |
486 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
355 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
487 | settings.set_title=TRUE; |
356 | { |
|
|
357 | settings.set_title = TRUE; |
|
|
358 | } |
488 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
359 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
489 | settings.set_title=FALSE; |
360 | { |
490 | } else { |
361 | settings.set_title = FALSE; |
|
|
362 | } |
|
|
363 | else |
|
|
364 | { |
491 | LOG(llevError, "load_settings: Unknown value for set_title" |
365 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
492 | ": %s\n", cp); |
366 | } |
493 | } |
367 | } |
494 | } else if (!strcasecmp(buf, "search_items")) { |
368 | else if (!strcasecmp (buf, "search_items")) |
|
|
369 | { |
495 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
370 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
371 | { |
496 | settings.search_items=TRUE; |
372 | settings.search_items = TRUE; |
|
|
373 | } |
497 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
374 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
375 | { |
498 | settings.search_items=FALSE; |
376 | settings.search_items = FALSE; |
499 | } else { |
377 | } |
|
|
378 | else |
|
|
379 | { |
500 | LOG(llevError, "load_settings: Unknown value for search_items" |
380 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
501 | ": %s\n", cp); |
381 | } |
502 | } |
382 | } |
503 | } else if (!strcasecmp(buf, "spell_encumbrance")) { |
383 | else if (!strcasecmp (buf, "spell_encumbrance")) |
|
|
384 | { |
504 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
385 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
386 | { |
505 | settings.spell_encumbrance=TRUE; |
387 | settings.spell_encumbrance = TRUE; |
|
|
388 | } |
506 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
389 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
390 | { |
507 | settings.spell_encumbrance=FALSE; |
391 | settings.spell_encumbrance = FALSE; |
508 | } else { |
392 | } |
509 | LOG(llevError, "load_settings: Unknown value for " |
393 | else |
510 | "spell_encumbrance: %s\n", cp); |
394 | { |
511 | } |
395 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
|
|
396 | } |
|
|
397 | } |
512 | } else if (!strcasecmp(buf, "spell_failure_effects")) { |
398 | else if (!strcasecmp (buf, "spell_failure_effects")) |
|
|
399 | { |
513 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
400 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
401 | { |
514 | settings.spell_failure_effects=TRUE; |
402 | settings.spell_failure_effects = TRUE; |
|
|
403 | } |
515 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
404 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
405 | { |
516 | settings.spell_failure_effects=FALSE; |
406 | settings.spell_failure_effects = FALSE; |
517 | } else { |
407 | } |
518 | LOG(llevError, "load_settings: Unknown value for " |
408 | else |
519 | "spell_failure_effects: %s\n", cp); |
409 | { |
520 | } |
410 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
521 | } else if (!strcasecmp(buf, "casting_time")) { |
411 | } |
522 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
412 | } |
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")) { |
413 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
|
|
414 | { |
564 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
415 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
416 | { |
565 | settings.spellpoint_level_depend=TRUE; |
417 | settings.spellpoint_level_depend = TRUE; |
|
|
418 | } |
566 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
419 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
420 | { |
567 | settings.spellpoint_level_depend=FALSE; |
421 | settings.spellpoint_level_depend = FALSE; |
568 | } else { |
422 | } |
569 | LOG(llevError, "load_settings: Unknown value for " |
423 | else |
570 | "spellpoint_level_depend: %s\n", cp); |
424 | { |
571 | } |
425 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
|
|
426 | } |
|
|
427 | } |
572 | } else if (!strcasecmp(buf, "stat_loss_on_death")) { |
428 | else if (!strcasecmp (buf, "stat_loss_on_death")) |
|
|
429 | { |
573 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
430 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
431 | { |
574 | settings.stat_loss_on_death=TRUE; |
432 | settings.stat_loss_on_death = TRUE; |
|
|
433 | } |
575 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
434 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
435 | { |
576 | settings.stat_loss_on_death=FALSE; |
436 | settings.stat_loss_on_death = FALSE; |
577 | } else { |
437 | } |
578 | LOG(llevError, "load_settings: Unknown value for " |
438 | else |
579 | "stat_loss_on_death: %s\n", cp); |
439 | { |
580 | } |
440 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
|
|
441 | } |
|
|
442 | } |
581 | } else if (!strcasecmp(buf, "use_permanent_experience")) { |
443 | else if (!strcasecmp (buf, "use_permanent_experience")) |
582 | LOG(llevError, "use_permanent_experience is deprecated, use" |
444 | { |
583 | "permenent_experience_percentage instead\n"); |
445 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
|
|
446 | } |
584 | } else if (!strcasecmp(buf, "permanent_experience_percentage")) { |
447 | else if (!strcasecmp (buf, "permanent_experience_percentage")) |
|
|
448 | { |
585 | int val = atoi(cp); |
449 | int val = atoi (cp); |
|
|
450 | |
586 | if (val < 0 || val >100) |
451 | if (val < 0 || val > 100) |
587 | LOG(llevError, "load_settings: permenent_experience_percentage" |
452 | 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); |
453 | else |
589 | else |
|
|
590 | settings.permanent_exp_ratio = val; |
454 | settings.permanent_exp_ratio = val; |
|
|
455 | } |
591 | } else if (!strcasecmp(buf, "death_penalty_percentage")) { |
456 | else if (!strcasecmp (buf, "death_penalty_percentage")) |
|
|
457 | { |
592 | int val = atoi(cp); |
458 | int val = atoi (cp); |
|
|
459 | |
593 | if (val < 0 || val >100) |
460 | if (val < 0 || val > 100) |
594 | LOG(llevError, "load_settings: death_penalty_percentage" |
461 | 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); |
462 | else |
596 | else |
|
|
597 | settings.death_penalty_ratio = val; |
463 | settings.death_penalty_ratio = val; |
|
|
464 | } |
598 | } else if (!strcasecmp(buf, "death_penalty_levels")) { |
465 | else if (!strcasecmp (buf, "death_penalty_levels")) |
|
|
466 | { |
599 | int val = atoi(cp); |
467 | int val = atoi (cp); |
|
|
468 | |
600 | if (val < 0 || val > 255) |
469 | if (val < 0 || val > 255) |
601 | LOG(llevError, "load_settings: death_penalty_levels" |
470 | 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); |
471 | else |
603 | else |
|
|
604 | settings.death_penalty_level = val; |
472 | settings.death_penalty_level = val; |
|
|
473 | } |
605 | }else if (!strcasecmp(buf, "balanced_stat_loss")) { |
474 | else if (!strcasecmp (buf, "balanced_stat_loss")) |
|
|
475 | { |
606 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
476 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
477 | { |
607 | settings.balanced_stat_loss=TRUE; |
478 | settings.balanced_stat_loss = TRUE; |
|
|
479 | } |
608 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
480 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
481 | { |
609 | settings.balanced_stat_loss=FALSE; |
482 | settings.balanced_stat_loss = FALSE; |
610 | } else { |
483 | } |
611 | LOG(llevError, "load_settings: Unknown value for " |
484 | else |
612 | "balanced_stat_loss: %s\n", cp); |
485 | { |
613 | } |
486 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
|
|
487 | } |
|
|
488 | } |
614 | } else if (!strcasecmp(buf,"simple_exp")) { |
489 | else if (!strcasecmp (buf, "simple_exp")) |
|
|
490 | { |
615 | if (!strcasecmp(cp,"on") || !strcasecmp(cp,"true")) { |
491 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
616 | settings.simple_exp=TRUE; |
492 | { |
|
|
493 | settings.simple_exp = TRUE; |
|
|
494 | } |
617 | } else if (!strcasecmp(cp,"off") || !strcasecmp(cp,"false")) { |
495 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
618 | settings.simple_exp=FALSE; |
496 | { |
619 | } else { |
497 | settings.simple_exp = FALSE; |
|
|
498 | } |
|
|
499 | else |
|
|
500 | { |
620 | LOG(llevError,"load_settings: Unknown value for simple_exp: %s\n", |
501 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
621 | cp); |
502 | } |
622 | } |
503 | } |
623 | } else if (!strcasecmp(buf, "item_power_factor")) { |
504 | else if (!strcasecmp (buf, "item_power_factor")) |
|
|
505 | { |
624 | float tmp = atof(cp); |
506 | float tmp = atof (cp); |
|
|
507 | |
625 | if (tmp < 0) |
508 | if (tmp < 0) |
626 | LOG(llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", |
509 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
627 | tmp); |
510 | else |
628 | else |
|
|
629 | settings.item_power_factor = tmp; |
511 | settings.item_power_factor = tmp; |
|
|
512 | } |
630 | } else if (!strcasecmp(buf, "pk_luck_penalty")) { |
513 | else if (!strcasecmp (buf, "pk_luck_penalty")) |
|
|
514 | { |
631 | sint16 val = atoi(cp); |
515 | sint16 val = atoi (cp); |
632 | |
516 | |
633 | if (val < -100 || val >100) |
517 | if (val < -100 || val > 100) |
634 | LOG(llevError, "load_settings: pk_luck_penalty must be between -100 and 100" |
518 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
635 | ", %d is invalid\n", val); |
519 | else |
636 | else |
|
|
637 | settings.pk_luck_penalty = val; |
520 | settings.pk_luck_penalty = val; |
|
|
521 | } |
638 | } else if (!strcasecmp(buf, "set_friendly_fire")) { |
522 | else if (!strcasecmp (buf, "set_friendly_fire")) |
|
|
523 | { |
639 | int val = atoi(cp); |
524 | int val = atoi (cp); |
640 | |
525 | |
641 | #if COZY_SERVER |
|
|
642 | if (val < 0 || val >100) |
526 | if (val < 0 || val > 100) |
643 | LOG(llevError, "load_settings: set_friendly_fire must be between 0 an 100" |
527 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
644 | ", %d is invalid\n", val); |
528 | 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; |
529 | settings.set_friendly_fire = val; |
|
|
530 | } |
652 | } else if ( !strcasecmp( buf, "armor_max_enchant" ) ) { |
531 | else if (!strcasecmp (buf, "armor_max_enchant")) |
|
|
532 | { |
653 | int max_e = atoi( cp ); |
533 | int max_e = atoi (cp); |
|
|
534 | |
654 | if ( max_e <= 0 ) |
535 | if (max_e <= 0) |
655 | LOG( llevError, "load_settings: armor_max_enchant is %d\n", max_e ); |
536 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
656 | else |
537 | else |
657 | settings.armor_max_enchant = max_e; |
538 | settings.armor_max_enchant = max_e; |
|
|
539 | } |
658 | } else if ( !strcasecmp( buf, "armor_weight_reduction" ) ) { |
540 | else if (!strcasecmp (buf, "armor_weight_reduction")) |
|
|
541 | { |
659 | int wr = atoi( cp ); |
542 | int wr = atoi (cp); |
|
|
543 | |
660 | if ( wr < 0 ) |
544 | if (wr < 0) |
661 | LOG( llevError, "load_settings: armor_weight_reduction is %d\n", wr ); |
545 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
662 | else |
546 | else |
663 | settings.armor_weight_reduction = wr; |
547 | settings.armor_weight_reduction = wr; |
|
|
548 | } |
664 | } else if ( !strcasecmp( buf, "armor_weight_linear" ) ) { |
549 | else if (!strcasecmp (buf, "armor_weight_linear")) |
|
|
550 | { |
665 | if (!strcasecmp(cp, "on") || !strcasecmp(cp, "true")) { |
551 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
|
|
552 | { |
666 | settings.armor_weight_linear=TRUE; |
553 | settings.armor_weight_linear = TRUE; |
|
|
554 | } |
667 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
555 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
|
|
556 | { |
668 | settings.armor_weight_linear=FALSE; |
557 | settings.armor_weight_linear = FALSE; |
669 | } else { |
558 | } |
|
|
559 | else |
|
|
560 | { |
670 | LOG(llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
561 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
671 | } |
562 | } |
672 | |
563 | |
|
|
564 | } |
673 | } else if ( !strcasecmp( buf, "armor_speed_improvement" ) ) { |
565 | else if (!strcasecmp (buf, "armor_speed_improvement")) |
|
|
566 | { |
674 | int wr = atoi( cp ); |
567 | int wr = atoi (cp); |
|
|
568 | |
675 | if ( wr < 0 ) |
569 | if (wr < 0) |
676 | LOG( llevError, "load_settings: armor_speed_improvement is %d\n", wr ); |
570 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
677 | else |
571 | else |
678 | settings.armor_speed_improvement = wr; |
572 | settings.armor_speed_improvement = wr; |
|
|
573 | } |
679 | } else if ( !strcasecmp( buf, "armor_speed_linear" ) ) { |
574 | 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 | } |
575 | { |
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")) { |
576 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
699 | settings.create_home_portals = TRUE; |
577 | { |
|
|
578 | settings.armor_speed_linear = TRUE; |
|
|
579 | } |
700 | } else if (!strcasecmp(cp, "off") || !strcasecmp(cp, "false")) { |
580 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
701 | settings.create_home_portals = FALSE; |
581 | { |
|
|
582 | settings.armor_speed_linear = FALSE; |
|
|
583 | } |
702 | } else { |
584 | else |
|
|
585 | { |
703 | LOG(llevError, "load_settings: Unknown value for create_home_portals: %s\n", cp); |
586 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
704 | } |
587 | } |
705 | |
588 | |
|
|
589 | } |
706 | } else { |
590 | else |
707 | LOG(llevError,"Unknown value in settings file: %s\n", buf); |
591 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
708 | } |
|
|
709 | } |
592 | } |
|
|
593 | |
710 | close_and_delete(fp, comp); |
594 | close_and_delete (fp, comp); |
711 | } |
595 | } |
712 | |
|
|
713 | |
596 | |
714 | /* |
597 | /* |
715 | * init() is called only once, when starting the program. |
598 | * init() is called only once, when starting the program. |
716 | */ |
599 | */ |
717 | |
600 | void |
718 | void init(int argc, char **argv) { |
601 | init (int argc, char **argv) |
719 | |
602 | { |
720 | init_done=0; /* Must be done before init_signal() */ |
603 | init_done = 0; /* Must be done before init_signal() */ |
721 | logfile=stderr; |
|
|
722 | parse_args(argc, argv, 1); /* First arg pass - right now it does |
|
|
723 | * nothing, but in future specifying the |
|
|
724 | * LibDir in this pass would be reasonable*/ |
|
|
725 | |
604 | |
726 | init_library(); /* Must be called early */ |
605 | init_environ (); |
727 | load_settings(); /* Load the settings file */ |
606 | cfperl_init (); |
728 | init_weather(); |
|
|
729 | load_materials(); |
|
|
730 | parse_args(argc, argv, 2); |
|
|
731 | fprintf(logfile,"Welcome to CrossFire, v%s\n",VERSION); |
|
|
732 | fprintf(logfile,"Copyright (C) 1994 Mark Wedel.\n"); |
|
|
733 | fprintf(logfile,"Copyright (C) 1992 Frank Tore Johansen.\n"); |
|
|
734 | |
|
|
735 | if (strcmp(settings.dm_mail, "") != 0) { |
|
|
736 | fprintf(logfile,"Maintained locally by: %s\n", settings.dm_mail); |
|
|
737 | fprintf(logfile,"Questions and bugs should be mailed to above address.\n"); |
|
|
738 | } |
|
|
739 | SRANDOM(time(NULL)); |
|
|
740 | |
|
|
741 | init_startup(); /* Write (C), check shutdown/forbid files */ |
|
|
742 | init_signals(); /* Sets up signal interceptions */ |
|
|
743 | init_commands(); /* Sort command tables */ |
|
|
744 | read_map_log(); /* Load up the old temp map files */ |
|
|
745 | init_skills(); |
|
|
746 | |
|
|
747 | parse_args(argc, argv, 3); |
|
|
748 | |
|
|
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(); |
|
|
755 | init_ericserver(); |
|
|
756 | metaserver_init(); |
|
|
757 | init_done=1; |
607 | init_done = 1; |
758 | } |
608 | } |
759 | |
609 | |
760 | void usage(void) { |
610 | void |
761 | (void) fprintf(logfile, |
611 | usage (void) |
762 | "Usage: crossfire [-h] [-<flags>]...\n"); |
612 | { |
|
|
613 | fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
763 | } |
614 | } |
764 | |
615 | |
765 | void help(void) { |
616 | void |
|
|
617 | help (void) |
|
|
618 | { |
|
|
619 | |
766 | /* The information in usage is redundant with what is given below, so why call it? */ |
620 | /* The information in usage is redundant with what is given below, so why call it? */ |
|
|
621 | |
767 | /* usage();*/ |
622 | /* usage();*/ |
768 | printf("Flags:\n"); |
623 | printf ("Flags:\n"); |
769 | printf(" -csport <port> Specifies the port to use for the new client/server code.\n"); |
624 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
770 | printf(" -d Turns on some debugging.\n"); |
625 | printf (" -d Turns on some debugging.\n"); |
771 | printf(" +d Turns off debugging (useful if server compiled with debugging\n"); |
626 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
772 | printf(" as default).\n"); |
627 | printf (" as default).\n"); |
773 | printf(" -detach The server will go in the background, closing all\n"); |
628 | printf (" -detach The server will go in the background, closing all\n"); |
774 | printf(" connections to the tty.\n"); |
629 | printf (" connections to the tty.\n"); |
775 | printf(" -h Display this information.\n"); |
630 | printf (" -h Display this information.\n"); |
776 | printf(" -log <file> Specifies which file to send output to.\n"); |
631 | printf (" -log <file> Specifies which file to send output to.\n"); |
777 | printf(" Only has meaning if -detach is specified.\n"); |
632 | printf (" Only has meaning if -detach is specified.\n"); |
778 | printf(" -mon Turns on monster debugging.\n"); |
633 | printf (" -mon Turns on monster debugging.\n"); |
779 | printf(" -o Prints out info on what was defined at compile time.\n"); |
634 | printf (" -o Prints out info on what was defined at compile time.\n"); |
780 | printf(" -s Display the high-score list.\n"); |
635 | printf (" -s Display the high-score list.\n"); |
781 | printf(" -score <name or class> Displays all high scores with matching name/class.\n"); |
636 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
782 | printf(" -v Print version and contributors.\n"); |
637 | printf (" -v Print version and contributors.\n"); |
783 | printf(" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
638 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
784 | printf(" -local Read/write local data (hiscore, unique items, etc.)\n"); |
639 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
785 | printf(" -maps Sets the directory for maps.\n"); |
640 | printf (" -maps Sets the directory for maps.\n"); |
786 | printf(" -arch Sets the archetype file to use.\n"); |
641 | printf (" -arch Sets the archetype file to use.\n"); |
787 | printf(" -regions Sets the regions file to use.\n"); |
642 | printf (" -regions Sets the regions file to use.\n"); |
788 | printf(" -playerdir Sets the directory for the player files.\n"); |
643 | printf (" -playerdir Sets the directory for the player files.\n"); |
789 | printf(" -templatedir Sets the directory for template generate maps.\n"); |
644 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
790 | printf(" -treasures Sets the treasures file to use.\n"); |
645 | printf (" -treasures Sets the treasures file to use.\n"); |
791 | printf(" -uniquedir Sets the unique items/maps directory.\n"); |
646 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
792 | printf(" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
647 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
793 | printf(" -m Lists out suggested experience for all monsters.\n"); |
648 | printf (" -m Lists out suggested experience for all monsters.\n"); |
794 | printf(" -m2 Dumps out abilities.\n"); |
649 | printf (" -m2 Dumps out abilities.\n"); |
795 | printf(" -m3 Dumps out artifact information.\n"); |
650 | printf (" -m3 Dumps out artifact information.\n"); |
796 | printf(" -m4 Dumps out spell information.\n"); |
651 | printf (" -m4 Dumps out spell information.\n"); |
797 | printf(" -m5 Dumps out skill information.\n"); |
652 | printf (" -m5 Dumps out skill information.\n"); |
798 | printf(" -m6 Dumps out race information.\n"); |
653 | printf (" -m6 Dumps out race information.\n"); |
799 | printf(" -m7 Dumps out alchemy information.\n"); |
654 | printf (" -m7 Dumps out alchemy information.\n"); |
800 | printf(" -m8 Dumps out gods information.\n"); |
655 | printf (" -m8 Dumps out gods information.\n"); |
801 | printf(" -m9 Dumps out more alchemy information (formula checking).\n"); |
656 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
802 | printf(" -mt <name> Dumps out list of treasures for a monster.\n"); |
657 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
803 | exit(0); |
|
|
804 | } |
|
|
805 | |
|
|
806 | void init_beforeplay(void) { |
|
|
807 | init_archetypes(); /* If not called before, reads all archetypes from file */ |
|
|
808 | init_artifacts(); /* If not called before, reads all artifacts from file */ |
|
|
809 | init_spells(); /* If not called before, links archtypes used by spells */ |
|
|
810 | init_regions(); /* If not called before, reads all regions from file */ |
|
|
811 | init_archetype_pointers(); /* Setup global pointers to archetypes */ |
|
|
812 | init_races(); /* overwrite race designations using entries in lib/races file */ |
|
|
813 | init_gods(); /* init linked list of gods from archs*/ |
|
|
814 | init_readable(); /* inits useful arrays for readable texts */ |
|
|
815 | init_formulae(); /* If not called before, reads formulae from file */ |
|
|
816 | |
|
|
817 | switch(settings.dumpvalues) { |
|
|
818 | case 1: |
|
|
819 | print_monsters(); |
|
|
820 | exit(0); |
|
|
821 | case 2: |
|
|
822 | dump_abilities(); |
|
|
823 | exit(0); |
|
|
824 | case 3: |
|
|
825 | dump_artifacts(); |
|
|
826 | exit(0); |
|
|
827 | case 4: |
|
|
828 | dump_spells(); |
|
|
829 | exit(0); |
|
|
830 | case 5: |
|
|
831 | exit(0); |
|
|
832 | case 6: |
|
|
833 | dump_races(); |
|
|
834 | exit(0); |
|
|
835 | case 7: |
|
|
836 | dump_alchemy(); |
|
|
837 | exit(0); |
|
|
838 | case 8: |
|
|
839 | dump_gods(); |
|
|
840 | exit(0); |
|
|
841 | case 9: |
|
|
842 | dump_alchemy_costs(); |
|
|
843 | exit(0); |
|
|
844 | case 10: |
|
|
845 | dump_monster_treasure(settings.dumparg); |
|
|
846 | exit(0); |
|
|
847 | } |
|
|
848 | } |
|
|
849 | |
|
|
850 | void init_startup(void) { |
|
|
851 | char buf[MAX_BUF]; |
|
|
852 | FILE *fp; |
|
|
853 | int comp; |
|
|
854 | |
|
|
855 | #ifdef SHUTDOWN_FILE |
|
|
856 | sprintf(buf,"%s/%s",settings.confdir,SHUTDOWN_FILE); |
|
|
857 | if ((fp = open_and_uncompress(buf, 0, &comp)) != NULL) { |
|
|
858 | while (fgets(buf, MAX_BUF-1, fp) != NULL) |
|
|
859 | printf("%s", buf); |
|
|
860 | close_and_delete(fp, comp); |
|
|
861 | exit(1); |
|
|
862 | } |
|
|
863 | #endif |
|
|
864 | |
|
|
865 | if (forbid_play()) { /* Maybe showing highscore should be allowed? */ |
|
|
866 | LOG(llevError, "CrossFire: Playing not allowed.\n"); |
|
|
867 | exit(-1); |
|
|
868 | } |
|
|
869 | } |
|
|
870 | |
|
|
871 | /* |
|
|
872 | * compile_info(): activated with the -o flag. |
|
|
873 | * It writes out information on how Imakefile and config.h was configured |
|
|
874 | * at compile time. |
|
|
875 | */ |
|
|
876 | |
|
|
877 | void compile_info(void) { |
|
|
878 | int i=0; |
|
|
879 | printf("Non-standard include files:\n"); |
|
|
880 | #if !defined (__STRICT_ANSI__) || defined (__sun__) |
|
|
881 | #if !defined (Mips) |
|
|
882 | printf("<stdlib.h>\n"); |
|
|
883 | i=1; |
|
|
884 | #endif |
|
|
885 | #if !defined (MACH) && !defined (sony) |
|
|
886 | printf("<malloc.h>\n"); |
|
|
887 | i=1; |
|
|
888 | #endif |
|
|
889 | #endif |
|
|
890 | #ifndef __STRICT_ANSI__ |
|
|
891 | #ifndef MACH |
|
|
892 | printf("<memory.h\n"); |
|
|
893 | i=1; |
|
|
894 | #endif |
|
|
895 | #endif |
|
|
896 | #ifndef sgi |
|
|
897 | printf("<sys/timeb.h>\n"); |
|
|
898 | i=1; |
|
|
899 | #endif |
|
|
900 | if(!i) |
|
|
901 | printf("(none)\n"); |
|
|
902 | printf("Datadir:\t\t%s\n",settings.datadir); |
|
|
903 | printf("Localdir:\t\t%s\n",settings.localdir); |
|
|
904 | #ifdef PERM_FILE |
|
|
905 | printf("Perm file:\t<ETC>/%s\n",PERM_FILE); |
|
|
906 | #endif |
|
|
907 | #ifdef SHUTDOWN_FILE |
|
|
908 | printf("Shutdown file:\t<ETC>/%s\n",SHUTDOWN_FILE); |
|
|
909 | #endif |
|
|
910 | printf("Save player:\t<true>\n"); |
|
|
911 | printf("Save mode:\t%4.4o\n",SAVE_MODE); |
|
|
912 | printf("Playerdir:\t<VAR>/%s\n",settings.playerdir); |
|
|
913 | printf("Itemsdir:\t<VAR>/%s\n", settings.uniquedir); |
|
|
914 | 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 |
|
|
918 | printf("Use_calloc:\t<true>\n"); |
|
|
919 | #else |
|
|
920 | printf("Use_calloc:\t<false>\n"); |
|
|
921 | #endif |
|
|
922 | |
|
|
923 | #ifdef X_EDITOR |
|
|
924 | printf("Editor:\t\t%s\n",X_EDITOR); |
|
|
925 | #endif |
|
|
926 | |
|
|
927 | printf("Max_time:\t%d\n",MAX_TIME); |
|
|
928 | |
|
|
929 | #ifdef WIN32 /* ***win32 compile_info(): remove execl... */ |
|
|
930 | printf("Logfilename:\t%s\n",settings.logfilename); |
|
|
931 | exit(0); |
658 | exit (0); |
932 | #else |
659 | } |
933 | execl("/bin/uname", "uname", "-a", NULL); |
660 | |
934 | LOG(llevError, "Oops, shouldn't have gotten here: execl(/bin/uname) failed: %s\n", strerror_local(errno)); |
661 | void |
935 | exit(-1); |
662 | init_beforeplay (void) |
936 | #endif |
663 | { |
|
|
664 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
|
|
665 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
666 | init_gods (); /* init linked list of gods from archs */ |
|
|
667 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
668 | init_formulae (); /* If not called before, reads formulae from file */ |
937 | } |
669 | } |
938 | |
670 | |
939 | /* Signal handlers: */ |
671 | /* Signal handlers: */ |
940 | |
672 | |
|
|
673 | static void |
|
|
674 | rec_sigabrt (int i) |
|
|
675 | { |
|
|
676 | signal (SIGABRT, SIG_DFL); |
|
|
677 | |
|
|
678 | LOG (llevError, "SIGABRT received.\n"); |
|
|
679 | cleanup ("SIGABRT received", 1); |
|
|
680 | } |
|
|
681 | |
|
|
682 | static void |
941 | void rec_sigsegv(int i) { |
683 | rec_sigsegv (int i) |
|
|
684 | { |
|
|
685 | signal (SIGSEGV, SIG_DFL); |
|
|
686 | |
942 | LOG(llevError,"\nSIGSEGV received.\n"); |
687 | LOG (llevError, "SIGSEGV received.\n"); |
943 | fatal_signal(1, 1); |
688 | cleanup ("SIGSEGV received", 1); |
944 | } |
689 | } |
945 | |
690 | |
946 | void rec_sigint(int i) { |
691 | static 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) { |
692 | rec_sigquit (int i) |
|
|
693 | { |
|
|
694 | signal (SIGQUIT, SIG_IGN); |
|
|
695 | |
961 | LOG(llevInfo,"\nSIGQUIT received\n"); |
696 | LOG (llevInfo, "SIGQUIT received\n"); |
962 | fatal_signal(1, 1); |
697 | cleanup ("SIGQUIT received", 1); |
963 | } |
698 | } |
964 | |
699 | |
|
|
700 | static void |
965 | void rec_sigbus(int i) { |
701 | rec_sigbus (int i) |
966 | #ifdef SIGBUS |
702 | { |
|
|
703 | signal (SIGBUS, SIG_DFL); |
|
|
704 | |
967 | LOG(llevError,"\nSIGBUS received\n"); |
705 | LOG (llevError, "SIGBUS received\n"); |
968 | fatal_signal(1, 1); |
706 | cleanup ("SIGBUS received", 1); |
969 | #endif |
|
|
970 | } |
707 | } |
971 | |
708 | |
972 | void rec_sigterm(int i) { |
709 | void |
973 | LOG(llevInfo,"\nSIGTERM received\n"); |
710 | reset_signals () |
974 | fatal_signal(0, 1); |
711 | { |
|
|
712 | signal (SIGABRT, SIG_DFL); |
|
|
713 | signal (SIGQUIT, SIG_DFL); |
|
|
714 | signal (SIGSEGV, SIG_DFL); |
|
|
715 | signal (SIGBUS , SIG_DFL); |
|
|
716 | signal (SIGINT , SIG_DFL); |
|
|
717 | signal (SIGTERM, SIG_DFL); |
975 | } |
718 | } |
976 | |
719 | |
977 | void fatal_signal(int make_core, int close_sockets) { |
720 | void |
978 | if(init_done) { |
|
|
979 | emergency_save(0); |
|
|
980 | clean_tmp_files(); |
|
|
981 | } |
|
|
982 | if(make_core) |
|
|
983 | abort(); |
|
|
984 | exit(0); |
|
|
985 | } |
|
|
986 | |
|
|
987 | void init_signals(void) { |
721 | init_signals (void) |
988 | #ifndef WIN32 /* init_signals() remove signals */ |
722 | { |
989 | signal(SIGHUP,rec_sighup); |
723 | // large stack, but it's important data we want to save, and it is not usually |
990 | signal(SIGINT,rec_sigint); |
724 | // being physically allocated anyways |
991 | signal(SIGQUIT,rec_sigquit); |
725 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
992 | signal(SIGSEGV,rec_sigsegv); |
726 | |
993 | signal(SIGPIPE,SIG_IGN); |
727 | stack_t ss; |
994 | #ifdef SIGBUS |
728 | ss.ss_sp = malloc (stacksize); |
995 | signal(SIGBUS,rec_sigbus); |
729 | ss.ss_flags = 0; |
996 | #endif |
730 | ss.ss_size = stacksize; |
997 | signal(SIGTERM,rec_sigterm); |
731 | sigaltstack (&ss, 0); |
998 | #endif |
732 | |
|
|
733 | struct sigaction sa; |
|
|
734 | |
|
|
735 | sigfillset (&sa.sa_mask); |
|
|
736 | sa.sa_flags = SA_RESTART; |
|
|
737 | |
|
|
738 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
|
|
739 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
|
|
740 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
741 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
|
|
742 | |
|
|
743 | sa.sa_flags |= SA_ONSTACK; |
|
|
744 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
999 | } |
745 | } |
1000 | |
746 | |
1001 | /* init_races() - reads the races file in the lib/ directory, then |
747 | /* init_races() - reads the races file in the lib/ directory, then |
1002 | * overwrites old 'race' entries. This routine allow us to quickly |
748 | * overwrites old 'race' entries. This routine allow us to quickly |
1003 | * re-configure the 'alignment' of monsters, objects. Useful for |
749 | * re-configure the 'alignment' of monsters, objects. Useful for |
1004 | * putting together lists of creatures, etc that belong to gods. |
750 | * putting together lists of creatures, etc that belong to gods. |
1005 | */ |
751 | */ |
1006 | |
752 | void |
1007 | void init_races (void) { |
753 | init_races (void) |
|
|
754 | { |
1008 | FILE *file; |
755 | FILE *file; |
1009 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
756 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
1010 | archetype *mon=NULL; |
757 | archetype *mon = NULL; |
1011 | static int init_done=0; |
758 | static int init_done = 0; |
1012 | |
759 | |
1013 | if (init_done) return; |
760 | 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; |
761 | return; |
|
|
762 | init_done = 1; |
|
|
763 | first_race = 0; |
|
|
764 | |
|
|
765 | sprintf (fname, "%s/races", settings.datadir); |
|
|
766 | LOG (llevDebug, "Reading races from %s...\n", fname); |
|
|
767 | if (!(file = fopen (fname, "r"))) |
|
|
768 | { |
|
|
769 | LOG (llevError, "Cannot open races file %s: %s\n", fname, strerror (errno)); |
|
|
770 | return; |
1022 | } |
771 | } |
1023 | |
772 | |
1024 | while(fgets(buf,MAX_BUF,file)!=NULL) { |
773 | while (fgets (buf, MAX_BUF, file) != NULL) |
|
|
774 | { |
1025 | int set_race=1,set_list=1; |
775 | int set_race = 1, set_list = 1; |
1026 | if(*buf=='#') continue; |
776 | |
|
|
777 | if (*buf == '#') |
|
|
778 | continue; |
|
|
779 | |
1027 | if((cp=strchr(buf,'\n'))!=NULL) |
780 | if ((cp = strchr (buf, '\n')) != NULL) |
1028 | *cp='\0'; |
781 | *cp = '\0'; |
|
|
782 | |
1029 | cp=buf; |
783 | cp = buf; |
1030 | while(*cp==' '||*cp=='!'||*cp=='@') { |
784 | while (*cp == ' ' || *cp == '!' || *cp == '@') |
|
|
785 | { |
1031 | if(*cp=='!') set_race=0; |
786 | if (*cp == '!') set_race = 0; |
1032 | if(*cp=='@') set_list=0; |
787 | if (*cp == '@') set_list = 0; |
|
|
788 | |
1033 | cp++; |
789 | cp++; |
1034 | } |
790 | } |
1035 | if(sscanf(cp,"RACE %s",variable)) { /* set new race value */ |
791 | |
|
|
792 | if (sscanf (cp, "RACE %s", variable)) |
|
|
793 | /* set new race value */ |
1036 | strcpy(race,variable); |
794 | strcpy (race, variable); |
1037 | } else { |
795 | else |
1038 | char *cp1; |
796 | { |
|
|
797 | char *cp1; |
|
|
798 | |
1039 | /* Take out beginning spaces */ |
799 | /* Take out beginning spaces */ |
1040 | for (cp1 = cp; *cp1==' '; cp1++); |
800 | for (cp1 = cp; *cp1 == ' '; cp1++) |
|
|
801 | ; |
1041 | /* Remove newline and trailing spaces */ |
802 | /* Remove newline and trailing spaces */ |
1042 | for (cp1 = cp + strlen(cp) -1; *cp1 == '\n' || *cp1 == ' '; cp1 --) { |
803 | for (cp1 = cp + strlen (cp) - 1; *cp1 == '\n' || *cp1 == ' '; cp1--) |
1043 | *cp1='\0'; |
804 | { |
1044 | if (cp==cp1) break; |
805 | *cp1 = '\0'; |
1045 | } |
806 | if (cp == cp1) |
1046 | |
807 | break; |
1047 | if (cp[strlen(cp)-1]=='\n') cp[strlen(cp)-1]='\0'; |
808 | } |
|
|
809 | |
|
|
810 | if (cp[strlen (cp) - 1] == '\n') |
|
|
811 | cp[strlen (cp) - 1] = '\0'; |
|
|
812 | |
1048 | /* set creature race to race value */ |
813 | /* set creature race to race value */ |
1049 | if((mon=find_archetype(cp))==NULL) |
814 | if ((mon = archetype::find (cp)) == NULL) |
1050 | LOG(llevError,"\nCreature %s in race file lacks archetype",cp); |
815 | LOG (llevError, "Creature %s in race file lacks archetype\n", cp); |
1051 | else { |
816 | else |
|
|
817 | { |
1052 | if(set_race&&(!mon->clone.race||strcmp(mon->clone.race,race))) { |
818 | if (set_race && (!mon->race || strcmp (&mon->race, race))) |
|
|
819 | { |
1053 | if(mon->clone.race) { |
820 | if (mon->race) |
1054 | LOG(llevDebug,"\n Resetting race to %s from %s for archetype %s", |
821 | LOG (llevDebug, "Resetting race to %s from %s for archetype %s\n", race, &mon->race, &mon->archname); |
1055 | race,mon->clone.race,mon->name); |
822 | |
1056 | free_string(mon->clone.race); |
823 | mon->race = race; |
1057 | } |
824 | } |
1058 | mon->clone.race=add_string(race); |
825 | |
1059 | } |
|
|
1060 | /* if the arch is a monster, add it to the race list */ |
826 | /* if the arch is a monster, add it to the race list */ |
1061 | if(set_list&&QUERY_FLAG(&mon->clone,FLAG_MONSTER)) |
827 | if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) |
1062 | add_to_racelist(race, &mon->clone); |
828 | add_to_racelist (race, mon); |
1063 | } |
829 | } |
1064 | } |
830 | } |
1065 | } |
831 | } |
|
|
832 | |
1066 | fclose(file); |
833 | fclose (file); |
1067 | LOG(llevDebug,"done.\n"); |
834 | LOG (llevDebug, "done.\n"); |
1068 | } |
835 | } |
1069 | |
836 | |
|
|
837 | void |
1070 | void dump_races(void) |
838 | dump_races (void) |
1071 | { |
839 | { |
1072 | racelink *list; |
840 | racelink *list; |
1073 | objectlink *tmp; |
841 | objectlink *tmp; |
|
|
842 | |
1074 | for(list=first_race;list;list=list->next) { |
843 | for (list = first_race; list; list = list->next) |
|
|
844 | { |
1075 | fprintf(stderr,"\nRACE %s:\t",list->name); |
845 | fprintf (stderr, "\nRACE %s:\t", &list->name); |
1076 | for(tmp=list->member;tmp;tmp=tmp->next) |
846 | for (tmp = list->member; tmp; tmp = tmp->next) |
1077 | fprintf(stderr,"%s(%d), ",tmp->ob->arch->name,tmp->ob->level); |
847 | fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level); |
1078 | } |
848 | } |
|
|
849 | |
1079 | fprintf(stderr,"\n"); |
850 | fprintf (stderr, "\n"); |
1080 | } |
851 | } |
1081 | |
852 | |
|
|
853 | void |
1082 | void add_to_racelist (const char *race_name, object *op) { |
854 | add_to_racelist (const char *race_name, object *op) |
|
|
855 | { |
1083 | racelink *race; |
856 | racelink *race; |
1084 | |
857 | |
1085 | if(!op||!race_name) return; |
858 | if (!op || !race_name) |
|
|
859 | return; |
|
|
860 | |
1086 | race=find_racelink(race_name); |
861 | race = find_racelink (race_name); |
1087 | |
862 | |
1088 | if(!race) { /* add in a new race list */ |
863 | if (!race) |
|
|
864 | { /* add in a new race list */ |
1089 | race = get_racelist(); |
865 | race = get_racelist (); |
1090 | race->next = first_race; |
866 | race->next = first_race; |
1091 | first_race = race; |
867 | first_race = race; |
1092 | race->name=add_string(race_name); |
868 | race->name = race_name; |
1093 | } |
869 | } |
1094 | |
870 | |
1095 | if(race->member->ob) { |
871 | if (race->member->ob) |
|
|
872 | { |
1096 | objectlink *tmp = get_objectlink(); |
873 | objectlink *tmp = get_objectlink (); |
|
|
874 | |
1097 | tmp->next=race->member; |
875 | tmp->next = race->member; |
1098 | race->member = tmp; |
876 | race->member = tmp; |
1099 | } |
877 | } |
|
|
878 | |
1100 | race->nrof++; |
879 | race->nrof++; |
1101 | race->member->ob = op; |
880 | race->member->ob = op; |
1102 | } |
881 | } |
1103 | |
882 | |
1104 | racelink * get_racelist ( ) { |
883 | racelink * |
1105 | racelink *list; |
884 | get_racelist () |
1106 | |
885 | { |
1107 | list = (racelink *) malloc(sizeof(racelink )); |
886 | racelink *list = new racelink; |
|
|
887 | |
1108 | list->name=NULL; |
888 | list->name = 0; |
1109 | list->nrof=0; |
889 | list->nrof = 0; |
|
|
890 | list->next = 0; |
1110 | list->member=get_objectlink(); |
891 | list->member = get_objectlink (); |
1111 | list->next=NULL; |
|
|
1112 | |
892 | |
1113 | return list; |
893 | return list; |
1114 | } |
894 | } |
1115 | |
895 | |
|
|
896 | racelink * |
1116 | racelink * find_racelink( const char *name ) { |
897 | find_racelink (const char *name) |
1117 | racelink *test=NULL; |
898 | { |
1118 | |
899 | if (name) |
1119 | if(name&&first_race) |
900 | for (racelink *link = first_race; link; link = link->next) |
1120 | for(test=first_race;test&&test!=test->next;test=test->next) |
901 | if (!link->name || !strcmp (name, link->name)) |
1121 | if(!test->name||!strcmp(name,test->name)) break; |
902 | return link; |
1122 | |
903 | |
1123 | return test; |
904 | return 0; |
1124 | } |
905 | } |