forked from github/server
bug 2291: json settings must not override eressea.ini.
https://bugs.eressea.de/view.php?id=2291
This commit is contained in:
parent
7f03417c37
commit
912a8b5412
|
@ -797,18 +797,18 @@ static void json_settings(cJSON *json) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
|
if (config_get(child->string) == NULL) {
|
||||||
if (child->valuestring) {
|
if (child->valuestring) {
|
||||||
config_set(child->string, child->valuestring);
|
config_set(child->string, child->valuestring);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char value[32];
|
char value[32];
|
||||||
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
|
if (child->type == cJSON_Number && child->valuedouble && child->valueint < child->valuedouble) {
|
||||||
sprintf(value, "%f", child->valuedouble);
|
sprintf(value, "%f", child->valuedouble);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf(value, "%d", child->valueint);
|
sprintf(value, "%d", child->valueint);
|
||||||
}
|
}
|
||||||
if (config_get(child->string) == NULL) {
|
|
||||||
config_set(child->string, value);
|
config_set(child->string, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,14 +70,17 @@ static void test_settings(CuTest * tc)
|
||||||
"\"integer\" : 14,"
|
"\"integer\" : 14,"
|
||||||
"\"true\": true,"
|
"\"true\": true,"
|
||||||
"\"game.id\": 4,"
|
"\"game.id\": 4,"
|
||||||
|
"\"game.name\": \"E3\","
|
||||||
"\"false\": false,"
|
"\"false\": false,"
|
||||||
"\"float\" : 1.5 }}";
|
"\"float\" : 1.5 }}";
|
||||||
cJSON *json = cJSON_Parse(data);
|
cJSON *json = cJSON_Parse(data);
|
||||||
|
|
||||||
test_cleanup();
|
test_cleanup();
|
||||||
config_set("game.id", "42"); /* should not be replaced */
|
config_set("game.id", "42"); /* should not be replaced */
|
||||||
|
config_set("game.name", "Eressea"); /* should not be replaced */
|
||||||
json_config(json);
|
json_config(json);
|
||||||
CuAssertStrEquals(tc, "42", config_get("game.id"));
|
CuAssertStrEquals(tc, "42", config_get("game.id"));
|
||||||
|
CuAssertStrEquals(tc, "Eressea", config_get("game.name"));
|
||||||
CuAssertStrEquals(tc, "1", config_get("true"));
|
CuAssertStrEquals(tc, "1", config_get("true"));
|
||||||
CuAssertStrEquals(tc, "0", config_get("false"));
|
CuAssertStrEquals(tc, "0", config_get("false"));
|
||||||
CuAssertStrEquals(tc, "1d4", config_get("string"));
|
CuAssertStrEquals(tc, "1d4", config_get("string"));
|
||||||
|
|
Loading…
Reference in New Issue