forked from github/server
Merge pull request #298 from ennorehling/feature/json-disable-skills
disable everything from JSON, not XML
This commit is contained in:
commit
a35ed82f43
|
@ -4,8 +4,9 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e2/terrains.json"
|
"e2/terrains.json"
|
||||||
],
|
],
|
||||||
"disable": [
|
"disabled": [
|
||||||
"pay"
|
"pay",
|
||||||
|
"jsreport"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 2,
|
"game.id": 2,
|
||||||
|
|
|
@ -52,38 +52,6 @@
|
||||||
<xi:include href="config://default/names-zombies.xml"/>
|
<xi:include href="config://default/names-zombies.xml"/>
|
||||||
<xi:include href="config://default/names-ghouls.xml"/>
|
<xi:include href="config://default/names-ghouls.xml"/>
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
|
||||||
<skill name="alchemy" enable="true"/>
|
|
||||||
<skill name="crossbow" enable="true"/>
|
|
||||||
<skill name="mining" enable="true"/>
|
|
||||||
<skill name="bow" enable="true"/>
|
|
||||||
<skill name="building" enable="true"/>
|
|
||||||
<skill name="trade" enable="true"/>
|
|
||||||
<skill name="forestry" enable="true"/>
|
|
||||||
<skill name="catapult" enable="true"/>
|
|
||||||
<skill name="herbalism" enable="true"/>
|
|
||||||
<skill name="magic" enable="true"/>
|
|
||||||
<skill name="training" enable="true"/>
|
|
||||||
<skill name="riding" enable="true"/>
|
|
||||||
<skill name="armorer" enable="true"/>
|
|
||||||
<skill name="shipcraft" enable="true"/>
|
|
||||||
<skill name="melee" enable="true"/>
|
|
||||||
<skill name="sailing" enable="true"/>
|
|
||||||
<skill name="polearm" enable="true"/>
|
|
||||||
<skill name="espionage" enable="true"/>
|
|
||||||
<skill name="quarrying" enable="true"/>
|
|
||||||
<skill name="roadwork" enable="true"/>
|
|
||||||
<skill name="tactics" enable="true"/>
|
|
||||||
<skill name="stealth" enable="true"/>
|
|
||||||
<skill name="entertainment" enable="true"/>
|
|
||||||
<skill name="weaponsmithing" enable="true"/>
|
|
||||||
<skill name="cartmaking" enable="true"/>
|
|
||||||
<skill name="perception" enable="true"/>
|
|
||||||
<skill name="taxation" enable="true"/>
|
|
||||||
<skill name="stamina" enable="true"/>
|
|
||||||
<skill name="unarmed" enable="true"/>
|
|
||||||
</game>
|
|
||||||
<strings>
|
<strings>
|
||||||
<string name="mailto">
|
<string name="mailto">
|
||||||
<text locale="de">eressea-server@eressea.de</text>
|
<text locale="de">eressea-server@eressea.de</text>
|
||||||
|
|
|
@ -4,7 +4,15 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e3/terrains.json"
|
"e3/terrains.json"
|
||||||
],
|
],
|
||||||
"disable": [
|
"disabled": [
|
||||||
|
"herbalism",
|
||||||
|
"alchemy",
|
||||||
|
"entertainment",
|
||||||
|
"espionage",
|
||||||
|
"perception",
|
||||||
|
"stealth",
|
||||||
|
"taxation",
|
||||||
|
"trade",
|
||||||
"besiege",
|
"besiege",
|
||||||
"steal",
|
"steal",
|
||||||
"buy",
|
"buy",
|
||||||
|
@ -13,7 +21,8 @@
|
||||||
"spy",
|
"spy",
|
||||||
"tax",
|
"tax",
|
||||||
"entertain",
|
"entertain",
|
||||||
"sell"
|
"sell",
|
||||||
|
"jsreport"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 3,
|
"game.id": 3,
|
||||||
|
|
|
@ -41,40 +41,6 @@
|
||||||
<xi:include href="config://default/names-zombies.xml"/>
|
<xi:include href="config://default/names-zombies.xml"/>
|
||||||
<xi:include href="config://default/names-ghouls.xml"/>
|
<xi:include href="config://default/names-ghouls.xml"/>
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
|
||||||
<skill name="armorer" enable="true"/>
|
|
||||||
<skill name="bow" enable="true"/>
|
|
||||||
<skill name="building" enable="true"/>
|
|
||||||
<skill name="cartmaking" enable="true"/>
|
|
||||||
<skill name="catapult" enable="true"/>
|
|
||||||
<skill name="crossbow" enable="true"/>
|
|
||||||
<skill name="forestry" enable="true"/>
|
|
||||||
<skill name="magic" enable="true"/>
|
|
||||||
<skill name="melee" enable="true"/>
|
|
||||||
<skill name="mining" enable="true"/>
|
|
||||||
<skill name="polearm" enable="true"/>
|
|
||||||
<skill name="quarrying" enable="true"/>
|
|
||||||
<skill name="riding" enable="true"/>
|
|
||||||
<skill name="roadwork" enable="true"/>
|
|
||||||
<skill name="sailing" enable="true"/>
|
|
||||||
<skill name="shipcraft" enable="true"/>
|
|
||||||
<skill name="stamina" enable="true"/>
|
|
||||||
<skill name="tactics" enable="true"/>
|
|
||||||
<skill name="training" enable="true"/>
|
|
||||||
<skill name="unarmed" enable="true"/>
|
|
||||||
<skill name="weaponsmithing" enable="true"/>
|
|
||||||
|
|
||||||
<skill name="herbalism" enable="false"/>
|
|
||||||
|
|
||||||
<skill name="alchemy" enable="false"/>
|
|
||||||
<skill name="entertainment" enable="false"/>
|
|
||||||
<skill name="espionage" enable="false"/>
|
|
||||||
<skill name="perception" enable="false"/>
|
|
||||||
<skill name="stealth" enable="false"/>
|
|
||||||
<skill name="taxation" enable="false"/>
|
|
||||||
<skill name="trade" enable="false"/>
|
|
||||||
</game>
|
|
||||||
<rules>
|
<rules>
|
||||||
<function name="wage" value="minimum_wage"/>
|
<function name="wage" value="minimum_wage"/>
|
||||||
</rules>
|
</rules>
|
||||||
|
|
|
@ -4,7 +4,15 @@
|
||||||
"prefixes.json",
|
"prefixes.json",
|
||||||
"e3/terrains.json"
|
"e3/terrains.json"
|
||||||
],
|
],
|
||||||
"disable": [
|
"disabled": [
|
||||||
|
"herbalism",
|
||||||
|
"alchemy",
|
||||||
|
"entertainment",
|
||||||
|
"espionage",
|
||||||
|
"perception",
|
||||||
|
"stealth",
|
||||||
|
"taxation",
|
||||||
|
"trade",
|
||||||
"besiege",
|
"besiege",
|
||||||
"steal",
|
"steal",
|
||||||
"buy",
|
"buy",
|
||||||
|
@ -13,7 +21,8 @@
|
||||||
"spy",
|
"spy",
|
||||||
"tax",
|
"tax",
|
||||||
"entertain",
|
"entertain",
|
||||||
"sell"
|
"sell",
|
||||||
|
"jsreport"
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
"game.id": 4,
|
"game.id": 4,
|
||||||
|
|
|
@ -42,39 +42,6 @@
|
||||||
<xi:include href="config://default/names-ghouls.xml"/>
|
<xi:include href="config://default/names-ghouls.xml"/>
|
||||||
<xi:include href="config://default/names-dragons.xml"/>
|
<xi:include href="config://default/names-dragons.xml"/>
|
||||||
|
|
||||||
<game>
|
|
||||||
<skill name="armorer" enable="true"/>
|
|
||||||
<skill name="bow" enable="true"/>
|
|
||||||
<skill name="building" enable="true"/>
|
|
||||||
<skill name="cartmaking" enable="true"/>
|
|
||||||
<skill name="catapult" enable="true"/>
|
|
||||||
<skill name="crossbow" enable="true"/>
|
|
||||||
<skill name="forestry" enable="true"/>
|
|
||||||
<skill name="magic" enable="true"/>
|
|
||||||
<skill name="melee" enable="true"/>
|
|
||||||
<skill name="mining" enable="true"/>
|
|
||||||
<skill name="polearm" enable="true"/>
|
|
||||||
<skill name="quarrying" enable="true"/>
|
|
||||||
<skill name="riding" enable="true"/>
|
|
||||||
<skill name="roadwork" enable="true"/>
|
|
||||||
<skill name="sailing" enable="true"/>
|
|
||||||
<skill name="shipcraft" enable="true"/>
|
|
||||||
<skill name="stamina" enable="true"/>
|
|
||||||
<skill name="tactics" enable="true"/>
|
|
||||||
<skill name="training" enable="true"/>
|
|
||||||
<skill name="unarmed" enable="true"/>
|
|
||||||
<skill name="weaponsmithing" enable="true"/>
|
|
||||||
|
|
||||||
<skill name="herbalism" enable="false"/>
|
|
||||||
|
|
||||||
<skill name="alchemy" enable="false"/>
|
|
||||||
<skill name="entertainment" enable="false"/>
|
|
||||||
<skill name="espionage" enable="false"/>
|
|
||||||
<skill name="perception" enable="false"/>
|
|
||||||
<skill name="stealth" enable="false"/>
|
|
||||||
<skill name="taxation" enable="false"/>
|
|
||||||
<skill name="trade" enable="false"/>
|
|
||||||
</game>
|
|
||||||
<rules>
|
<rules>
|
||||||
<function name="wage" value="minimum_wage"/>
|
<function name="wage" value="minimum_wage"/>
|
||||||
</rules>
|
</rules>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
local pkg = {}
|
local pkg = {}
|
||||||
|
|
||||||
function pkg.init()
|
function pkg.init()
|
||||||
eressea.settings.set("feature.jsreport.enable", "1")
|
eressea.settings.set("jsreport.enabled", "1")
|
||||||
end
|
end
|
||||||
|
|
||||||
function pkg.update()
|
function pkg.update()
|
||||||
|
|
|
@ -25,7 +25,7 @@ static void coor_from_tiled(int *x, int *y) {
|
||||||
|
|
||||||
static int report_json(const char *filename, report_context * ctx, const char *charset)
|
static int report_json(const char *filename, report_context * ctx, const char *charset)
|
||||||
{
|
{
|
||||||
if (get_param_int(global.parameters, "feature.jsreport.enable", 0) != 0) {
|
if (get_param_int(global.parameters, "jsreport.enabled", 0) != 0) {
|
||||||
FILE * F = fopen(filename, "w");
|
FILE * F = fopen(filename, "w");
|
||||||
if (F) {
|
if (F) {
|
||||||
int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
|
int x, y, minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
|
||||||
|
|
|
@ -501,14 +501,42 @@ static void json_prefixes(cJSON *json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void json_disable_keywords(cJSON *json) {
|
/** disable a feature.
|
||||||
|
* features are identified by eone of:
|
||||||
|
* 1. the keyword for their orders,
|
||||||
|
* 2. the name of the skill they use,
|
||||||
|
* 3. a "module.enabled" flag in the settings
|
||||||
|
*/
|
||||||
|
static void disable_feature(const char *str) {
|
||||||
|
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);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_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) {
|
||||||
cJSON *child;
|
cJSON *child;
|
||||||
if (json->type != cJSON_Array) {
|
if (json->type != cJSON_Array) {
|
||||||
log_error("disable is not a json array: %d", json->type);
|
log_error("disabled is not a json array: %d", json->type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
disable_keyword_str(child->valuestring);
|
disable_feature(child->valuestring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -865,8 +893,8 @@ 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) {
|
else if (strcmp(child->string, "disabled") == 0) {
|
||||||
json_disable_keywords(child);
|
json_disable_features(child);
|
||||||
}
|
}
|
||||||
else if (strcmp(child->string, "terrains") == 0) {
|
else if (strcmp(child->string, "terrains") == 0) {
|
||||||
json_terrains(child);
|
json_terrains(child);
|
||||||
|
|
|
@ -101,20 +101,26 @@ static void test_prefixes(CuTest * tc)
|
||||||
|
|
||||||
static void test_disable(CuTest * tc)
|
static void test_disable(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char * data = "{\"disable\": [ "
|
const char * data = "{\"disabled\": [ "
|
||||||
|
"\"alchemy\","
|
||||||
"\"pay\","
|
"\"pay\","
|
||||||
"\"besiege\""
|
"\"besiege\","
|
||||||
|
"\"module\""
|
||||||
"]}";
|
"]}";
|
||||||
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));
|
||||||
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));
|
||||||
|
CuAssertIntEquals(tc, 0, get_param_int(global.parameters, "module.enabled", 1));
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2052,44 +2052,8 @@ static int parse_strings(xmlDocPtr doc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_main(xmlDocPtr doc)
|
|
||||||
{
|
|
||||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
|
||||||
xmlXPathObjectPtr result =
|
|
||||||
xmlXPathEvalExpression(BAD_CAST "/eressea/game", xpath);
|
|
||||||
xmlNodeSetPtr nodes = result->nodesetval;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (nodes->nodeNr > 0) {
|
|
||||||
xmlNodePtr node = nodes->nodeTab[0];
|
|
||||||
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
xpath->node = node;
|
|
||||||
/* reading eressea/game/skill */
|
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "skill", xpath);
|
|
||||||
nodes = result->nodesetval;
|
|
||||||
for (i = 0; i != nodes->nodeNr; ++i) {
|
|
||||||
xmlNodePtr node = nodes->nodeTab[i];
|
|
||||||
xmlChar *propName = xmlGetProp(node, BAD_CAST "name");
|
|
||||||
skill_t sk = findskill((const char *)propName);
|
|
||||||
if (sk != NOSKILL) {
|
|
||||||
bool enable = xml_bvalue(node, "enable", true);
|
|
||||||
enable_skill(sk, enable);
|
|
||||||
}
|
|
||||||
xmlFree(propName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
xmlXPathFreeObject(result);
|
|
||||||
|
|
||||||
xmlXPathFreeContext(xpath);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void register_xmlreader(void)
|
void register_xmlreader(void)
|
||||||
{
|
{
|
||||||
xml_register_callback(parse_main);
|
|
||||||
|
|
||||||
xml_register_callback(parse_strings);
|
xml_register_callback(parse_strings);
|
||||||
xml_register_callback(parse_messages);
|
xml_register_callback(parse_messages);
|
||||||
xml_register_callback(parse_resources);
|
xml_register_callback(parse_resources);
|
||||||
|
|
|
@ -74,20 +74,6 @@ 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,7 +81,6 @@ 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])
|
||||||
|
|
||||||
|
|
|
@ -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