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