Controllers

This commit is contained in:
Poojawa
2018-09-11 02:04:10 -05:00
parent 07cb9572bd
commit 09512a6001
37 changed files with 522 additions and 447 deletions
+63 -66
View File
@@ -1,6 +1,9 @@
#define LIST_MODE_NUM 0
#define LIST_MODE_TEXT 1
#define LIST_MODE_FLAG 2
#define VALUE_MODE_NUM 0
#define VALUE_MODE_TEXT 1
#define VALUE_MODE_FLAG 2
#define KEY_MODE_TEXT 0
#define KEY_MODE_TYPE 1
/datum/config_entry
var/name //read-only, this is determined by the last portion of the derived entry type
@@ -15,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()
@@ -37,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)]")
@@ -58,32 +66,6 @@
VASProcCallGuard(str_val)
CRASH("Invalid config entry type!")
/datum/config_entry/proc/ValidateKeyedList(str_val, list_mode, splitter)
str_val = trim(str_val)
var/key_pos = findtext(str_val, splitter)
var/key_name = null
var/key_value = null
if(key_pos || list_mode == LIST_MODE_FLAG)
key_name = lowertext(copytext(str_val, 1, key_pos))
key_value = copytext(str_val, key_pos + 1)
var/temp
var/continue_check
switch(list_mode)
if(LIST_MODE_FLAG)
temp = TRUE
continue_check = TRUE
if(LIST_MODE_NUM)
temp = text2num(key_value)
continue_check = !isnull(temp)
if(LIST_MODE_TEXT)
temp = key_value
continue_check = temp
if(continue_check && ValidateListEntry(key_name, temp))
config_entry_value[key_name] = temp
return TRUE
return FALSE
/datum/config_entry/proc/ValidateListEntry(key_name, key_value)
return TRUE
@@ -156,44 +138,59 @@
config_entry_value = new_list
return TRUE
/datum/config_entry/keyed_flag_list
abstract_type = /datum/config_entry/keyed_flag_list
config_entry_value = list()
dupes_allowed = TRUE
/datum/config_entry/keyed_flag_list/ValidateAndSet(str_val)
if(!VASProcCallGuard(str_val))
return FALSE
return ValidateKeyedList(str_val, LIST_MODE_FLAG, " ")
/datum/config_entry/keyed_number_list
abstract_type = /datum/config_entry/keyed_number_list
/datum/config_entry/keyed_list
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 = " "
/datum/config_entry/keyed_number_list/vv_edit_var(var_name, var_value)
return var_name != "splitter" && ..()
/datum/config_entry/keyed_list/New()
. = ..()
if(isnull(key_mode) || isnull(value_mode))
CRASH("Keyed list of type [type] created with null key or value mode!")
/datum/config_entry/keyed_number_list/ValidateAndSet(str_val)
/datum/config_entry/keyed_list/ValidateAndSet(str_val)
if(!VASProcCallGuard(str_val))
return FALSE
return ValidateKeyedList(str_val, LIST_MODE_NUM, splitter)
/datum/config_entry/keyed_string_list
abstract_type = /datum/config_entry/keyed_string_list
config_entry_value = list()
dupes_allowed = TRUE
var/splitter = " "
str_val = trim(str_val)
var/key_pos = findtext(str_val, splitter)
var/key_name = null
var/key_value = null
/datum/config_entry/keyed_string_list/vv_edit_var(var_name, var_value)
if(key_pos || value_mode == VALUE_MODE_FLAG)
key_name = lowertext(copytext(str_val, 1, key_pos))
key_value = copytext(str_val, key_pos + 1)
var/new_key
var/new_value
var/continue_check_value
var/continue_check_key
switch(key_mode)
if(KEY_MODE_TEXT)
new_key = key_name
continue_check_key = new_key
if(KEY_MODE_TYPE)
new_key = key_name
if(!ispath(new_key))
new_key = text2path(new_key)
continue_check_key = ispath(new_key)
switch(value_mode)
if(VALUE_MODE_FLAG)
new_value = TRUE
continue_check_value = TRUE
if(VALUE_MODE_NUM)
new_value = text2num(key_value)
continue_check_value = !isnull(new_value)
if(VALUE_MODE_TEXT)
new_value = key_value
continue_check_value = new_value
if(continue_check_value && continue_check_key && ValidateListEntry(new_key, new_value))
config_entry_value[new_key] = new_value
return TRUE
return FALSE
/datum/config_entry/keyed_list/vv_edit_var(var_name, var_value)
return var_name != "splitter" && ..()
/datum/config_entry/keyed_string_list/ValidateAndSet(str_val)
if(!VASProcCallGuard(str_val))
return FALSE
return ValidateKeyedList(str_val, LIST_MODE_TEXT, splitter)
#undef LIST_MODE_NUM
#undef LIST_MODE_TEXT
#undef LIST_MODE_FLAG
+41 -22
View File
@@ -20,7 +20,19 @@
var/motd
/datum/controller/configuration/proc/Load()
/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)
CRASH("[THIS_PROC_TYPE_WEIRD] called more than once!")
InitEntries()
@@ -36,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 ..()
@@ -84,9 +102,10 @@
var/list/lines = world.file2list("[directory]/[filename]")
var/list/_entries = entries
for(var/L in lines)
L = trim(L)
if(!L)
continue
var/firstchar = copytext(L, 1, 2)
if(firstchar == "#")
continue
@@ -107,7 +126,7 @@
if(!entry)
continue
if(entry == "$include")
if(!value)
log_config("Warning: Invalid $include directive: [value]")
@@ -115,7 +134,7 @@
LoadEntries(value, stack)
++.
continue
var/datum/config_entry/E = _entries[entry]
if(!E)
log_config("Unknown setting in configuration: '[entry]'")
@@ -137,19 +156,19 @@
E = new_ver
else
warning("[new_ver.type] is deprecated but gave no proper return for DeprecationUpdate()")
var/validated = E.ValidateAndSet(value)
if(!validated)
log_config("Failed to validate setting \"[value]\" for [entry]")
else
else
if(E.modified && !E.dupes_allowed)
log_config("Duplicate setting for [entry] ([value], [E.resident_file]) detected! Using latest.")
E.resident_file = filename
if(validated)
E.modified = TRUE
++.
/datum/controller/configuration/can_vv_get(var_name)
@@ -165,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)
@@ -175,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)
@@ -188,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()
@@ -197,7 +216,7 @@
mode_reports = list()
mode_false_report_weight = list()
votable_modes = list()
var/list/probabilities = Get(/datum/config_entry/keyed_number_list/probability)
var/list/probabilities = Get(/datum/config_entry/keyed_list/probability)
for(var/T in gamemode_cache)
// I wish I didn't have to instance the game modes in order to look up
// their information, but it is the only way (at least that I know of).
@@ -293,9 +312,9 @@
/datum/controller/configuration/proc/get_runnable_modes()
var/list/datum/game_mode/runnable_modes = new
var/list/probabilities = Get(/datum/config_entry/keyed_number_list/probability)
var/list/min_pop = Get(/datum/config_entry/keyed_number_list/min_pop)
var/list/max_pop = Get(/datum/config_entry/keyed_number_list/max_pop)
var/list/probabilities = Get(/datum/config_entry/keyed_list/probability)
var/list/min_pop = Get(/datum/config_entry/keyed_list/min_pop)
var/list/max_pop = Get(/datum/config_entry/keyed_list/max_pop)
var/list/repeated_mode_adjust = Get(/datum/config_entry/number_list/repeated_mode_adjust)
for(var/T in gamemode_cache)
var/datum/game_mode/M = new T()
@@ -323,9 +342,9 @@
/datum/controller/configuration/proc/get_runnable_midround_modes(crew)
var/list/datum/game_mode/runnable_modes = new
var/list/probabilities = Get(/datum/config_entry/keyed_number_list/probability)
var/list/min_pop = Get(/datum/config_entry/keyed_number_list/min_pop)
var/list/max_pop = Get(/datum/config_entry/keyed_number_list/max_pop)
var/list/probabilities = Get(/datum/config_entry/keyed_list/probability)
var/list/min_pop = Get(/datum/config_entry/keyed_list/min_pop)
var/list/max_pop = Get(/datum/config_entry/keyed_list/max_pop)
for(var/T in (gamemode_cache - SSticker.mode.type))
var/datum/game_mode/M = new T()
if(!(M.config_tag in modes))
@@ -4,10 +4,12 @@
/datum/config_entry/string/comms_key/ValidateAndSet(str_val)
return str_val != "default_pwd" && length(str_val) > 6 && ..()
/datum/config_entry/keyed_string_list/cross_server
/datum/config_entry/keyed_list/cross_server
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_TEXT
protection = CONFIG_ENTRY_LOCKED
/datum/config_entry/keyed_string_list/cross_server/ValidateAndSet(str_val)
/datum/config_entry/keyed_list/cross_server/ValidateAndSet(str_val)
. = ..()
if(.)
var/list/newv = list()
@@ -15,7 +17,7 @@
newv[replacetext(I, "+", " ")] = config_entry_value[I]
config_entry_value = newv
/datum/config_entry/keyed_string_list/cross_server/ValidateListEntry(key_name, key_value)
/datum/config_entry/keyed_list/cross_server/ValidateListEntry(key_name, key_value)
return key_value != "byond:\\address:port" && ..()
/datum/config_entry/string/cross_comms_name
@@ -1,31 +1,43 @@
/datum/config_entry/number_list/repeated_mode_adjust
/datum/config_entry/keyed_number_list/probability
/datum/config_entry/keyed_list/probability
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_NUM
/datum/config_entry/keyed_number_list/probability/ValidateListEntry(key_name)
/datum/config_entry/keyed_list/probability/ValidateListEntry(key_name)
return key_name in config.modes
/datum/config_entry/keyed_number_list/max_pop
/datum/config_entry/keyed_list/max_pop
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_NUM
/datum/config_entry/keyed_number_list/max_pop/ValidateListEntry(key_name)
/datum/config_entry/keyed_list/max_pop/ValidateListEntry(key_name)
return key_name in config.modes
/datum/config_entry/keyed_number_list/min_pop
/datum/config_entry/keyed_list/min_pop
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_NUM
/datum/config_entry/keyed_number_list/min_pop/ValidateListEntry(key_name, key_value)
/datum/config_entry/keyed_list/min_pop/ValidateListEntry(key_name, key_value)
return key_name in config.modes
/datum/config_entry/keyed_flag_list/continuous // which roundtypes continue if all antagonists die
/datum/config_entry/keyed_list/continuous // which roundtypes continue if all antagonists die
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_FLAG
/datum/config_entry/keyed_flag_list/continuous/ValidateListEntry(key_name, key_value)
/datum/config_entry/keyed_list/continuous/ValidateListEntry(key_name, key_value)
return key_name in config.modes
/datum/config_entry/keyed_flag_list/midround_antag // which roundtypes use the midround antagonist system
/datum/config_entry/keyed_list/midround_antag // which roundtypes use the midround antagonist system
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_FLAG
/datum/config_entry/keyed_flag_list/midround_antag/ValidateListEntry(key_name, key_value)
/datum/config_entry/keyed_list/midround_antag/ValidateListEntry(key_name, key_value)
return key_name in config.modes
/datum/config_entry/keyed_string_list/policy
/datum/config_entry/keyed_list/policy
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_TEXT
/datum/config_entry/number/damage_multiplier
config_entry_value = 1
@@ -124,7 +136,9 @@
/datum/config_entry/flag/show_game_type_odds //if set this allows players to see the odds of each roundtype on the get revision screen
/datum/config_entry/keyed_flag_list/roundstart_races //races you can play as from the get go.
/datum/config_entry/keyed_list/roundstart_races //races you can play as from the get go.
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_FLAG
/datum/config_entry/flag/join_with_mutant_humans //players can pick mutant bodyparts for humans before joining the game
@@ -174,28 +188,67 @@
/datum/config_entry/flag/emojis
/datum/config_entry/number/run_delay //Used for modifying movement speed for mobs.
var/static/value_cache = 0
/datum/config_entry/keyed_list/multiplicative_movespeed
key_mode = KEY_MODE_TYPE
value_mode = VALUE_MODE_NUM
config_entry_value = list( //DEFAULTS
/mob/living/simple_animal = 1,
/mob/living/silicon/pai = 1,
/mob/living/carbon/alien/humanoid/hunter = -1,
/mob/living/carbon/alien/humanoid/royal/praetorian = 1,
/mob/living/carbon/alien/humanoid/royal/queen = 3
)
/datum/config_entry/number/run_delay/ValidateAndSet()
/datum/config_entry/keyed_list/multiplicative_movespeed/ValidateAndSet()
. = ..()
if(.)
value_cache = config_entry_value
update_config_movespeed_type_lookup(TRUE)
/datum/config_entry/number/walk_delay
var/static/value_cache = 0
/datum/config_entry/keyed_list/multiplicative_movespeed/vv_edit_var(var_name, var_value)
. = ..()
if(. && (var_name == NAMEOF(src, config_entry_value)))
update_config_movespeed_type_lookup(TRUE)
/datum/config_entry/number/walk_delay/ValidateAndSet()
/datum/config_entry/number/movedelay //Used for modifying movement speed for mobs.
abstract_type = /datum/config_entry/number/movedelay
/datum/config_entry/number/movedelay/ValidateAndSet()
. = ..()
if(.)
value_cache = config_entry_value
update_mob_config_movespeeds()
/datum/config_entry/number/human_delay //Mob specific modifiers. NOTE: These will affect different mob types in different ways
/datum/config_entry/number/robot_delay
/datum/config_entry/number/monkey_delay
/datum/config_entry/number/alien_delay
/datum/config_entry/number/slime_delay
/datum/config_entry/number/animal_delay
/datum/config_entry/number/movedelay/vv_edit_var(var_name, var_value)
. = ..()
if(. && (var_name == NAMEOF(src, config_entry_value)))
update_mob_config_movespeeds()
/datum/config_entry/number/movedelay/run_delay
/datum/config_entry/number/movedelay/walk_delay
/////////////////////////////////////////////////Outdated move delay
/datum/config_entry/number/outdated_movedelay
deprecated_by = /datum/config_entry/keyed_list/multiplicative_movespeed
abstract_type = /datum/config_entry/number/outdated_movedelay
var/movedelay_type
/datum/config_entry/number/outdated_movedelay/DeprecationUpdate(value)
return "[movedelay_type] [value]"
/datum/config_entry/number/outdated_movedelay/human_delay
movedelay_type = /mob/living/carbon/human
/datum/config_entry/number/outdated_movedelay/robot_delay
movedelay_type = /mob/living/silicon/robot
/datum/config_entry/number/outdated_movedelay/monkey_delay
movedelay_type = /mob/living/carbon/monkey
/datum/config_entry/number/outdated_movedelay/alien_delay
movedelay_type = /mob/living/carbon/alien
/datum/config_entry/number/outdated_movedelay/slime_delay
movedelay_type = /mob/living/simple_animal/slime
/datum/config_entry/number/outdated_movedelay/animal_delay
movedelay_type = /mob/living/simple_animal
/////////////////////////////////////////////////
/datum/config_entry/flag/roundstart_away //Will random away mission be loaded.
@@ -219,9 +272,13 @@
config_entry_value = 12
min_val = 0
/datum/config_entry/keyed_flag_list/random_laws
/datum/config_entry/keyed_list/random_laws
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_FLAG
/datum/config_entry/keyed_number_list/law_weight
/datum/config_entry/keyed_list/law_weight
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_NUM
splitter = ","
/datum/config_entry/number/overflow_cap
@@ -286,25 +343,10 @@
/datum/config_entry/flag/shift_time_realtime
/datum/config_entry/keyed_number_list/antag_rep
/datum/config_entry/keyed_list/antag_rep
key_mode = KEY_MODE_TEXT
value_mode = VALUE_MODE_NUM
/datum/config_entry/number/monkeycap
config_entry_value = 64
min_val = 0
//Cit changes - Adds config options for crew objectives and miscreants
/datum/config_entry/flag/allow_crew_objectives
/datum/config_entry/flag/allow_miscreants
/datum/config_entry/flag/allow_extended_miscreants
/datum/config_entry/flag/nightshift_enabled
/datum/config_entry/number/nightshift_start
config_entry_value = 20
/datum/config_entry/number/nightshift_finish
config_entry_value = 6
//End of Cit changes
@@ -49,6 +49,8 @@
/datum/config_entry/flag/log_pda // log pda messages
/datum/config_entry/flag/log_telecomms // log telecomms messages
/datum/config_entry/flag/log_twitter // log certain expliotable parrots and other such fun things in a JSON file of twitter valid phrases.
/datum/config_entry/flag/log_world_topic // log all world.Topic() calls
@@ -324,8 +326,6 @@
/datum/config_entry/flag/allow_map_voting
/datum/config_entry/flag/generate_minimaps
/datum/config_entry/number/client_warn_version
config_entry_value = null
min_val = 500