From 230e47c0eaae5eabf2db7bf1b5d0c4e541cd97be Mon Sep 17 00:00:00 2001 From: kevinz000 <2003111+kevinz000@users.noreply.github.com> Date: Fri, 10 Aug 2018 12:44:14 -0700 Subject: [PATCH] Configuration entry refactor! (#39608) * Config entry refactor * Fixes * Update configuration.dm --- .../controllers/configuration/config_entry.dm | 18 +++++++---- .../configuration/configuration.dm | 30 ++++++++++++++----- code/modules/admin/admin_verbs.dm | 3 +- code/modules/admin/verbs/debug.dm | 9 ++++++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/code/controllers/configuration/config_entry.dm b/code/controllers/configuration/config_entry.dm index 5314cf19b91..49ff1c8d498 100644 --- a/code/controllers/configuration/config_entry.dm +++ b/code/controllers/configuration/config_entry.dm @@ -18,6 +18,8 @@ var/protection = NONE var/abstract_type = /datum/config_entry //do not instantiate if type matches this + var/vv_VAS = TRUE //Force validate and set on VV. VAS proccall guard will run regardless. + var/dupes_allowed = FALSE /datum/config_entry/New() @@ -40,20 +42,23 @@ . &= !(protection & CONFIG_ENTRY_HIDDEN) /datum/config_entry/vv_edit_var(var_name, var_value) - var/static/list/banned_edits = list(NAMEOF(src, name), NAMEOF(src, default), NAMEOF(src, resident_file), NAMEOF(src, protection), NAMEOF(src, abstract_type), NAMEOF(src, modified), NAMEOF(src, dupes_allowed)) + var/static/list/banned_edits = list(NAMEOF(src, name), NAMEOF(src, vv_VAS), NAMEOF(src, default), NAMEOF(src, resident_file), NAMEOF(src, protection), NAMEOF(src, abstract_type), NAMEOF(src, modified), NAMEOF(src, dupes_allowed)) if(var_name == NAMEOF(src, config_entry_value)) if(protection & CONFIG_ENTRY_LOCKED) return FALSE - . = ValidateAndSet("[var_value]") - if(.) - datum_flags |= DF_VAR_EDITED - return + if(vv_VAS) + . = ValidateAndSet("[var_value]") + if(.) + datum_flags |= DF_VAR_EDITED + return + else + return ..() if(var_name in banned_edits) return FALSE return ..() /datum/config_entry/proc/VASProcCallGuard(str_val) - . = !(IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "ValidateAndSet" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") + . = !((protection & CONFIG_ENTRY_LOCKED) && IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "ValidateAndSet" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") if(!.) log_admin_private("Config set of [type] to [str_val] attempted by [key_name(usr)]") @@ -137,6 +142,7 @@ abstract_type = /datum/config_entry/keyed_list config_entry_value = list() dupes_allowed = TRUE + vv_VAS = FALSE //VAS will not allow things like deleting from lists, it'll just bug horribly. var/key_mode var/value_mode var/splitter = " " diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm index 2b1790c7f8c..0232081c1ac 100644 --- a/code/controllers/configuration/configuration.dm +++ b/code/controllers/configuration/configuration.dm @@ -20,7 +20,17 @@ var/motd +/datum/controller/configuration/proc/admin_reload() + if(IsAdminAdvancedProcCall()) + return + log_admin("[key_name_admin(usr)] has forcefully reloaded the configuration from disk.") + message_admins("[key_name_admin(usr)] has forcefully reloaded the configuration from disk.") + full_wipe() + Load(world.params[OVERRIDE_CONFIG_DIRECTORY_PARAMETER]) + /datum/controller/configuration/proc/Load(_directory) + if(IsAdminAdvancedProcCall()) //If admin proccall is detected down the line it will horribly break everything. + return if(_directory) directory = _directory if(entries) @@ -38,12 +48,18 @@ loadmaplist(CONFIG_MAPS_FILE) LoadMOTD() -/datum/controller/configuration/Destroy() +/datum/controller/configuration/proc/full_wipe() + if(IsAdminAdvancedProcCall()) + return entries_by_type.Cut() QDEL_LIST_ASSOC_VAL(entries) + entries = null QDEL_LIST_ASSOC_VAL(maplist) + maplist = null QDEL_NULL(defaultmap) +/datum/controller/configuration/Destroy() + full_wipe() config = null return ..() @@ -168,9 +184,6 @@ stat("[name]:", statclick) /datum/controller/configuration/proc/Get(entry_type) - if(IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "Get" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") - log_admin_private("Config access of [entry_type] attempted by [key_name(usr)]") - return var/datum/config_entry/E = entry_type var/entry_is_abstract = initial(E.abstract_type) == entry_type if(entry_is_abstract) @@ -178,12 +191,12 @@ E = entries_by_type[entry_type] if(!E) CRASH("Missing config entry for [entry_type]!") + if((E.protection & CONFIG_ENTRY_HIDDEN) && IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "Get" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") + log_admin_private("Config access of [entry_type] attempted by [key_name(usr)]") + return return E.config_entry_value /datum/controller/configuration/proc/Set(entry_type, new_val) - if(IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "Set" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") - log_admin_private("Config rewrite of [entry_type] to [new_val] attempted by [key_name(usr)]") - return var/datum/config_entry/E = entry_type var/entry_is_abstract = initial(E.abstract_type) == entry_type if(entry_is_abstract) @@ -191,6 +204,9 @@ E = entries_by_type[entry_type] if(!E) CRASH("Missing config entry for [entry_type]!") + if((E.protection & CONFIG_ENTRY_LOCKED) && IsAdminAdvancedProcCall() && GLOB.LastAdminCalledProc == "Set" && GLOB.LastAdminCalledTargetRef == "[REF(src)]") + log_admin_private("Config rewrite of [entry_type] to [new_val] attempted by [key_name(usr)]") + return return E.ValidateAndSet("[new_val]") /datum/controller/configuration/proc/LoadModes() diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 7ba3e699d4e..3ccf7e6e79b 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -158,6 +158,7 @@ GLOBAL_LIST_INIT(admin_verbs_debug, world.AVerbsDebug()) /client/proc/pump_random_event, /client/proc/cmd_display_init_log, /client/proc/cmd_display_overlay_log, + /client/proc/reload_configuration, /datum/admins/proc/create_or_modify_area, ) GLOBAL_PROTECT(admin_verbs_possess) @@ -181,7 +182,7 @@ GLOBAL_LIST_INIT(admin_verbs_hideable, list( /client/proc/admin_ghost, /client/proc/toggle_view_range, /client/proc/cmd_admin_subtle_message, - /client/proc/cmd_admin_headset_message, + /client/proc/cmd_admin_headset_message, /client/proc/cmd_admin_check_contents, /datum/admins/proc/access_news_network, /client/proc/admin_call_shuttle, diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index 87008704705..67b33afcc6f 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -1091,3 +1091,12 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) return sort = sortlist[sort] profile_show(src, sort) + +/client/proc/reload_configuration() + set category = "Debug" + set name = "Reload Configuration" + set desc = "Force config reload to world default" + if(!check_rights(R_DEBUG)) + return + if(alert(usr, "Are you absolutely sure you want to reload the configuration from the default path on the disk, wiping any in-round modificatoins?", "Really reset?", "No", "Yes") == "Yes") + config.admin_reload()