1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
|
|
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <unistd.h> |
26 | #include <unistd.h> |
|
|
27 | |
|
|
28 | #include "loader.h" |
|
|
29 | |
|
|
30 | regionvec regions; |
|
|
31 | |
|
|
32 | region * |
|
|
33 | region::default_region () |
|
|
34 | { |
|
|
35 | for_all_regions (rgn) |
|
|
36 | if (rgn->fallback) |
|
|
37 | return rgn; |
|
|
38 | |
|
|
39 | return regions [0]; |
|
|
40 | } |
27 | |
41 | |
28 | /* |
42 | /* |
29 | * Pass a char array, returns a pointer to the region of the same name. |
43 | * Pass a char array, returns a pointer to the region of the same name. |
30 | * if it can't find a region of the same name it returns the first region |
44 | * if it can't find a region of the same name it returns the first region |
31 | * with the 'fallback' property set. |
45 | * with the 'fallback' property set. |
32 | * if it can't find a matching name /or/ a fallback region it logs an info message |
46 | * if it can't find a matching name /or/ a fallback region it logs an info message |
33 | * message and returns NULL |
47 | * message and returns NULL |
34 | * used by the map parsing code. |
48 | * used by the map parsing code. |
35 | */ |
49 | */ |
36 | region * |
50 | region * |
37 | get_region_by_name (const char *region_name) |
51 | region::find (const char *name) |
38 | { |
52 | { |
39 | region *reg; |
53 | for_all_regions (rgn) |
40 | char *p = strchr (region_name, '\n'); |
|
|
41 | |
|
|
42 | if (p) |
|
|
43 | *p = '\0'; |
|
|
44 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
45 | if (!strcmp (reg->name, region_name)) |
54 | if (!strcmp (rgn->name, name)) |
46 | return reg; |
55 | return rgn; |
47 | |
56 | |
48 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
49 | { |
|
|
50 | if (reg->fallback) |
|
|
51 | { |
|
|
52 | LOG (llevDebug, "region called %s requested, but not found, fallback used.\n", region_name); |
57 | LOG (llevError, "region called %s requested, but not found, using fallback.\n", name); |
53 | return reg; |
|
|
54 | } |
|
|
55 | } |
|
|
56 | LOG (llevInfo, "Got no region or fallback for region %s.\n", region_name); |
|
|
57 | return NULL; |
|
|
58 | } |
|
|
59 | |
58 | |
60 | /* This might need optimising at some point. */ |
59 | return default_region (); |
61 | region * |
|
|
62 | get_region_by_map (maptile *m) |
|
|
63 | { |
|
|
64 | return get_region_by_name (get_name_of_region_for_map (m)); |
|
|
65 | } |
|
|
66 | |
|
|
67 | /* |
|
|
68 | * Since we won't assume all maps have a region set properly, we need an |
|
|
69 | * explicit check that it is, this is much nicer here than scattered throughout |
|
|
70 | * the map code. |
|
|
71 | */ |
|
|
72 | |
|
|
73 | const char * |
|
|
74 | get_name_of_region_for_map (const maptile *m) |
|
|
75 | { |
|
|
76 | region *reg; |
|
|
77 | |
|
|
78 | if (m->region != NULL) |
|
|
79 | return m->region->name; |
|
|
80 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
81 | { |
|
|
82 | if (reg->fallback) |
|
|
83 | return reg->name; |
|
|
84 | } |
|
|
85 | LOG (llevInfo, "map %s had no region and I couldn't find a fallback to use.\n", m->name); |
|
|
86 | return "unknown"; |
|
|
87 | } |
60 | } |
88 | |
61 | |
89 | /* |
62 | /* |
90 | * Tries to find a region that 'name' corresponds to. |
63 | * Tries to find a region that 'name' corresponds to. |
91 | * It looks, in order, for: |
64 | * It looks, in order, for: |
… | |
… | |
97 | * (there should be only one of these - the top level one) |
70 | * (there should be only one of these - the top level one) |
98 | * If we got a NULL, then just return the top level region |
71 | * If we got a NULL, then just return the top level region |
99 | * |
72 | * |
100 | */ |
73 | */ |
101 | region * |
74 | region * |
102 | get_region_from_string (const char *name) |
75 | region::find_fuzzy (const char *name) |
103 | { |
76 | { |
104 | region *reg; |
77 | if (!name) |
105 | char *substr; |
78 | return default_region (); |
106 | char *p; |
|
|
107 | |
79 | |
108 | if (name == NULL) |
|
|
109 | { |
|
|
110 | for (reg = first_region; reg->parent != NULL; reg = reg->parent); |
|
|
111 | return reg; |
|
|
112 | } |
|
|
113 | p = strchr (name, '\n'); |
80 | char *p = strchr (name, '\n'); |
114 | if (p) |
81 | if (p) |
115 | *p = '\0'; |
82 | *p = '\0'; |
116 | for (reg = first_region; reg != NULL; reg = reg->next) |
83 | |
|
|
84 | for_all_regions (rgn) |
117 | if (!strcasecmp (reg->name, name)) |
85 | if (!strcasecmp (rgn->name, name)) |
118 | return reg; |
86 | return rgn; |
119 | |
87 | |
120 | for (reg = first_region; reg != NULL; reg = reg->next) |
88 | for_all_regions (rgn) |
121 | if (reg->longname != NULL) |
89 | if (rgn->longname) |
|
|
90 | if (!strcasecmp (rgn->longname, name)) |
|
|
91 | return rgn; |
|
|
92 | |
|
|
93 | for_all_regions (rgn) |
|
|
94 | if (rgn->longname) |
122 | { |
95 | { |
123 | if (!strcasecmp (reg->longname, name)) |
96 | if (strstr (rgn->longname, name)) |
124 | return reg; |
97 | return rgn; |
125 | } |
98 | } |
126 | |
99 | |
127 | substr = NULL; |
100 | for_all_regions (rgn) |
128 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
129 | if (reg->longname != NULL) |
101 | if (rgn->longname) |
130 | { |
|
|
131 | substr = strstr (reg->longname, name); |
|
|
132 | if (substr != NULL) |
|
|
133 | return reg; |
|
|
134 | } |
|
|
135 | for (reg = first_region; reg != NULL; reg = reg->next) |
|
|
136 | if (reg->longname != NULL) |
|
|
137 | { |
102 | { |
138 | /* |
103 | /* |
139 | * This is not a bug, we want the region that is most identifiably a discrete |
104 | * This is not a bug, we want the region that is most identifiably a discrete |
140 | * area in the game, eg if we have 'scor', we want to return 'scorn' and not |
105 | * area in the game, eg if we have 'scor', we want to return 'scorn' and not |
141 | * 'scornarena', regardless of their order on the list so we only look at those |
106 | * 'scornarena', regardless of their order on the list so we only look at those |
142 | * regions with a longname set. |
107 | * regions with a longname set. |
143 | */ |
108 | */ |
144 | substr = strstr (reg->name, name); |
109 | if (strstr (rgn->name, name)) |
145 | if (substr != NULL) |
|
|
146 | return reg; |
110 | return rgn; |
147 | } |
111 | } |
148 | for (reg = first_region; reg != NULL; reg = reg->next) |
112 | |
|
|
113 | for_all_regions (rgn) |
149 | { |
114 | { |
150 | substr = strstr (reg->name, name); |
115 | if (strstr (rgn->name, name)) |
151 | if (substr != NULL) |
|
|
152 | return reg; |
116 | return rgn; |
153 | } |
117 | } |
154 | /* if we are still here, we are going to have to give up, and give the top level region */ |
118 | |
155 | for (reg = first_region; reg->parent != NULL; reg = reg->parent); |
119 | return default_region (); |
156 | return reg; |
|
|
157 | } |
120 | } |
158 | |
121 | |
159 | /* |
122 | /* |
160 | * returns 1 if the player is in the region reg, or a child region thereof |
123 | * returns 1 if the player is in the region reg, or a child region thereof |
161 | * otherwise returns 0 |
124 | * otherwise returns 0 |
162 | * if passed a NULL region returns -1 |
125 | * if passed a NULL region returns -1 |
163 | */ |
126 | */ |
164 | |
127 | |
165 | int |
128 | static int |
166 | region_is_child_of_region (const region * child, const region * r) |
129 | region_is_child_of_region (const region * child, const region * r) |
167 | { |
130 | { |
168 | |
131 | |
169 | if (r == NULL) |
132 | if (r == NULL) |
170 | return -1; |
133 | return -1; |
|
|
134 | |
171 | if (child == NULL) |
135 | if (child == NULL) |
172 | return 0; |
136 | return 0; |
|
|
137 | |
173 | if (!strcmp (child->name, r->name)) |
138 | if (!strcmp (child->name, r->name)) |
174 | return 1; |
139 | return 1; |
|
|
140 | |
175 | else if (child->parent != NULL) |
141 | else if (child->parent != NULL) |
176 | return region_is_child_of_region (child->parent, r); |
142 | return region_is_child_of_region (child->parent, r); |
177 | else |
143 | else |
178 | return 0; |
144 | return 0; |
179 | } |
145 | } |
180 | |
146 | |
181 | /* |
|
|
182 | * the longname of a region is not a required field, any given region |
|
|
183 | * may want to not set it and use the parent's one instead. so, we: |
|
|
184 | * 1. check if a longname is set and if so return it. |
|
|
185 | * 2. check if there is a parent and try and call the function against that |
|
|
186 | * 3. return a obviously wrong string if we can't get a longname, this should |
|
|
187 | * never happen. We also log a debug message. |
|
|
188 | */ |
|
|
189 | const char * |
|
|
190 | get_region_longname (const region * r) |
|
|
191 | { |
|
|
192 | |
|
|
193 | if (r->longname != NULL) |
|
|
194 | return r->longname; |
|
|
195 | else if (r->parent != NULL) |
|
|
196 | return get_region_longname (r->parent); |
|
|
197 | else |
|
|
198 | { |
|
|
199 | LOG (llevDebug, "NOTICE region %s has no parent and no longname.\n", r->name); |
|
|
200 | return "no name can be found for the current region"; |
|
|
201 | } |
|
|
202 | } |
|
|
203 | |
|
|
204 | const char * |
|
|
205 | get_region_msg (const region * r) |
|
|
206 | { |
|
|
207 | if (r->msg != NULL) |
|
|
208 | return r->msg; |
|
|
209 | else if (r->parent != NULL) |
|
|
210 | return get_region_msg (r->parent); |
|
|
211 | else |
|
|
212 | { |
|
|
213 | LOG (llevDebug, "NOTICE region %s has no parent and no msg.\n", r->name); |
|
|
214 | return "no description can be found for the current region"; |
|
|
215 | } |
|
|
216 | } |
|
|
217 | |
|
|
218 | /** Returns an object which is an exit through which the player represented by op should be |
147 | /** Returns an object which is an exit through which the player represented by op should be |
219 | * sent in order to be imprisoned. If there is no suitable place to which an exit can be |
148 | * sent in order to be imprisoned. If there is no suitable place to which an exit can be |
220 | * constructed, then NULL will be returned. The caller is responsible for freeing the object |
149 | * constructed, then NULL will be returned. The caller is responsible for freeing the object |
221 | * created by this function. |
150 | * created by this function. |
222 | */ |
151 | */ |
… | |
… | |
229 | if (op->type != PLAYER) |
158 | if (op->type != PLAYER) |
230 | { |
159 | { |
231 | LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); |
160 | LOG (llevError, "region.c: get_jail_exit called against non-player object.\n"); |
232 | return NULL; |
161 | return NULL; |
233 | } |
162 | } |
234 | reg = get_region_by_map (op->map); |
163 | |
|
|
164 | reg = op->region (); |
235 | while (reg != NULL) |
165 | while (reg) |
236 | { |
166 | { |
237 | if (reg->jailmap) |
167 | if (reg->jailmap) |
238 | { |
168 | { |
239 | exit = get_object (); |
169 | exit = object::create (); |
240 | EXIT_PATH (exit) = reg->jailmap; |
170 | EXIT_PATH (exit) = reg->jailmap; |
241 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
171 | /* damned exits reset savebed and remove teleports, so the prisoner can't escape */ |
242 | SET_FLAG (exit, FLAG_DAMNED); |
172 | SET_FLAG (exit, FLAG_DAMNED); |
243 | EXIT_X (exit) = reg->jailx; |
173 | EXIT_X (exit) = reg->jailx; |
244 | EXIT_Y (exit) = reg->jaily; |
174 | EXIT_Y (exit) = reg->jaily; |
245 | return exit; |
175 | return exit; |
246 | } |
176 | } |
247 | else |
177 | else |
248 | reg = reg->parent; |
178 | reg = reg->parent; |
249 | } |
179 | } |
|
|
180 | |
250 | LOG (llevDebug, "No suitable jailmap for region %s was found.\n", reg->name); |
181 | LOG (llevError, "No suitable jailmap for region %s was found.\n", ®->name); |
|
|
182 | |
251 | return NULL; |
183 | return 0; |
|
|
184 | } |
|
|
185 | |
|
|
186 | region *loader_region::get_region (const char *name) |
|
|
187 | { |
|
|
188 | region *rgn = new region; |
|
|
189 | rgn->name = name; |
|
|
190 | return rgn; |
|
|
191 | } |
|
|
192 | |
|
|
193 | void loader_region::put_region (region *rgn) |
|
|
194 | { |
|
|
195 | for_all_regions (old) |
|
|
196 | if (old->name == rgn->name) |
|
|
197 | { |
|
|
198 | // replace, copy new values (ugly) |
|
|
199 | rgn->index = old->index; |
|
|
200 | *old = *rgn; |
|
|
201 | delete rgn; |
|
|
202 | |
|
|
203 | return; |
|
|
204 | } |
|
|
205 | |
|
|
206 | // just append |
|
|
207 | regions.push_back (rgn); |
|
|
208 | } |
|
|
209 | |
|
|
210 | bool |
|
|
211 | loader_base::parse_region (object_thawer &thawer, region *rgn) |
|
|
212 | { |
|
|
213 | for (;;) |
|
|
214 | { |
|
|
215 | keyword kw = thawer.get_kv (); |
|
|
216 | |
|
|
217 | switch (kw) |
|
|
218 | { |
|
|
219 | case KW_parent: |
|
|
220 | rgn->parent = region::find (thawer.get_str ()); |
|
|
221 | break; |
|
|
222 | |
|
|
223 | case KW_longname: |
|
|
224 | thawer.get (rgn->longname); |
|
|
225 | break; |
|
|
226 | |
|
|
227 | case KW_jail_map: |
|
|
228 | thawer.get (rgn->jailmap); |
|
|
229 | break; |
|
|
230 | |
|
|
231 | case KW_jail_x: |
|
|
232 | thawer.get (rgn->jailx); |
|
|
233 | break; |
|
|
234 | |
|
|
235 | case KW_jail_y: |
|
|
236 | thawer.get (rgn->jaily); |
|
|
237 | break; |
|
|
238 | |
|
|
239 | case KW_msg: |
|
|
240 | thawer.get_ml (KW_endmsg, rgn->msg); |
|
|
241 | break; |
|
|
242 | |
|
|
243 | case KW_fallback: |
|
|
244 | thawer.get (rgn->fallback); |
|
|
245 | break; |
|
|
246 | |
|
|
247 | case KW_end: |
|
|
248 | return true; |
|
|
249 | |
|
|
250 | default: |
|
|
251 | if (!thawer.parse_error (kw, "region", rgn->name)) |
|
|
252 | return false; |
|
|
253 | break; |
|
|
254 | } |
|
|
255 | } |
252 | } |
256 | } |
253 | |
257 | |
254 | /* |
258 | /* |
255 | * First initialises the archtype hash-table (init_archetable()). |
259 | * First initialises the archtype hash-table (init_archetable()). |
256 | * Reads and parses the archetype file (with the first and second-pass |
260 | * Reads and parses the archetype file (with the first and second-pass |
… | |
… | |
258 | * Then initialises treasures by calling load_treasures(). |
262 | * Then initialises treasures by calling load_treasures(). |
259 | */ |
263 | */ |
260 | void |
264 | void |
261 | init_regions (void) |
265 | init_regions (void) |
262 | { |
266 | { |
263 | FILE *fp; |
|
|
264 | char filename[MAX_BUF]; |
267 | char filename[MAX_BUF]; |
265 | int comp; |
268 | int comp; |
266 | |
269 | |
267 | if (first_region != NULL) /* Only do this once */ |
270 | if (!regions.size ()) |
268 | return; |
271 | { |
|
|
272 | // make sure one region is always available |
|
|
273 | region *rgn = new region; |
|
|
274 | rgn->name = "<builtin>"; |
|
|
275 | rgn->longname = "Built-in Region"; |
|
|
276 | regions.push_back (rgn); |
|
|
277 | } |
269 | |
278 | |
270 | sprintf (filename, "%s/%s/%s", settings.datadir, settings.mapdir, settings.regions); |
279 | sprintf (filename, "%s/%s/%s", settings.datadir, settings.mapdir, settings.regions); |
271 | LOG (llevDebug, "Reading regions from %s...\n", filename); |
280 | LOG (llevDebug, "Reading regions from %s...\n", filename); |
272 | if ((fp = open_and_uncompress (filename, 0, &comp)) == NULL) |
281 | |
|
|
282 | loader_region loader; |
|
|
283 | |
|
|
284 | if (!loader.load (filename)) |
273 | { |
285 | { |
274 | LOG (llevError, " Can't open regions file %s in init_regions.\n", filename); |
286 | LOG (llevError, "Can't open regions file %s in init_regions.\n", filename); |
275 | return; |
287 | return; |
276 | } |
288 | } |
277 | parse_regions (fp); |
289 | |
278 | assign_region_parents (); |
|
|
279 | LOG (llevDebug, " done\n"); |
290 | LOG (llevDebug, " done\n"); |
280 | |
|
|
281 | close_and_delete (fp, comp); |
|
|
282 | } |
291 | } |
283 | |
|
|
284 | /* |
|
|
285 | * Allocates and zeros a region struct, this isn't free()'d anywhere, so might |
|
|
286 | * be a memory leak, but it shouldn't matter too much since it isn't called that |
|
|
287 | * often.... |
|
|
288 | */ |
|
|
289 | |
|
|
290 | region * |
|
|
291 | get_region_struct (void) |
|
|
292 | { |
|
|
293 | |
|
|
294 | region *reg; |
|
|
295 | |
|
|
296 | reg = (region *) CALLOC (1, sizeof (region)); |
|
|
297 | if (reg == NULL) |
|
|
298 | fatal (OUT_OF_MEMORY); |
|
|
299 | |
|
|
300 | memset (reg, '\0', sizeof (region)); |
|
|
301 | |
|
|
302 | return reg; |
|
|
303 | } |
|
|
304 | |
|
|
305 | /* |
|
|
306 | * Reads/parses the region file, and copies into a linked list |
|
|
307 | * of region structs. |
|
|
308 | */ |
|
|
309 | void |
|
|
310 | parse_regions (FILE * fp) |
|
|
311 | { |
|
|
312 | region *newreg; |
|
|
313 | region *reg; |
|
|
314 | |
|
|
315 | char buf[HUGE_BUF], msgbuf[HUGE_BUF], *key = NULL, *value, *end; |
|
|
316 | int msgpos = 0; |
|
|
317 | |
|
|
318 | newreg = NULL; |
|
|
319 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
|
|
320 | { |
|
|
321 | buf[HUGE_BUF - 1] = 0; |
|
|
322 | key = buf; |
|
|
323 | while (isspace (*key)) |
|
|
324 | key++; |
|
|
325 | if (*key == 0) |
|
|
326 | continue; /* empty line */ |
|
|
327 | value = strchr (key, ' '); |
|
|
328 | if (!value) |
|
|
329 | { |
|
|
330 | end = strchr (key, '\n'); |
|
|
331 | *end = 0; |
|
|
332 | } |
|
|
333 | else |
|
|
334 | { |
|
|
335 | *value = 0; |
|
|
336 | value++; |
|
|
337 | while (isspace (*value)) |
|
|
338 | value++; |
|
|
339 | end = strchr (value, '\n'); |
|
|
340 | } |
|
|
341 | |
|
|
342 | /* |
|
|
343 | * This is a bizzare mutated form of the map and archetype parser |
|
|
344 | * rolled into one. Key is the field name, value is what it should |
|
|
345 | * be set to. |
|
|
346 | * We've already done the work to null terminate key, |
|
|
347 | * and strip off any leading spaces for both of these. |
|
|
348 | * We have not touched the newline at the end of the line - |
|
|
349 | * these might be needed for some values. the end pointer |
|
|
350 | * points to the first of the newlines. |
|
|
351 | * value could be NULL! It would be easy enough to just point |
|
|
352 | * this to "" to prevent cores, but that would let more errors slide |
|
|
353 | * through. |
|
|
354 | */ |
|
|
355 | if (!strcmp (key, "region")) |
|
|
356 | { |
|
|
357 | *end = 0; |
|
|
358 | newreg = get_region_struct (); |
|
|
359 | newreg->name = strdup_local (value); |
|
|
360 | } |
|
|
361 | else if (!strcmp (key, "parent")) |
|
|
362 | { |
|
|
363 | /* |
|
|
364 | * Note that this is in the initialisation code, so we don't actually |
|
|
365 | * assign the pointer to the parent yet, because it might not have been |
|
|
366 | * parsed. |
|
|
367 | */ |
|
|
368 | *end = 0; |
|
|
369 | newreg->parent_name = strdup_local (value); |
|
|
370 | } |
|
|
371 | else if (!strcmp (key, "longname")) |
|
|
372 | { |
|
|
373 | *end = 0; |
|
|
374 | newreg->longname = strdup_local (value); |
|
|
375 | } |
|
|
376 | else if (!strcmp (key, "jail")) |
|
|
377 | { |
|
|
378 | /* jail entries are of the form: /path/to/map x y */ |
|
|
379 | char path[MAX_BUF]; |
|
|
380 | int x, y; |
|
|
381 | |
|
|
382 | if (sscanf (value, "%[^ ] %d %d\n", path, &x, &y) != 3) |
|
|
383 | { |
|
|
384 | LOG (llevError, "region.c: malformated regions entry: jail %s\n", value); |
|
|
385 | continue; |
|
|
386 | } |
|
|
387 | newreg->jailmap = strdup_local (path); |
|
|
388 | newreg->jailx = x; |
|
|
389 | newreg->jaily = y; |
|
|
390 | } |
|
|
391 | else if (!strcmp (key, "msg")) |
|
|
392 | { |
|
|
393 | while (fgets (buf, HUGE_BUF - 1, fp) != NULL) |
|
|
394 | { |
|
|
395 | if (!strcmp (buf, "endmsg\n")) |
|
|
396 | break; |
|
|
397 | else |
|
|
398 | { |
|
|
399 | strcpy (msgbuf + msgpos, buf); |
|
|
400 | msgpos += strlen (buf); |
|
|
401 | } |
|
|
402 | } |
|
|
403 | /* |
|
|
404 | * There may be regions with empty messages (eg, msg/endmsg |
|
|
405 | * with nothing between). When maps are loaded, this is done |
|
|
406 | * so better do it here too... |
|
|
407 | */ |
|
|
408 | if (msgpos != 0) |
|
|
409 | newreg->msg = strdup_local (msgbuf); |
|
|
410 | |
|
|
411 | /* we have to reset msgpos, or the next region will store both msg blocks. */ |
|
|
412 | msgpos = 0; |
|
|
413 | } |
|
|
414 | else if (!strcmp (key, "fallback")) |
|
|
415 | { |
|
|
416 | *end = 0; |
|
|
417 | newreg->fallback = atoi (value); |
|
|
418 | } |
|
|
419 | else if (!strcmp (key, "end")) |
|
|
420 | { |
|
|
421 | /* Place this new region last on the list, if the list is empty put it first */ |
|
|
422 | for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next); |
|
|
423 | |
|
|
424 | if (reg == NULL) |
|
|
425 | first_region = newreg; |
|
|
426 | else |
|
|
427 | reg->next = newreg; |
|
|
428 | newreg = NULL; |
|
|
429 | } |
|
|
430 | else if (!strcmp (key, "nomore")) |
|
|
431 | { |
|
|
432 | /* we have reached the end of the region specs.... */ |
|
|
433 | break; |
|
|
434 | } |
|
|
435 | else |
|
|
436 | { |
|
|
437 | /* we should never get here, if we have, then something is wrong */ |
|
|
438 | LOG (llevError, "Got unknown value in region file: %s %s\n", key, value); |
|
|
439 | } |
|
|
440 | } |
|
|
441 | if (!key || strcmp (key, "nomore")) |
|
|
442 | LOG (llevError, "Got premature eof on regions file!\n"); |
|
|
443 | } |
|
|
444 | |
|
|
445 | void |
|
|
446 | assign_region_parents (void) |
|
|
447 | { |
|
|
448 | region *reg; |
|
|
449 | uint32 parent_count = 0; |
|
|
450 | uint32 region_count = 0; |
|
|
451 | |
|
|
452 | for (reg = first_region; reg != NULL && reg->next != NULL; reg = reg->next) |
|
|
453 | { |
|
|
454 | if (reg->parent_name != NULL) |
|
|
455 | { |
|
|
456 | reg->parent = get_region_by_name (reg->parent_name); |
|
|
457 | parent_count++; |
|
|
458 | } |
|
|
459 | region_count++; |
|
|
460 | } |
|
|
461 | LOG (llevDebug, "Assigned %u regions with %u parents.", region_count, parent_count); |
|
|
462 | } |
|
|