From 3cae82ae71ffb1573dc6152e8edb4406b2bb5a5f Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 12 Mar 2022 22:53:21 +0200 Subject: [PATCH 23/23] 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 42dd903c30..f004ad01fe 100644 --- a/server/settings.c +++ b/server/settings.c @@ -170,6 +170,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; }; @@ -1294,7 +1296,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, \ @@ -1305,7 +1307,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, \ @@ -1315,7 +1317,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, \ @@ -1326,7 +1338,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, \ @@ -1336,7 +1348,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[] = { @@ -3026,15 +3038,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 @@ -4105,7 +4117,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 */ @@ -4117,10 +4131,12 @@ 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 (!setting_ruleset_one(file, name, path)) { - log_error("unknown setting in '%s': %s", secfile_name(file), name); + log_error("Unknown unsettable setting in '%s': %s", + secfile_name(file), name); } } } @@ -4129,7 +4145,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; } @@ -4158,8 +4176,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