forked from github/server
Merge pull request #297 from ennorehling/feature/json-disable-keywords
disable keywords in JSON, not XML
This commit is contained in:
commit
e80f53d35e
|
@ -4,6 +4,9 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e2/terrains.json"
|
"e2/terrains.json"
|
||||||
],
|
],
|
||||||
|
"disable": [
|
||||||
|
"pay"
|
||||||
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 2,
|
"game.id": 2,
|
||||||
"game.name": "Eressea",
|
"game.name": "Eressea",
|
||||||
|
|
|
@ -54,10 +54,6 @@
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
<game>
|
||||||
<!-- Game specific settings -->
|
|
||||||
|
|
||||||
<order name="pay" disable="yes"/>
|
|
||||||
|
|
||||||
<skill name="alchemy" enable="true"/>
|
<skill name="alchemy" enable="true"/>
|
||||||
<skill name="crossbow" enable="true"/>
|
<skill name="crossbow" enable="true"/>
|
||||||
<skill name="mining" enable="true"/>
|
<skill name="mining" enable="true"/>
|
||||||
|
|
|
@ -4,6 +4,17 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e3/terrains.json"
|
"e3/terrains.json"
|
||||||
],
|
],
|
||||||
|
"disable": [
|
||||||
|
"besiege",
|
||||||
|
"steal",
|
||||||
|
"buy",
|
||||||
|
"teach",
|
||||||
|
"sabotage",
|
||||||
|
"spy",
|
||||||
|
"tax",
|
||||||
|
"entertain",
|
||||||
|
"sell"
|
||||||
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 3,
|
"game.id": 3,
|
||||||
"game.name": "E3",
|
"game.name": "E3",
|
||||||
|
|
|
@ -43,17 +43,6 @@
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
<game>
|
||||||
<!-- Game specific settings -->
|
|
||||||
<order name="besiege" disable="yes"/>
|
|
||||||
<order name="steal" disable="yes"/>
|
|
||||||
<order name="buy" disable="yes"/>
|
|
||||||
<order name="teach" disable="yes"/>
|
|
||||||
<order name="sabotage" disable="yes"/>
|
|
||||||
<order name="spy" disable="yes"/>
|
|
||||||
<order name="tax" disable="yes"/>
|
|
||||||
<order name="entertain" disable="yes"/>
|
|
||||||
<order name="sell" disable="yes"/>
|
|
||||||
|
|
||||||
<skill name="armorer" enable="true"/>
|
<skill name="armorer" enable="true"/>
|
||||||
<skill name="bow" enable="true"/>
|
<skill name="bow" enable="true"/>
|
||||||
<skill name="building" enable="true"/>
|
<skill name="building" enable="true"/>
|
||||||
|
|
|
@ -4,6 +4,17 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e3/terrains.json"
|
"e3/terrains.json"
|
||||||
],
|
],
|
||||||
|
"disable": [
|
||||||
|
"besiege",
|
||||||
|
"steal",
|
||||||
|
"buy",
|
||||||
|
"teach",
|
||||||
|
"sabotage",
|
||||||
|
"spy",
|
||||||
|
"tax",
|
||||||
|
"entertain",
|
||||||
|
"sell"
|
||||||
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 4,
|
"game.id": 4,
|
||||||
"game.name": "Deveron",
|
"game.name": "Deveron",
|
||||||
|
|
|
@ -43,16 +43,6 @@
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
<game>
|
||||||
<order name="besiege" disable="yes"/>
|
|
||||||
<order name="steal" disable="yes"/>
|
|
||||||
<order name="buy" disable="yes"/>
|
|
||||||
<order name="teach" disable="yes"/>
|
|
||||||
<order name="sabotage" disable="yes"/>
|
|
||||||
<order name="spy" disable="yes"/>
|
|
||||||
<order name="tax" disable="yes"/>
|
|
||||||
<order name="entertain" disable="yes"/>
|
|
||||||
<order name="sell" disable="yes"/>
|
|
||||||
|
|
||||||
<skill name="armorer" enable="true"/>
|
<skill name="armorer" enable="true"/>
|
||||||
<skill name="bow" enable="true"/>
|
<skill name="bow" enable="true"/>
|
||||||
<skill name="building" enable="true"/>
|
<skill name="building" enable="true"/>
|
||||||
|
|
|
@ -501,6 +501,17 @@ static void json_prefixes(cJSON *json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void json_disable_keywords(cJSON *json) {
|
||||||
|
cJSON *child;
|
||||||
|
if (json->type != cJSON_Array) {
|
||||||
|
log_error("disable is not a json array: %d", json->type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (child = json->child; child; child = child->next) {
|
||||||
|
disable_keyword_str(child->valuestring);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void json_terrains(cJSON *json) {
|
static void json_terrains(cJSON *json) {
|
||||||
cJSON *child;
|
cJSON *child;
|
||||||
if (json->type != cJSON_Object) {
|
if (json->type != cJSON_Object) {
|
||||||
|
@ -854,6 +865,9 @@ void json_config(cJSON *json) {
|
||||||
else if (strcmp(child->string, "prefixes") == 0) {
|
else if (strcmp(child->string, "prefixes") == 0) {
|
||||||
json_prefixes(child);
|
json_prefixes(child);
|
||||||
}
|
}
|
||||||
|
else if (strcmp(child->string, "disable") == 0) {
|
||||||
|
json_disable_keywords(child);
|
||||||
|
}
|
||||||
else if (strcmp(child->string, "terrains") == 0) {
|
else if (strcmp(child->string, "terrains") == 0) {
|
||||||
json_terrains(child);
|
json_terrains(child);
|
||||||
init_terrains();
|
init_terrains();
|
||||||
|
|
|
@ -99,6 +99,25 @@ static void test_prefixes(CuTest * tc)
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_disable(CuTest * tc)
|
||||||
|
{
|
||||||
|
const char * data = "{\"disable\": [ "
|
||||||
|
"\"pay\","
|
||||||
|
"\"besiege\""
|
||||||
|
"]}";
|
||||||
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
|
||||||
|
test_cleanup();
|
||||||
|
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
||||||
|
CuAssertTrue(tc, !keyword_disabled(K_PAY));
|
||||||
|
CuAssertTrue(tc, !keyword_disabled(K_BESIEGE));
|
||||||
|
json_config(json);
|
||||||
|
CuAssertTrue(tc, !keyword_disabled(K_BANNER));
|
||||||
|
CuAssertTrue(tc, keyword_disabled(K_PAY));
|
||||||
|
CuAssertTrue(tc, keyword_disabled(K_BESIEGE));
|
||||||
|
test_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_races(CuTest * tc)
|
static void test_races(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"races\": { \"orc\" : { "
|
const char * data = "{\"races\": { \"orc\" : { "
|
||||||
|
@ -576,6 +595,7 @@ CuSuite *get_jsonconf_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_flags);
|
SUITE_ADD_TEST(suite, test_flags);
|
||||||
SUITE_ADD_TEST(suite, test_settings);
|
SUITE_ADD_TEST(suite, test_settings);
|
||||||
SUITE_ADD_TEST(suite, test_prefixes);
|
SUITE_ADD_TEST(suite, test_prefixes);
|
||||||
|
SUITE_ADD_TEST(suite, test_disable);
|
||||||
SUITE_ADD_TEST(suite, test_infinitive_from_config);
|
SUITE_ADD_TEST(suite, test_infinitive_from_config);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2066,30 +2066,6 @@ static int parse_main(xmlDocPtr doc)
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
/* reading eressea/game/order */
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "order", xpath);
|
|
||||||
nodes = result->nodesetval;
|
|
||||||
for (i = 0; i != nodes->nodeNr; ++i) {
|
|
||||||
xmlNodePtr node = nodes->nodeTab[i];
|
|
||||||
xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
|
|
||||||
|
|
||||||
if (xml_bvalue(node, "disable", false)) {
|
|
||||||
int k;
|
|
||||||
for (k = 0; k != MAXKEYWORDS; ++k) {
|
|
||||||
if (strcmp(keywords[k], (const char *)propName) == 0) {
|
|
||||||
enable_keyword(k, false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (k == MAXKEYWORDS) {
|
|
||||||
log_error("trying to disable unknown command %s\n", (const char *)propName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlFree(propName);
|
|
||||||
}
|
|
||||||
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
/* reading eressea/game/skill */
|
/* reading eressea/game/skill */
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "skill", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "skill", xpath);
|
||||||
nodes = result->nodesetval;
|
nodes = result->nodesetval;
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include "keyword.h"
|
#include "keyword.h"
|
||||||
|
|
||||||
#include "util/language.h"
|
#include <util/language.h>
|
||||||
#include "util/umlaut.h"
|
#include <util/umlaut.h>
|
||||||
|
#include <util/log.h>
|
||||||
|
|
||||||
#include <critbit.h>
|
#include <critbit.h>
|
||||||
|
|
||||||
|
@ -73,6 +74,20 @@ keyword_t get_keyword(const char *s, const struct locale *lang) {
|
||||||
|
|
||||||
static bool disabled_kwd[MAXKEYWORDS];
|
static bool disabled_kwd[MAXKEYWORDS];
|
||||||
|
|
||||||
|
void disable_keyword_str(const char *str) {
|
||||||
|
// FIXME: this is slower than balls.
|
||||||
|
int k;
|
||||||
|
for (k = 0; k != MAXKEYWORDS; ++k) {
|
||||||
|
if (strcmp(keywords[k], str) == 0) {
|
||||||
|
enable_keyword(k, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (k == MAXKEYWORDS) {
|
||||||
|
log_error("trying to disable unknown command %s\n", str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void enable_keyword(keyword_t kwd, bool enabled) {
|
void enable_keyword(keyword_t kwd, bool enabled) {
|
||||||
assert(kwd < MAXKEYWORDS);
|
assert(kwd < MAXKEYWORDS);
|
||||||
disabled_kwd[kwd] = !enabled;
|
disabled_kwd[kwd] = !enabled;
|
||||||
|
|
|
@ -81,6 +81,7 @@ extern "C"
|
||||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||||
bool keyword_disabled(keyword_t kwd);
|
bool keyword_disabled(keyword_t kwd);
|
||||||
void enable_keyword(keyword_t kwd, bool enabled);
|
void enable_keyword(keyword_t kwd, bool enabled);
|
||||||
|
void disable_keyword_str(const char *str);
|
||||||
const char *keyword(keyword_t kwd);
|
const char *keyword(keyword_t kwd);
|
||||||
// #define keyword(kwd) mkname("keyword", keywords[kwd])
|
// #define keyword(kwd) mkname("keyword", keywords[kwd])
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,8 @@ struct unit *test_create_unit(struct faction *f, struct region *r)
|
||||||
|
|
||||||
void test_cleanup(void)
|
void test_cleanup(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
free_terrains();
|
free_terrains();
|
||||||
free_resources();
|
free_resources();
|
||||||
global.functions.maintenance = NULL;
|
global.functions.maintenance = NULL;
|
||||||
|
@ -87,6 +89,9 @@ void test_cleanup(void)
|
||||||
free_seen();
|
free_seen();
|
||||||
free_prefixes();
|
free_prefixes();
|
||||||
mt_clear();
|
mt_clear();
|
||||||
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
||||||
|
enable_keyword(i, true);
|
||||||
|
}
|
||||||
if (!mt_find("missing_message")) {
|
if (!mt_find("missing_message")) {
|
||||||
mt_register(mt_new_va("missing_message", "name:string", 0));
|
mt_register(mt_new_va("missing_message", "name:string", 0));
|
||||||
mt_register(mt_new_va("missing_feedback", "unit:unit", "region:region", "command:order", "name:string", 0));
|
mt_register(mt_new_va("missing_feedback", "unit:unit", "region:region", "command:order", "name:string", 0));
|
||||||
|
|
Loading…
Reference in New Issue