From 2a5634858d28624b406342f39e429d483f01d072 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Thu, 15 Dec 2022 23:35:53 +0200 Subject: [PATCH 39/39] Client: Use setdef to decide whether store server setting Replace old check if the settings current value matches internal default with check if it's supposed to be some kind of default. This means: - Ruleset defaults are no longer saved as "non-default" - Value explicitly set to same as the default gets saved See osdn #43748 Signed-off-by: Marko Lindqvist --- client/options.c | 91 ++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/client/options.c b/client/options.c index 53e6d94c69..c80543a7c7 100644 --- a/client/options.c +++ b/client/options.c @@ -5417,55 +5417,56 @@ void desired_settable_options_update(void) fc_assert_ret(NULL != settable_options_hash); options_iterate(server_optset, poption) { - value = NULL; - def_val = NULL; - switch (option_type(poption)) { - case OT_BOOLEAN: - fc_strlcpy(val_buf, option_bool_get(poption) ? "enabled" : "disabled", - sizeof(val_buf)); - value = val_buf; - fc_strlcpy(def_buf, option_bool_def(poption) ? "enabled" : "disabled", - sizeof(def_buf)); - def_val = def_buf; - break; - case OT_INTEGER: - fc_snprintf(val_buf, sizeof(val_buf), "%d", option_int_get(poption)); - value = val_buf; - fc_snprintf(def_buf, sizeof(def_buf), "%d", option_int_def(poption)); - def_val = def_buf; - break; - case OT_STRING: - value = option_str_get(poption); - def_val = option_str_def(poption); - break; - case OT_ENUM: - server_option_enum_support_name(poption, &value, &def_val); - break; - case OT_BITWISE: - server_option_bitwise_support_name(poption, val_buf, sizeof(val_buf), - def_buf, sizeof(def_buf)); - value = val_buf; - def_val = def_buf; - break; - case OT_FONT: - case OT_COLOR: - case OT_VIDEO_MODE: - break; - } - - if (NULL == value || NULL == def_val) { - log_error("Option type %s (%d) not supported for '%s'.", - option_type_name(option_type(poption)), option_type(poption), - option_name(poption)); - continue; - } + struct server_option *srv = SERVER_OPTION(poption); - if (0 == strcmp(value, def_val)) { - /* Not set, using default... */ + if (srv->setdef != SETDEF_CHANGED) { + /* Some level default - do not store */ settable_options_hash_remove(settable_options_hash, option_name(poption)); } else { - /* Really desired. */ + value = NULL; + def_val = NULL; + switch (option_type(poption)) { + case OT_BOOLEAN: + fc_strlcpy(val_buf, option_bool_get(poption) ? "enabled" : "disabled", + sizeof(val_buf)); + value = val_buf; + fc_strlcpy(def_buf, option_bool_def(poption) ? "enabled" : "disabled", + sizeof(def_buf)); + def_val = def_buf; + break; + case OT_INTEGER: + fc_snprintf(val_buf, sizeof(val_buf), "%d", option_int_get(poption)); + value = val_buf; + fc_snprintf(def_buf, sizeof(def_buf), "%d", option_int_def(poption)); + def_val = def_buf; + break; + case OT_STRING: + value = option_str_get(poption); + def_val = option_str_def(poption); + break; + case OT_ENUM: + server_option_enum_support_name(poption, &value, &def_val); + break; + case OT_BITWISE: + server_option_bitwise_support_name(poption, val_buf, sizeof(val_buf), + def_buf, sizeof(def_buf)); + value = val_buf; + def_val = def_buf; + break; + case OT_FONT: + case OT_COLOR: + case OT_VIDEO_MODE: + break; + } + + if (NULL == value || NULL == def_val) { + log_error("Option type %s (%d) not supported for '%s'.", + option_type_name(option_type(poption)), option_type(poption), + option_name(poption)); + continue; + } + settable_options_hash_replace(settable_options_hash, option_name(poption), value); } -- 2.35.1