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