1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * 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 | * 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 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * 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 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | #include <material.h> |
27 | #include <material.h> |
27 | #include <loader.h> |
|
|
28 | #include <sproto.h> |
28 | #include <sproto.h> |
29 | |
29 | |
30 | /* This loads the settings file. There could be debate whether this should |
30 | /* This loads the settings file. There could be debate whether this should |
31 | * be here or in the common directory - but since only the server needs this |
31 | * be here or in the common directory - but since only the server needs this |
32 | * information, having it here probably makes more sense. |
32 | * information, having it here probably makes more sense. |
33 | */ |
33 | */ |
34 | void |
34 | void |
35 | load_settings (void) |
35 | load_settings () |
36 | { |
36 | { |
37 | char buf[MAX_BUF], *cp; |
37 | object_thawer thawer (settings.confdir, "settings"); |
38 | int has_val, comp; |
|
|
39 | FILE *fp; |
|
|
40 | |
38 | |
41 | sprintf (buf, "%s/settings", settings.confdir); |
39 | if (!thawer) |
42 | |
|
|
43 | /* We don't require a settings file at current time, but down the road, |
|
|
44 | * there will probably be so many values that not having a settings file |
|
|
45 | * will not be a good thing. |
|
|
46 | */ |
|
|
47 | if (!(fp = open_and_uncompress (buf, 0, &comp))) |
|
|
48 | { |
40 | { |
49 | LOG (llevError, "Error: No settings file found\n"); |
41 | LOG (llevError, "Error: No settings file found\n"); |
50 | exit (1); |
42 | exit (1); |
51 | } |
43 | } |
52 | |
44 | |
53 | while (fgets (buf, MAX_BUF - 1, fp) != NULL) |
45 | while (thawer.kw) |
54 | { |
46 | { |
55 | if (buf[0] == '#') |
47 | const char *buf = thawer.kw_str; |
56 | continue; |
48 | const char *cp = thawer.value_nn; |
57 | /* eliminate newline */ |
|
|
58 | if ((cp = strrchr (buf, '\n')) != NULL) |
|
|
59 | *cp = '\0'; |
|
|
60 | |
49 | |
61 | /* Skip over empty lines */ |
|
|
62 | if (buf[0] == 0) |
|
|
63 | continue; |
|
|
64 | |
|
|
65 | /* Skip all the spaces and set them to nulls. If not space, |
|
|
66 | * set cp to "" to make strcpy's and the like easier down below. |
|
|
67 | */ |
|
|
68 | if ((cp = strchr (buf, ' ')) != NULL) |
|
|
69 | { |
|
|
70 | while (*cp == ' ') |
|
|
71 | *cp++ = 0; |
|
|
72 | has_val = 1; |
|
|
73 | } |
|
|
74 | else |
|
|
75 | { |
|
|
76 | cp = (char *)""; |
|
|
77 | has_val = 0; |
|
|
78 | } |
|
|
79 | |
|
|
80 | if (!strcasecmp (buf, "not_permadeth")) |
50 | if (!strcmp (buf, "not_permadeth")) |
81 | { |
51 | { |
82 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
52 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
83 | { |
53 | { |
84 | settings.not_permadeth = TRUE; |
54 | settings.not_permadeth = TRUE; |
85 | } |
55 | } |
86 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
56 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
87 | { |
57 | { |
88 | settings.not_permadeth = FALSE; |
58 | settings.not_permadeth = FALSE; |
89 | } |
59 | } |
90 | else |
60 | else |
91 | { |
61 | { |
92 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
62 | LOG (llevError, "load_settings: Unknown value for not_permadeth" ": %s\n", cp); |
93 | } |
63 | } |
94 | } |
64 | } |
95 | else if (!strcasecmp (buf, "resurrection")) |
65 | else if (!strcmp (buf, "resurrection")) |
96 | { |
66 | { |
97 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
67 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
98 | { |
68 | { |
99 | settings.resurrection = TRUE; |
69 | settings.resurrection = TRUE; |
100 | } |
70 | } |
101 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
71 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
102 | { |
72 | { |
103 | settings.resurrection = FALSE; |
73 | settings.resurrection = FALSE; |
104 | } |
74 | } |
105 | else |
75 | else |
106 | { |
76 | { |
107 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
77 | LOG (llevError, "load_settings: Unknown value for resurrection" ": %s\n", cp); |
108 | } |
78 | } |
109 | } |
79 | } |
110 | else if (!strcasecmp (buf, "set_title")) |
80 | else if (!strcmp (buf, "set_title")) |
111 | { |
81 | { |
112 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
82 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
113 | { |
83 | { |
114 | settings.set_title = TRUE; |
84 | settings.set_title = TRUE; |
115 | } |
85 | } |
116 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
86 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
117 | { |
87 | { |
118 | settings.set_title = FALSE; |
88 | settings.set_title = FALSE; |
119 | } |
89 | } |
120 | else |
90 | else |
121 | { |
91 | { |
122 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
92 | LOG (llevError, "load_settings: Unknown value for set_title" ": %s\n", cp); |
123 | } |
93 | } |
124 | } |
94 | } |
125 | else if (!strcasecmp (buf, "search_items")) |
95 | else if (!strcmp (buf, "search_items")) |
126 | { |
96 | { |
127 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
97 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
128 | { |
98 | { |
129 | settings.search_items = TRUE; |
99 | settings.search_items = TRUE; |
130 | } |
100 | } |
131 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
101 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
132 | { |
102 | { |
133 | settings.search_items = FALSE; |
103 | settings.search_items = FALSE; |
134 | } |
104 | } |
135 | else |
105 | else |
136 | { |
106 | { |
137 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
107 | LOG (llevError, "load_settings: Unknown value for search_items" ": %s\n", cp); |
138 | } |
108 | } |
139 | } |
109 | } |
140 | else if (!strcasecmp (buf, "spell_encumbrance")) |
110 | else if (!strcmp (buf, "spell_encumbrance")) |
141 | { |
111 | { |
142 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
112 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
143 | { |
113 | { |
144 | settings.spell_encumbrance = TRUE; |
114 | settings.spell_encumbrance = TRUE; |
145 | } |
115 | } |
146 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
116 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
147 | { |
117 | { |
148 | settings.spell_encumbrance = FALSE; |
118 | settings.spell_encumbrance = FALSE; |
149 | } |
119 | } |
150 | else |
120 | else |
151 | { |
121 | { |
152 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
122 | LOG (llevError, "load_settings: Unknown value for " "spell_encumbrance: %s\n", cp); |
153 | } |
123 | } |
154 | } |
124 | } |
155 | else if (!strcasecmp (buf, "spell_failure_effects")) |
125 | else if (!strcmp (buf, "spell_failure_effects")) |
156 | { |
126 | { |
157 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
127 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
158 | { |
128 | { |
159 | settings.spell_failure_effects = TRUE; |
129 | settings.spell_failure_effects = TRUE; |
160 | } |
130 | } |
161 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
131 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
162 | { |
132 | { |
163 | settings.spell_failure_effects = FALSE; |
133 | settings.spell_failure_effects = FALSE; |
164 | } |
134 | } |
165 | else |
135 | else |
166 | { |
136 | { |
167 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
137 | LOG (llevError, "load_settings: Unknown value for " "spell_failure_effects: %s\n", cp); |
168 | } |
138 | } |
169 | } |
139 | } |
170 | else if (!strcasecmp (buf, "spellpoint_level_depend")) |
140 | else if (!strcmp (buf, "spellpoint_level_depend")) |
171 | { |
141 | { |
172 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
142 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
173 | { |
143 | { |
174 | settings.spellpoint_level_depend = TRUE; |
144 | settings.spellpoint_level_depend = TRUE; |
175 | } |
145 | } |
176 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
146 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
177 | { |
147 | { |
178 | settings.spellpoint_level_depend = FALSE; |
148 | settings.spellpoint_level_depend = FALSE; |
179 | } |
149 | } |
180 | else |
150 | else |
181 | { |
151 | { |
182 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
152 | LOG (llevError, "load_settings: Unknown value for " "spellpoint_level_depend: %s\n", cp); |
183 | } |
153 | } |
184 | } |
154 | } |
185 | else if (!strcasecmp (buf, "stat_loss_on_death")) |
155 | else if (!strcmp (buf, "stat_loss_on_death")) |
186 | { |
156 | { |
187 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
157 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
188 | { |
158 | { |
189 | settings.stat_loss_on_death = TRUE; |
159 | settings.stat_loss_on_death = TRUE; |
190 | } |
160 | } |
191 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
161 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
192 | { |
162 | { |
193 | settings.stat_loss_on_death = FALSE; |
163 | settings.stat_loss_on_death = FALSE; |
194 | } |
164 | } |
195 | else |
165 | else |
196 | { |
166 | { |
197 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
167 | LOG (llevError, "load_settings: Unknown value for " "stat_loss_on_death: %s\n", cp); |
198 | } |
168 | } |
199 | } |
169 | } |
200 | else if (!strcasecmp (buf, "use_permanent_experience")) |
170 | else if (!strcmp (buf, "use_permanent_experience")) |
201 | { |
171 | { |
202 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
172 | LOG (llevError, "use_permanent_experience is deprecated, use" "permenent_experience_percentage instead\n"); |
203 | } |
173 | } |
204 | else if (!strcasecmp (buf, "permanent_experience_percentage")) |
174 | else if (!strcmp (buf, "permanent_experience_percentage")) |
205 | { |
175 | { |
206 | int val = atoi (cp); |
176 | int val = atoi (cp); |
207 | |
177 | |
208 | if (val < 0 || val > 100) |
178 | if (val < 0 || val > 100) |
209 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
179 | LOG (llevError, "load_settings: permenent_experience_percentage" "must be between 0 and 100, %d is invalid\n", val); |
210 | else |
180 | else |
211 | settings.permanent_exp_ratio = val; |
181 | settings.permanent_exp_ratio = val; |
212 | } |
182 | } |
213 | else if (!strcasecmp (buf, "death_penalty_percentage")) |
183 | else if (!strcmp (buf, "death_penalty_percentage")) |
214 | { |
184 | { |
215 | int val = atoi (cp); |
185 | int val = atoi (cp); |
216 | |
186 | |
217 | if (val < 0 || val > 100) |
187 | if (val < 0 || val > 100) |
218 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
188 | LOG (llevError, "load_settings: death_penalty_percentage" "must be between 0 and 100, %d is invalid\n", val); |
219 | else |
189 | else |
220 | settings.death_penalty_ratio = val; |
190 | settings.death_penalty_ratio = val; |
221 | } |
191 | } |
222 | else if (!strcasecmp (buf, "death_penalty_levels")) |
192 | else if (!strcmp (buf, "death_penalty_levels")) |
223 | { |
193 | { |
224 | int val = atoi (cp); |
194 | int val = atoi (cp); |
225 | |
195 | |
226 | if (val < 0 || val > 255) |
196 | if (val < 0 || val > 255) |
227 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
197 | LOG (llevError, "load_settings: death_penalty_levels" "can not be negative, %d is invalid\n", val); |
228 | else |
198 | else |
229 | settings.death_penalty_level = val; |
199 | settings.death_penalty_level = val; |
230 | } |
200 | } |
231 | else if (!strcasecmp (buf, "balanced_stat_loss")) |
201 | else if (!strcmp (buf, "balanced_stat_loss")) |
232 | { |
202 | { |
233 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
203 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
234 | { |
204 | { |
235 | settings.balanced_stat_loss = TRUE; |
205 | settings.balanced_stat_loss = TRUE; |
236 | } |
206 | } |
237 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
207 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
238 | { |
208 | { |
239 | settings.balanced_stat_loss = FALSE; |
209 | settings.balanced_stat_loss = FALSE; |
240 | } |
210 | } |
241 | else |
211 | else |
242 | { |
212 | { |
243 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
213 | LOG (llevError, "load_settings: Unknown value for " "balanced_stat_loss: %s\n", cp); |
244 | } |
214 | } |
245 | } |
215 | } |
246 | else if (!strcasecmp (buf, "simple_exp")) |
216 | else if (!strcmp (buf, "simple_exp")) |
247 | { |
217 | { |
248 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
218 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
249 | { |
219 | { |
250 | settings.simple_exp = TRUE; |
220 | settings.simple_exp = TRUE; |
251 | } |
221 | } |
252 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
222 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
253 | { |
223 | { |
254 | settings.simple_exp = FALSE; |
224 | settings.simple_exp = FALSE; |
255 | } |
225 | } |
256 | else |
226 | else |
257 | { |
227 | { |
258 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
228 | LOG (llevError, "load_settings: Unknown value for simple_exp: %s\n", cp); |
259 | } |
229 | } |
260 | } |
230 | } |
261 | else if (!strcasecmp (buf, "item_power_factor")) |
231 | else if (!strcmp (buf, "item_power_factor")) |
262 | { |
232 | { |
263 | float tmp = atof (cp); |
233 | float tmp = atof (cp); |
264 | |
234 | |
265 | if (tmp < 0) |
235 | if (tmp < 0) |
266 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
236 | LOG (llevError, "load_settings: item_power_factor must be a positive number (%f < 0)\n", tmp); |
267 | else |
237 | else |
268 | settings.item_power_factor = tmp; |
238 | settings.item_power_factor = tmp; |
269 | } |
239 | } |
270 | else if (!strcasecmp (buf, "pk_luck_penalty")) |
240 | else if (!strcmp (buf, "pk_luck_penalty")) |
271 | { |
241 | { |
272 | sint16 val = atoi (cp); |
242 | sint16 val = atoi (cp); |
273 | |
243 | |
274 | if (val < -100 || val > 100) |
244 | if (val < -100 || val > 100) |
275 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
245 | LOG (llevError, "load_settings: pk_luck_penalty must be between -100 and 100" ", %d is invalid\n", val); |
276 | else |
246 | else |
277 | settings.pk_luck_penalty = val; |
247 | settings.pk_luck_penalty = val; |
278 | } |
248 | } |
279 | else if (!strcasecmp (buf, "set_friendly_fire")) |
249 | else if (!strcmp (buf, "set_friendly_fire")) |
280 | { |
250 | { |
281 | int val = atoi (cp); |
251 | int val = atoi (cp); |
282 | |
252 | |
283 | if (val < 0 || val > 100) |
253 | if (val < 0 || val > 100) |
284 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
254 | LOG (llevError, "load_settings: set_friendly_fire must be between 0 an 100" ", %d is invalid\n", val); |
285 | else |
255 | else |
286 | settings.set_friendly_fire = val; |
256 | settings.set_friendly_fire = val; |
287 | } |
257 | } |
288 | else if (!strcasecmp (buf, "armor_max_enchant")) |
258 | else if (!strcmp (buf, "armor_max_enchant")) |
289 | { |
259 | { |
290 | int max_e = atoi (cp); |
260 | int max_e = atoi (cp); |
291 | |
261 | |
292 | if (max_e <= 0) |
262 | if (max_e <= 0) |
293 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
263 | LOG (llevError, "load_settings: armor_max_enchant is %d\n", max_e); |
294 | else |
264 | else |
295 | settings.armor_max_enchant = max_e; |
265 | settings.armor_max_enchant = max_e; |
296 | } |
266 | } |
297 | else if (!strcasecmp (buf, "armor_weight_reduction")) |
267 | else if (!strcmp (buf, "armor_weight_reduction")) |
298 | { |
268 | { |
299 | int wr = atoi (cp); |
269 | int wr = atoi (cp); |
300 | |
270 | |
301 | if (wr < 0) |
271 | if (wr < 0) |
302 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
272 | LOG (llevError, "load_settings: armor_weight_reduction is %d\n", wr); |
303 | else |
273 | else |
304 | settings.armor_weight_reduction = wr; |
274 | settings.armor_weight_reduction = wr; |
305 | } |
275 | } |
306 | else if (!strcasecmp (buf, "armor_weight_linear")) |
276 | else if (!strcmp (buf, "armor_weight_linear")) |
307 | { |
277 | { |
308 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
278 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
309 | { |
279 | { |
310 | settings.armor_weight_linear = TRUE; |
280 | settings.armor_weight_linear = TRUE; |
311 | } |
281 | } |
312 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
282 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
313 | { |
283 | { |
314 | settings.armor_weight_linear = FALSE; |
284 | settings.armor_weight_linear = FALSE; |
315 | } |
285 | } |
316 | else |
286 | else |
317 | { |
287 | { |
318 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
288 | LOG (llevError, "load_settings: unknown value for armor_weight_linear: %s\n", cp); |
319 | } |
289 | } |
320 | |
290 | |
321 | } |
291 | } |
322 | else if (!strcasecmp (buf, "armor_speed_improvement")) |
292 | else if (!strcmp (buf, "armor_speed_improvement")) |
323 | { |
293 | { |
324 | int wr = atoi (cp); |
294 | int wr = atoi (cp); |
325 | |
295 | |
326 | if (wr < 0) |
296 | if (wr < 0) |
327 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
297 | LOG (llevError, "load_settings: armor_speed_improvement is %d\n", wr); |
328 | else |
298 | else |
329 | settings.armor_speed_improvement = wr; |
299 | settings.armor_speed_improvement = wr; |
330 | } |
300 | } |
331 | else if (!strcasecmp (buf, "armor_speed_linear")) |
301 | else if (!strcmp (buf, "armor_speed_linear")) |
332 | { |
302 | { |
333 | if (!strcasecmp (cp, "on") || !strcasecmp (cp, "true")) |
303 | if (!strcmp (cp, "on") || !strcmp (cp, "true")) |
334 | { |
304 | { |
335 | settings.armor_speed_linear = TRUE; |
305 | settings.armor_speed_linear = TRUE; |
336 | } |
306 | } |
337 | else if (!strcasecmp (cp, "off") || !strcasecmp (cp, "false")) |
307 | else if (!strcmp (cp, "off") || !strcmp (cp, "false")) |
338 | { |
308 | { |
339 | settings.armor_speed_linear = FALSE; |
309 | settings.armor_speed_linear = FALSE; |
340 | } |
310 | } |
341 | else |
311 | else |
342 | { |
312 | { |
343 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
313 | LOG (llevError, "load_settings: unknown value for armor_speed_linear: %s\n", cp); |
344 | } |
314 | } |
345 | |
315 | |
346 | } |
316 | } |
347 | else |
317 | else |
348 | LOG (llevError, "Unknown value in settings file: %s\n", buf); |
318 | thawer.parse_error ("settings file"); |
|
|
319 | |
|
|
320 | thawer.next (); |
349 | } |
321 | } |
350 | |
|
|
351 | close_and_delete (fp, comp); |
|
|
352 | } |
322 | } |
353 | |
323 | |
354 | /* |
324 | /* |
355 | * init() is called only once, when starting the program. |
325 | * init() is called only once, when starting the program. |
356 | */ |
326 | */ |
… | |
… | |
362 | init_environ (); |
332 | init_environ (); |
363 | cfperl_init (); |
333 | cfperl_init (); |
364 | init_done = 1; |
334 | init_done = 1; |
365 | } |
335 | } |
366 | |
336 | |
367 | void |
|
|
368 | usage (void) |
|
|
369 | { |
|
|
370 | fprintf (stderr, "Usage: deliantra-server [-h] [-<flags>]...\n"); |
|
|
371 | } |
|
|
372 | |
|
|
373 | void |
|
|
374 | help (void) |
|
|
375 | { |
|
|
376 | |
|
|
377 | /* The information in usage is redundant with what is given below, so why call it? */ |
|
|
378 | |
|
|
379 | /* usage();*/ |
|
|
380 | printf ("Flags:\n"); |
|
|
381 | printf (" -csport <port> Specifies the port to use for the new client/server code.\n"); |
|
|
382 | printf (" -d Turns on some debugging.\n"); |
|
|
383 | printf (" +d Turns off debugging (useful if server compiled with debugging\n"); |
|
|
384 | printf (" as default).\n"); |
|
|
385 | printf (" -detach The server will go in the background, closing all\n"); |
|
|
386 | printf (" connections to the tty.\n"); |
|
|
387 | printf (" -h Display this information.\n"); |
|
|
388 | printf (" -log <file> Specifies which file to send output to.\n"); |
|
|
389 | printf (" Only has meaning if -detach is specified.\n"); |
|
|
390 | printf (" -mon Turns on monster debugging.\n"); |
|
|
391 | printf (" -o Prints out info on what was defined at compile time.\n"); |
|
|
392 | printf (" -s Display the high-score list.\n"); |
|
|
393 | printf (" -score <name or class> Displays all high scores with matching name/class.\n"); |
|
|
394 | printf (" -v Print version and contributors.\n"); |
|
|
395 | printf (" -data Sets the lib dir (archetypes, treasures, etc.)\n"); |
|
|
396 | printf (" -local Read/write local data (hiscore, unique items, etc.)\n"); |
|
|
397 | printf (" -maps Sets the directory for maps.\n"); |
|
|
398 | printf (" -arch Sets the archetype file to use.\n"); |
|
|
399 | printf (" -regions Sets the regions file to use.\n"); |
|
|
400 | printf (" -playerdir Sets the directory for the player files.\n"); |
|
|
401 | printf (" -templatedir Sets the directory for template generate maps.\n"); |
|
|
402 | printf (" -treasures Sets the treasures file to use.\n"); |
|
|
403 | printf (" -uniquedir Sets the unique items/maps directory.\n"); |
|
|
404 | printf (" -tmpdir Sets the directory for temporary files (mostly maps.)\n"); |
|
|
405 | printf (" -m Lists out suggested experience for all monsters.\n"); |
|
|
406 | printf (" -m2 Dumps out abilities.\n"); |
|
|
407 | printf (" -m3 Dumps out artifact information.\n"); |
|
|
408 | printf (" -m4 Dumps out spell information.\n"); |
|
|
409 | printf (" -m5 Dumps out skill information.\n"); |
|
|
410 | printf (" -m6 Dumps out race information.\n"); |
|
|
411 | printf (" -m7 Dumps out alchemy information.\n"); |
|
|
412 | printf (" -m8 Dumps out gods information.\n"); |
|
|
413 | printf (" -m9 Dumps out more alchemy information (formula checking).\n"); |
|
|
414 | printf (" -mt <name> Dumps out list of treasures for a monster.\n"); |
|
|
415 | exit (0); |
|
|
416 | } |
|
|
417 | |
|
|
418 | void |
|
|
419 | init_beforeplay (void) |
|
|
420 | { |
|
|
421 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
|
|
422 | init_races (); /* overwrite race designations using entries in lib/races file */ |
|
|
423 | init_gods (); /* init linked list of gods from archs */ |
|
|
424 | init_readable (); /* inits useful arrays for readable texts */ |
|
|
425 | init_formulae (); /* If not called before, reads formulae from file */ |
|
|
426 | } |
|
|
427 | |
|
|
428 | /* Signal handlers: */ |
337 | /* Signal handlers: */ |
429 | |
338 | |
430 | static void |
339 | static void |
431 | rec_sigabrt (int i) |
340 | rec_sigabrt (int i) |
432 | { |
341 | { |
… | |
… | |
435 | LOG (llevError, "SIGABRT received.\n"); |
344 | LOG (llevError, "SIGABRT received.\n"); |
436 | cleanup ("SIGABRT received", 1); |
345 | cleanup ("SIGABRT received", 1); |
437 | } |
346 | } |
438 | |
347 | |
439 | static void |
348 | static void |
|
|
349 | rec_sigquit (int i) |
|
|
350 | { |
|
|
351 | signal (SIGQUIT, SIG_IGN); |
|
|
352 | |
|
|
353 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
354 | cleanup ("SIGQUIT received", 1); |
|
|
355 | } |
|
|
356 | |
|
|
357 | static void |
440 | rec_sigsegv (int i) |
358 | rec_sigsegv (int i) |
441 | { |
359 | { |
442 | signal (SIGSEGV, SIG_DFL); |
360 | signal (SIGSEGV, SIG_DFL); |
443 | |
361 | |
444 | LOG (llevError, "SIGSEGV received.\n"); |
362 | LOG (llevError, "SIGSEGV received.\n"); |
445 | cleanup ("SIGSEGV received", 1); |
363 | cleanup ("SIGSEGV received", 1); |
446 | } |
364 | } |
447 | |
365 | |
448 | static void |
366 | static void |
449 | rec_sigquit (int i) |
|
|
450 | { |
|
|
451 | signal (SIGQUIT, SIG_IGN); |
|
|
452 | |
|
|
453 | LOG (llevInfo, "SIGQUIT received\n"); |
|
|
454 | cleanup ("SIGQUIT received", 1); |
|
|
455 | } |
|
|
456 | |
|
|
457 | static void |
|
|
458 | rec_sigbus (int i) |
367 | rec_sigbus (int i) |
459 | { |
368 | { |
460 | signal (SIGBUS, SIG_DFL); |
369 | signal (SIGBUS, SIG_DFL); |
461 | |
370 | |
462 | LOG (llevError, "SIGBUS received\n"); |
371 | LOG (llevError, "SIGBUS received\n"); |
463 | cleanup ("SIGBUS received", 1); |
372 | cleanup ("SIGBUS received", 1); |
|
|
373 | } |
|
|
374 | |
|
|
375 | static void |
|
|
376 | rec_sigfpe (int i) |
|
|
377 | { |
|
|
378 | signal (SIGFPE, SIG_DFL); |
|
|
379 | |
|
|
380 | LOG (llevError, "SIGFPE received.\n"); |
|
|
381 | cleanup ("SIGFPE received", 1); |
464 | } |
382 | } |
465 | |
383 | |
466 | void |
384 | void |
467 | reset_signals () |
385 | reset_signals () |
468 | { |
386 | { |
469 | signal (SIGABRT, SIG_DFL); |
387 | signal (SIGABRT, SIG_DFL); |
470 | signal (SIGQUIT, SIG_DFL); |
388 | signal (SIGQUIT, SIG_DFL); |
471 | signal (SIGSEGV, SIG_DFL); |
389 | signal (SIGSEGV, SIG_DFL); |
|
|
390 | #ifdef SIGBUS |
472 | signal (SIGBUS , SIG_DFL); |
391 | signal (SIGBUS , SIG_DFL); |
|
|
392 | #endif |
|
|
393 | signal (SIGFPE , SIG_DFL); |
473 | signal (SIGINT , SIG_DFL); |
394 | signal (SIGINT , SIG_DFL); |
474 | signal (SIGTERM, SIG_DFL); |
395 | signal (SIGTERM, SIG_DFL); |
475 | } |
396 | } |
476 | |
397 | |
477 | void |
398 | void |
478 | init_signals (void) |
399 | init_signals () |
479 | { |
400 | { |
480 | // large stack, but it's important data we want to save, and it is not usually |
401 | // large stack, but it's important data we want to save, and it is not usually |
481 | // being physically allocated anyways |
402 | // being physically allocated anyways |
482 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
403 | const size_t stacksize = 8 * 1024 * 1024 + SIGSTKSZ; |
483 | |
404 | |
… | |
… | |
493 | sa.sa_flags = SA_RESTART; |
414 | sa.sa_flags = SA_RESTART; |
494 | |
415 | |
495 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
416 | sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); |
496 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
417 | sa.sa_handler = rec_sigabrt; sigaction (SIGABRT, &sa, 0); |
497 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
418 | sa.sa_handler = rec_sigquit; sigaction (SIGQUIT, &sa, 0); |
|
|
419 | #ifdef SIGBUS |
498 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
420 | sa.sa_handler = rec_sigbus; sigaction (SIGBUS, &sa, 0); |
|
|
421 | #endif |
|
|
422 | sa.sa_handler = rec_sigfpe; sigaction (SIGFPE, &sa, 0); |
499 | |
423 | |
500 | sa.sa_flags |= SA_ONSTACK; |
424 | sa.sa_flags |= SA_ONSTACK; |
501 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
425 | sa.sa_handler = rec_sigsegv; sigaction (SIGSEGV, &sa, 0); |
|
|
426 | } |
|
|
427 | |
|
|
428 | static racelink * |
|
|
429 | get_racelist () |
|
|
430 | { |
|
|
431 | racelink *list = new racelink; |
|
|
432 | |
|
|
433 | list->name = 0; |
|
|
434 | list->nrof = 0; |
|
|
435 | list->next = 0; |
|
|
436 | list->member = get_objectlink (); |
|
|
437 | |
|
|
438 | return list; |
|
|
439 | } |
|
|
440 | |
|
|
441 | racelink * |
|
|
442 | find_racelink (const char *name) |
|
|
443 | { |
|
|
444 | if (name) |
|
|
445 | for (racelink *link = first_race; link; link = link->next) |
|
|
446 | if (!link->name || !strcmp (name, link->name)) |
|
|
447 | return link; |
|
|
448 | |
|
|
449 | return 0; |
|
|
450 | } |
|
|
451 | |
|
|
452 | static void |
|
|
453 | add_to_racelist (const char *race_name, object *op) |
|
|
454 | { |
|
|
455 | racelink *race; |
|
|
456 | |
|
|
457 | if (!op || !race_name) |
|
|
458 | return; |
|
|
459 | |
|
|
460 | race = find_racelink (race_name); |
|
|
461 | |
|
|
462 | if (!race) |
|
|
463 | { /* add in a new race list */ |
|
|
464 | race = get_racelist (); |
|
|
465 | race->next = first_race; |
|
|
466 | first_race = race; |
|
|
467 | race->name = race_name; |
|
|
468 | } |
|
|
469 | |
|
|
470 | if (race->member->ob) |
|
|
471 | { |
|
|
472 | objectlink *tmp = get_objectlink (); |
|
|
473 | |
|
|
474 | tmp->next = race->member; |
|
|
475 | race->member = tmp; |
|
|
476 | } |
|
|
477 | |
|
|
478 | race->nrof++; |
|
|
479 | race->member->ob = op; |
502 | } |
480 | } |
503 | |
481 | |
504 | /* init_races() - reads the races file in the lib/ directory, then |
482 | /* init_races() - reads the races file in the lib/ directory, then |
505 | * overwrites old 'race' entries. This routine allow us to quickly |
483 | * overwrites old 'race' entries. This routine allow us to quickly |
506 | * re-configure the 'alignment' of monsters, objects. Useful for |
484 | * re-configure the 'alignment' of monsters, objects. Useful for |
507 | * putting together lists of creatures, etc that belong to gods. |
485 | * putting together lists of creatures, etc that belong to gods. |
508 | */ |
486 | */ |
509 | void |
487 | static void |
510 | init_races (void) |
488 | init_races () |
511 | { |
489 | { |
512 | FILE *file; |
490 | FILE *file; |
513 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
491 | char race[MAX_BUF], fname[MAX_BUF], buf[MAX_BUF], *cp, variable[MAX_BUF]; |
514 | archetype *mon = NULL; |
492 | archetype *mon = NULL; |
515 | static int init_done = 0; |
493 | static int init_done = 0; |
… | |
… | |
579 | |
557 | |
580 | mon->race = race; |
558 | mon->race = race; |
581 | } |
559 | } |
582 | |
560 | |
583 | /* if the arch is a monster, add it to the race list */ |
561 | /* if the arch is a monster, add it to the race list */ |
584 | if (set_list && QUERY_FLAG (mon, FLAG_MONSTER)) |
562 | if (set_list && mon->flag [FLAG_MONSTER]) |
585 | add_to_racelist (race, mon); |
563 | add_to_racelist (race, mon); |
586 | } |
564 | } |
587 | } |
565 | } |
588 | } |
566 | } |
589 | |
567 | |
590 | fclose (file); |
568 | fclose (file); |
591 | LOG (llevDebug, "done.\n"); |
569 | LOG (llevDebug, "done.\n"); |
592 | } |
570 | } |
593 | |
571 | |
594 | void |
572 | void |
595 | dump_races (void) |
573 | init_beforeplay () |
596 | { |
574 | { |
597 | racelink *list; |
575 | init_artifacts (); /* If not called before, reads all artifacts from file */ |
598 | objectlink *tmp; |
576 | init_races (); /* overwrite race designations using entries in lib/races file */ |
599 | |
577 | init_gods (); /* init linked list of gods from archs */ |
600 | for (list = first_race; list; list = list->next) |
578 | init_readable (); /* inits useful arrays for readable texts */ |
601 | { |
579 | init_formulae (); /* If not called before, reads formulae from file */ |
602 | fprintf (stderr, "\nRACE %s:\t", &list->name); |
|
|
603 | for (tmp = list->member; tmp; tmp = tmp->next) |
|
|
604 | fprintf (stderr, "%s(%d), ", &tmp->ob->arch->archname, tmp->ob->level); |
|
|
605 | } |
|
|
606 | |
|
|
607 | fprintf (stderr, "\n"); |
|
|
608 | } |
580 | } |
609 | |
581 | |
610 | void |
|
|
611 | add_to_racelist (const char *race_name, object *op) |
|
|
612 | { |
|
|
613 | racelink *race; |
|
|
614 | |
|
|
615 | if (!op || !race_name) |
|
|
616 | return; |
|
|
617 | |
|
|
618 | race = find_racelink (race_name); |
|
|
619 | |
|
|
620 | if (!race) |
|
|
621 | { /* add in a new race list */ |
|
|
622 | race = get_racelist (); |
|
|
623 | race->next = first_race; |
|
|
624 | first_race = race; |
|
|
625 | race->name = race_name; |
|
|
626 | } |
|
|
627 | |
|
|
628 | if (race->member->ob) |
|
|
629 | { |
|
|
630 | objectlink *tmp = get_objectlink (); |
|
|
631 | |
|
|
632 | tmp->next = race->member; |
|
|
633 | race->member = tmp; |
|
|
634 | } |
|
|
635 | |
|
|
636 | race->nrof++; |
|
|
637 | race->member->ob = op; |
|
|
638 | } |
|
|
639 | |
|
|
640 | racelink * |
|
|
641 | get_racelist () |
|
|
642 | { |
|
|
643 | racelink *list = new racelink; |
|
|
644 | |
|
|
645 | list->name = 0; |
|
|
646 | list->nrof = 0; |
|
|
647 | list->next = 0; |
|
|
648 | list->member = get_objectlink (); |
|
|
649 | |
|
|
650 | return list; |
|
|
651 | } |
|
|
652 | |
|
|
653 | racelink * |
|
|
654 | find_racelink (const char *name) |
|
|
655 | { |
|
|
656 | if (name) |
|
|
657 | for (racelink *link = first_race; link; link = link->next) |
|
|
658 | if (!link->name || !strcmp (name, link->name)) |
|
|
659 | return link; |
|
|
660 | |
|
|
661 | return 0; |
|
|
662 | } |
|
|