From e5919a112b0717a6d416f461d58837542c25c7b2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 12 Mar 2022 22:59:18 +0200 Subject: [PATCH 45/45] Fix metamessage resetting on ruleset load User (or the public server environment) set metamessage should not get cleared when the ruleset gets loaded. It was, like any other server setting. See osdn #43759 Signed-off-by: Marko Lindqvist --- server/settings.c | 56 +++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/server/settings.c b/server/settings.c index 45629d9ecc..2757c5f837 100644 --- a/server/settings.c +++ b/server/settings.c @@ -171,6 +171,8 @@ struct setting { /* ruleset lock for game settings */ bool locked; + bool ruleset_settable; + /* It's not "default", even if value is the same as default */ enum setting_default_level setdef; enum setting_default_level game_setdef; @@ -1302,7 +1304,7 @@ static bool plrcol_validate(int value, struct connection *caller, scateg, slevel, \ INIT_BRACE_BEGIN \ .boolean = {&value, _default, func_validate, bool_name, \ - FALSE} INIT_BRACE_END , func_action, FALSE}, + FALSE} INIT_BRACE_END , func_action, FALSE, TRUE}, #define GEN_INT(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_help, \ @@ -1313,7 +1315,7 @@ static bool plrcol_validate(int value, struct connection *caller, INIT_BRACE_BEGIN \ .integer = {(int *) &value, _default, _min, _max, func_validate, \ 0} INIT_BRACE_END, \ - func_action, FALSE}, + func_action, FALSE, TRUE}, #define GEN_STRING(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_validate, func_action, \ @@ -1323,7 +1325,17 @@ static bool plrcol_validate(int value, struct connection *caller, INIT_BRACE_BEGIN \ .string = {value, _default, sizeof(value), func_validate, ""} \ INIT_BRACE_END, \ - func_action, FALSE}, + func_action, FALSE, TRUE}, + +#define GEN_STRING_NRS(name, value, sclass, scateg, slevel, al_read, al_write, \ + short_help, extra_help, func_validate, func_action, \ + _default) \ + {name, sclass, al_read, al_write, short_help, extra_help, NULL, \ + SST_STRING, scateg, slevel, \ + INIT_BRACE_BEGIN \ + .string = {value, _default, sizeof(value), func_validate, ""} \ + INIT_BRACE_END, \ + func_action, FALSE, FALSE}, #define GEN_ENUM(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_help, func_validate, \ @@ -1334,7 +1346,7 @@ static bool plrcol_validate(int value, struct connection *caller, .enumerator = { &value, sizeof(value), _default, \ func_validate, \ (val_name_func_t) func_name, 0 } INIT_BRACE_END, \ - func_action, FALSE}, + func_action, FALSE, TRUE}, #define GEN_BITWISE(name, value, sclass, scateg, slevel, al_read, al_write, \ short_help, extra_help, func_validate, func_action, \ @@ -1344,7 +1356,7 @@ static bool plrcol_validate(int value, struct connection *caller, INIT_BRACE_BEGIN \ .bitwise = { (unsigned *) (void *) &value, _default, func_validate, \ func_name, 0 } INIT_BRACE_END, \ - func_action, FALSE}, + func_action, FALSE, TRUE}, /* game settings */ static struct setting settings[] = { @@ -3075,15 +3087,15 @@ static struct setting settings[] = { "affect users kicked in the past."), NULL, NULL, NULL, GAME_MIN_KICK_TIME, GAME_MAX_KICK_TIME, GAME_DEFAULT_KICK_TIME) - GEN_STRING("metamessage", game.server.meta_info.user_message, - SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_CTRL, ALLOW_CTRL, - N_("Metaserver info line"), - N_("User defined metaserver info line. For most of the time " - "a user defined metamessage will be used instead of an " - "automatically generated message. " - "Set to empty (\"\", not \"empty\") to always use an " - "automatically generated meta server message."), - NULL, metamessage_action, GAME_DEFAULT_USER_META_MESSAGE) + GEN_STRING_NRS("metamessage", game.server.meta_info.user_message, + SSET_META, SSET_INTERNAL, SSET_RARE, ALLOW_CTRL, ALLOW_CTRL, + N_("Metaserver info line"), + N_("User defined metaserver info line. For most of the time " + "a user defined metamessage will be used instead of an " + "automatically generated message. " + "Set to empty (\"\", not \"empty\") to always use an " + "automatically generated meta server message."), + NULL, metamessage_action, GAME_DEFAULT_USER_META_MESSAGE) }; #undef GEN_BOOL @@ -4165,7 +4177,9 @@ bool settings_ruleset(struct section_file *file, const char *section, /* Unlock all settings. */ settings_iterate(SSET_ALL, pset) { setting_lock_set(pset, FALSE); - setting_set_to_default(pset); + if (pset->ruleset_settable) { + setting_set_to_default(pset); + } } settings_iterate_end; /* settings */ @@ -4177,6 +4191,7 @@ bool settings_ruleset(struct section_file *file, const char *section, for (j = 0; (name = secfile_lookup_str_default(file, NULL, "%s.set%d.name", section, j)); j++) { char path[256]; + fc_snprintf(path, sizeof(path), "%s.set%d", section, j); if (compat) { @@ -4184,7 +4199,8 @@ bool settings_ruleset(struct section_file *file, const char *section, } if (!setting_ruleset_one(file, name, path, compat)) { - log_error("unknown setting in '%s': %s", secfile_name(file), name); + log_error("unknown unsettable setting in '%s': %s", + secfile_name(file), name); } } } @@ -4193,7 +4209,9 @@ bool settings_ruleset(struct section_file *file, const char *section, * default values. */ if (act) { settings_iterate(SSET_ALL, pset) { - setting_action(pset); + if (pset->ruleset_settable) { + setting_action(pset); + } } settings_iterate_end; } @@ -4223,8 +4241,8 @@ static bool setting_ruleset_one(struct section_file *file, } } settings_iterate_end; - if (pset == NULL) { - /* no setting found */ + if (pset == NULL || !pset->ruleset_settable) { + /* No setting found or it's not settable by ruleset */ return FALSE; } -- 2.35.1