allow disabling skills through json

This commit is contained in:
Enno Rehling 2015-09-12 17:43:31 +02:00
parent a01955e06a
commit 1e75255d51
3 changed files with 18 additions and 8 deletions

View File

@ -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) {

View File

@ -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));

View File

@ -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);
}