forked from github/server
allow disabling skills through json
This commit is contained in:
parent
a01955e06a
commit
1e75255d51
|
@ -508,22 +508,26 @@ static void json_prefixes(cJSON *json) {
|
||||||
* 3. a "module.enabled" flag in the settings
|
* 3. a "module.enabled" flag in the settings
|
||||||
*/
|
*/
|
||||||
static void disable_feature(const char *str) {
|
static void disable_feature(const char *str) {
|
||||||
// FIXME: this is slower than balls.
|
char name[32];
|
||||||
int k;
|
int k;
|
||||||
|
skill_t sk;
|
||||||
|
sk = findskill(str);
|
||||||
|
if (sk != NOSKILL) {
|
||||||
|
enable_skill(sk, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (k = 0; k != MAXKEYWORDS; ++k) {
|
for (k = 0; k != MAXKEYWORDS; ++k) {
|
||||||
|
// FIXME: this loop is slow as balls.
|
||||||
if (strcmp(keywords[k], str) == 0) {
|
if (strcmp(keywords[k], str) == 0) {
|
||||||
log_info("disable keyword %s\n", str);
|
log_info("disable keyword %s\n", str);
|
||||||
enable_keyword(k, false);
|
enable_keyword(k, false);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (k == MAXKEYWORDS) {
|
|
||||||
char name[32];
|
|
||||||
_snprintf(name, sizeof(name), "%s.enabled", str);
|
_snprintf(name, sizeof(name), "%s.enabled", str);
|
||||||
log_info("disable feature %s\n", name);
|
log_info("disable feature %s\n", name);
|
||||||
set_param(&global.parameters, name, "0");
|
set_param(&global.parameters, name, "0");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void json_disable_features(cJSON *json) {
|
static void json_disable_features(cJSON *json) {
|
||||||
cJSON *child;
|
cJSON *child;
|
||||||
|
|
|
@ -102,6 +102,7 @@ static void test_prefixes(CuTest * tc)
|
||||||
static void test_disable(CuTest * tc)
|
static void test_disable(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"disabled\": [ "
|
const char * data = "{\"disabled\": [ "
|
||||||
|
"\"alchemy\","
|
||||||
"\"pay\","
|
"\"pay\","
|
||||||
"\"besiege\","
|
"\"besiege\","
|
||||||
"\"module\""
|
"\"module\""
|
||||||
|
@ -109,11 +110,13 @@ static void test_disable(CuTest * tc)
|
||||||
cJSON *json = cJSON_Parse(data);
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
|
CuAssertTrue(tc, skill_enabled(SK_ALCHEMY));
|
||||||
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
||||||
CuAssertTrue(tc, !keyword_disabled(K_PAY));
|
CuAssertTrue(tc, !keyword_disabled(K_PAY));
|
||||||
CuAssertTrue(tc, !keyword_disabled(K_BESIEGE));
|
CuAssertTrue(tc, !keyword_disabled(K_BESIEGE));
|
||||||
CuAssertIntEquals(tc, 1, get_param_int(global.parameters, "module.enabled", 1));
|
CuAssertIntEquals(tc, 1, get_param_int(global.parameters, "module.enabled", 1));
|
||||||
json_config(json);
|
json_config(json);
|
||||||
|
CuAssertTrue(tc, !skill_enabled(SK_ALCHEMY));
|
||||||
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
||||||
CuAssertTrue(tc, keyword_disabled(K_PAY));
|
CuAssertTrue(tc, keyword_disabled(K_PAY));
|
||||||
CuAssertTrue(tc, keyword_disabled(K_BESIEGE));
|
CuAssertTrue(tc, keyword_disabled(K_BESIEGE));
|
||||||
|
|
|
@ -89,6 +89,9 @@ void test_cleanup(void)
|
||||||
free_seen();
|
free_seen();
|
||||||
free_prefixes();
|
free_prefixes();
|
||||||
mt_clear();
|
mt_clear();
|
||||||
|
for (i = 0; i != MAXSKILLS; ++i) {
|
||||||
|
enable_skill(i, true);
|
||||||
|
}
|
||||||
for (i = 0; i != MAXKEYWORDS; ++i) {
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
enable_keyword(i, true);
|
enable_keyword(i, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue