forked from github/server
BUG 2301: validate [game] section in eressea.ini
load_inifile is old stuff, should use config_get instead.
This commit is contained in:
parent
7b4550b9d6
commit
4b88a5abc7
|
@ -732,6 +732,17 @@ bool config_changed(int *cache_key) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static const char * valid_keys[] = {
|
||||
"game.id",
|
||||
"game.name",
|
||||
"game.locale",
|
||||
"game.verbose",
|
||||
"game.email",
|
||||
"game.mailcmd",
|
||||
"game.sender",
|
||||
NULL
|
||||
};
|
||||
|
||||
#define MAXKEYS 16
|
||||
void config_set_from(const dictionary *d)
|
||||
{
|
||||
|
@ -742,6 +753,8 @@ void config_set_from(const dictionary *d)
|
|||
int k, nkeys = iniparser_getsecnkeys(d, sec);
|
||||
const char *keys[MAXKEYS];
|
||||
size_t slen = strlen(sec);
|
||||
bool check = strcmp(sec, "game") == 0;
|
||||
|
||||
assert(nkeys <= MAXKEYS);
|
||||
assert(slen<sizeof(key));
|
||||
memcpy(key, sec, slen);
|
||||
|
@ -756,6 +769,15 @@ void config_set_from(const dictionary *d)
|
|||
val = iniparser_getstring(d, keys[k], NULL);
|
||||
if (!orig) {
|
||||
if (val) {
|
||||
if (check) {
|
||||
int i;
|
||||
for (i = 0; valid_keys[i]; ++i) {
|
||||
if (strcmp(key, valid_keys[i]) == 0) break;
|
||||
}
|
||||
if (!valid_keys[i]) {
|
||||
log_error("unknown key in ini-section %s: %s = %s", sec, key, val);
|
||||
}
|
||||
}
|
||||
config_set(key, val);
|
||||
}
|
||||
} else {
|
||||
|
|
14
src/main.c
14
src/main.c
|
@ -68,8 +68,13 @@ static void load_inifile(dictionary * d)
|
|||
}
|
||||
|
||||
lomem = iniparser_getint(d, "game:lomem", lomem) ? 1 : 0;
|
||||
|
||||
verbosity = iniparser_getint(d, "game:verbose", 2);
|
||||
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
||||
#ifdef USE_CURSES
|
||||
/* only one value in the [editor] section */
|
||||
force_color = iniparser_getint(d, "editor:color", force_color);
|
||||
gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage);
|
||||
#endif
|
||||
}
|
||||
|
||||
static dictionary *parse_config(const char *filename)
|
||||
|
@ -89,13 +94,6 @@ static dictionary *parse_config(const char *filename)
|
|||
if (d) {
|
||||
load_inifile(d);
|
||||
config_set_from(d);
|
||||
|
||||
memdebug = iniparser_getint(d, "game:memcheck", memdebug);
|
||||
#ifdef USE_CURSES
|
||||
/* only one value in the [editor] section */
|
||||
force_color = iniparser_getint(d, "editor:color", force_color);
|
||||
gm_codepage = iniparser_getint(d, "editor:codepage", gm_codepage);
|
||||
#endif
|
||||
}
|
||||
str = config_get("game.locales");
|
||||
make_locales(str ? str : "de,en");
|
||||
|
|
Loading…
Reference in New Issue