From 7551bf868473e80b5c2120c647dd8eed6ef3f284 Mon Sep 17 00:00:00 2001 From: atermonera Date: Sat, 15 Jan 2022 20:16:35 -0800 Subject: [PATCH] Adds config-enabled whitelist for sprite accessories --- code/controllers/configuration.dm | 6 +++ code/game/jobs/whitelist.dm | 46 ++++++++++--------- .../preference_setup/general/03_body.dm | 17 +++++-- config/example/config.txt | 6 ++- config/example/genemodwhitelist.txt | 16 +++++++ 5 files changed, 65 insertions(+), 26 deletions(-) create mode 100644 config/example/genemodwhitelist.txt diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index b54548cfc5..462bc27ee5 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -290,6 +290,9 @@ var/list/gamemode_cache = list() // How strictly the loadout enforces object species whitelists var/loadout_whitelist = LOADOUT_WHITELIST_LAX + // Whether whitelists are enforced for ears/tail/etc modifications + var/genemod_whitelist = FALSE + var/disable_webhook_embeds = FALSE /datum/configuration/New() @@ -941,6 +944,9 @@ var/list/gamemode_cache = list() if("enable_night_shifts") config.enable_night_shifts = TRUE + if("genemod_whitelist") + config.genemod_whitelist = TRUE + else log_misc("Unknown setting in configuration: '[name]'") diff --git a/code/game/jobs/whitelist.dm b/code/game/jobs/whitelist.dm index 9963c1580c..b1911bb08c 100644 --- a/code/game/jobs/whitelist.dm +++ b/code/game/jobs/whitelist.dm @@ -1,19 +1,17 @@ -#define WHITELISTFILE "data/whitelist.txt" - var/list/whitelist = list() /hook/startup/proc/loadWhitelist() if(config.usewhitelist) load_whitelist() - return 1 + return TRUE /proc/load_whitelist() - whitelist = file2list(WHITELISTFILE) + whitelist = file2list("data/whitelist.txt") if(!whitelist.len) whitelist = null /proc/check_whitelist(mob/M /*, var/rank*/) if(!whitelist) - return 0 + return FALSE return ("[M.ckey]" in whitelist) /var/list/alien_whitelist = list() @@ -21,7 +19,7 @@ var/list/whitelist = list() /hook/startup/proc/loadAlienWhitelist() if(config.usealienwhitelist) load_alienwhitelist() - return 1 + return TRUE /proc/load_alienwhitelist() var/text = file2text("config/alienwhitelist.txt") @@ -33,51 +31,55 @@ var/list/whitelist = list() /proc/is_alien_whitelisted(mob/M, var/datum/species/species) //They are admin or the whitelist isn't in use if(whitelist_overrides(M)) - return 1 + return TRUE //You did something wrong if(!M || !species) - return 0 + return FALSE //The species isn't even whitelisted if(!(species.spawn_flags & SPECIES_IS_WHITELISTED)) - return 1 + return TRUE //If we have a loaded file, search it if(alien_whitelist) for (var/s in alien_whitelist) if(findtext(s,"[M.ckey] - [species.name]")) - return 1 + return TRUE if(findtext(s,"[M.ckey] - All")) - return 1 + return TRUE /proc/is_lang_whitelisted(mob/M, var/datum/language/language) //They are admin or the whitelist isn't in use if(whitelist_overrides(M)) - return 1 + return TRUE //You did something wrong if(!M || !language) - return 0 + return FALSE //The language isn't even whitelisted if(!(language.flags & WHITELISTED)) - return 1 + return TRUE //If we have a loaded file, search it if(alien_whitelist) for (var/s in alien_whitelist) if(findtext(s,"[M.ckey] - [language.name]")) - return 1 + return TRUE if(findtext(s,"[M.ckey] - All")) - return 1 + return TRUE /proc/whitelist_overrides(mob/M) - if(!config.usealienwhitelist) - return 1 - if(check_rights(R_ADMIN|R_EVENT, 0, M)) - return 1 + return !config.usealienwhitelist || check_rights(R_ADMIN|R_EVENT, 0, M) - return 0 +/var/list/genemod_whitelist = list() +/hook/startup/proc/LoadGenemodWhitelist() + global.genemod_whitelist = file2list("config/genemodwhitelist.txt") + return TRUE -#undef WHITELISTFILE +/proc/is_genemod_whitelisted(mob/M) + return M && M.client && M.client.ckey && LAZYLEN(global.genemod_whitelist) && (M.client.ckey in global.genemod_whitelist) + +/proc/foo() + to_world(list2text(global.genemod_whitelist)) diff --git a/code/modules/client/preference_setup/general/03_body.dm b/code/modules/client/preference_setup/general/03_body.dm index e711742287..be9a802b52 100644 --- a/code/modules/client/preference_setup/general/03_body.dm +++ b/code/modules/client/preference_setup/general/03_body.dm @@ -70,9 +70,20 @@ var/global/list/valid_bloodtypes = list("A+", "A-", "B+", "B-", "AB+", "AB-", "O continue if(instance.ckeys_allowed && (!client || !(client.ckey in instance.ckeys_allowed))) continue - if(instance.species_allowed && (!species || !(species in instance.species_allowed)) && (!client || !check_rights(R_ADMIN | R_EVENT | R_FUN, 0, client))) - continue - .[instance.name] = instance + + // Is an admin OR + // Instance is species-whitelisted AND current species matches whitelist OR + // ~~Is NOT species-whitelisted AND~~ config ckey-whitelist is enabled AND ckey matches whitelist + + // There's 3 dedicated species for events that are species-whitelisted for ALL sprites, + // so the list at present actually has a minimum length of 3. + // But because I don't trust SS13 developers to actually respect a #define I set somewhere, + // I'm just throwing out that requirement altogether. -Ater + // TODO: Implement a framework for dynamically creating new singleton even species in-round (Don't @ me with this) + if((istype(client) && check_rights(R_ADMIN | R_EVENT | R_FUN, 0, client)) || \ + (LAZYLEN(instance.species_allowed) && species && (species in instance.species_allowed)) || \ + (config.genemod_whitelist && is_genemod_whitelisted(src))) + .[instance.name] = instance /datum/category_item/player_setup_item/general/body name = "Body" diff --git a/config/example/config.txt b/config/example/config.txt index 18ad88df30..3171fcd7d4 100644 --- a/config/example/config.txt +++ b/config/example/config.txt @@ -546,4 +546,8 @@ ENGINE_MAP Supermatter Engine,Edison's Bane # Controls how strictly the species whitelists on loadout entries are enforced # Possible values: 0 (Off), 1 (Lax, user must be whitelisted for the species), 2 (Strict, user must be the species) -LOADOUT_WHITELIST 1 \ No newline at end of file +LOADOUT_WHITELIST 1 + +# Enables whitelisting ckeys for ears/tail/etc modifications to players. +# Uncomment to ENABLE the whitelist +# GENEMOD_WHITELIST \ No newline at end of file diff --git a/config/example/genemodwhitelist.txt b/config/example/genemodwhitelist.txt new file mode 100644 index 0000000000..1bb18d5cc2 --- /dev/null +++ b/config/example/genemodwhitelist.txt @@ -0,0 +1,16 @@ +# The ckeys of players whitelisted to use general-use sprite accessories. +# Note that this is in the format of "canonical" ckeys, which according to the byond docs are basically just lower-case: +# +# Format: +# ckey(Key) +# Args: +# Key +# The player key to convert to canonical form. +# Returns: +# The key in canonical form. To do this, it strips all punctuation and space from the key and converts to lowercase. The result is still unique for each different key. +# +# You can actually fill this file with whatever besides the whitelisted ckeys because the matching is very dumb + +some_user +someotheruser +text that has spaces and so isn't really a ckey (It does nothing) \ No newline at end of file