diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 23486c8aa..64ae06477 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -508,21 +508,25 @@ static void json_prefixes(cJSON *json) { * 3. a "module.enabled" flag in the settings */ static void disable_feature(const char *str) { - // FIXME: this is slower than balls. + char name[32]; int k; + skill_t sk; + sk = findskill(str); + if (sk != NOSKILL) { + enable_skill(sk, false); + return; + } for (k = 0; k != MAXKEYWORDS; ++k) { + // FIXME: this loop is slow as balls. if (strcmp(keywords[k], str) == 0) { log_info("disable keyword %s\n", str); enable_keyword(k, false); - break; + return; } } - if (k == MAXKEYWORDS) { - char name[32]; - _snprintf(name, sizeof(name), "%s.enabled", str); - log_info("disable feature %s\n", name); - set_param(&global.parameters, name, "0"); - } + _snprintf(name, sizeof(name), "%s.enabled", str); + log_info("disable feature %s\n", name); + set_param(&global.parameters, name, "0"); } static void json_disable_features(cJSON *json) { diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index 0474b99a6..d7a4ad0cd 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -102,6 +102,7 @@ static void test_prefixes(CuTest * tc) static void test_disable(CuTest * tc) { const char * data = "{\"disabled\": [ " + "\"alchemy\"," "\"pay\"," "\"besiege\"," "\"module\"" @@ -109,11 +110,13 @@ static void test_disable(CuTest * tc) cJSON *json = cJSON_Parse(data); test_cleanup(); + CuAssertTrue(tc, skill_enabled(SK_ALCHEMY)); CuAssertTrue(tc, !keyword_disabled(K_BANNER)); CuAssertTrue(tc, !keyword_disabled(K_PAY)); CuAssertTrue(tc, !keyword_disabled(K_BESIEGE)); CuAssertIntEquals(tc, 1, get_param_int(global.parameters, "module.enabled", 1)); json_config(json); + CuAssertTrue(tc, !skill_enabled(SK_ALCHEMY)); CuAssertTrue(tc, !keyword_disabled(K_BANNER)); CuAssertTrue(tc, keyword_disabled(K_PAY)); CuAssertTrue(tc, keyword_disabled(K_BESIEGE)); diff --git a/src/tests.c b/src/tests.c index 3389aff01..596d7b02f 100644 --- a/src/tests.c +++ b/src/tests.c @@ -89,6 +89,9 @@ void test_cleanup(void) free_seen(); free_prefixes(); mt_clear(); + for (i = 0; i != MAXSKILLS; ++i) { + enable_skill(i, true); + } for (i = 0; i != MAXKEYWORDS; ++i) { enable_keyword(i, true); }