mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2026-08-30 00:35:45 +01:00
Improve whitelist checking speed
This commit is contained in:
+41
-24
@@ -30,56 +30,73 @@ var/list/whitelist = list()
|
||||
if (!text)
|
||||
log_misc("Failed to load config/alienwhitelist.txt")
|
||||
else
|
||||
alien_whitelist = splittext(text, "\n")
|
||||
var/lines = splittext(text, "\n") // Now we've got a bunch of "ckey = something" strings in a list
|
||||
for(var/line in lines)
|
||||
var/list/left_and_right = splittext(line, " - ") // Split it on the dash into left and right
|
||||
if(LAZYLEN(left_and_right) != 2)
|
||||
warning("Alien whitelist entry is invalid: [line]") // If we didn't end up with a left and right, the line is bad
|
||||
continue
|
||||
var/key = left_and_right[1]
|
||||
if(key != ckey(key))
|
||||
warning("Alien whitelist entry appears to have key, not ckey: [line]") // The key contains invalid ckey characters
|
||||
continue
|
||||
var/list/our_whitelists = alien_whitelist[key] // Try to see if we have one already and add to it
|
||||
if(!our_whitelists) // Guess this is their first/only whitelist entry
|
||||
our_whitelists = list()
|
||||
alien_whitelist[key] = our_whitelists
|
||||
our_whitelists += left_and_right[2]
|
||||
|
||||
/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
|
||||
if(findtext(s,"[M.ckey] - All"))
|
||||
return 1
|
||||
//Search the whitelist
|
||||
var/list/our_whitelists = alien_whitelist[M.ckey]
|
||||
if("All" in our_whitelists)
|
||||
return TRUE
|
||||
if(species.name in our_whitelists)
|
||||
return TRUE
|
||||
|
||||
// Go apply!
|
||||
return FALSE
|
||||
|
||||
/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
|
||||
if(findtext(s,"[M.ckey] - All"))
|
||||
return 1
|
||||
//Search the whitelist
|
||||
var/list/our_whitelists = alien_whitelist[M.ckey]
|
||||
if("All" in our_whitelists)
|
||||
return TRUE
|
||||
if(language.name in our_whitelists)
|
||||
return TRUE
|
||||
|
||||
return FALSE
|
||||
|
||||
/proc/whitelist_overrides(mob/M)
|
||||
if(!config.usealienwhitelist)
|
||||
return 1
|
||||
return TRUE
|
||||
if(check_rights(R_ADMIN|R_EVENT, 0, M))
|
||||
return 1
|
||||
return TRUE
|
||||
|
||||
return 0
|
||||
return FALSE
|
||||
|
||||
#undef WHITELISTFILE
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<<<<<<< HEAD
|
||||
some~user - Species
|
||||
|
||||
||||||| parent of 49840a5684... Merge pull request #11291 from VOREStation/Arokha/wlspeed
|
||||
some~user - Species
|
||||
=======
|
||||
>>>>>>> 49840a5684... Merge pull request #11291 from VOREStation/Arokha/wlspeed
|
||||
admiraldragon - Vox
|
||||
aetherelemental - Daemon
|
||||
arandomalien - Xenochimera
|
||||
@@ -19,7 +24,23 @@ hollifex - Diona
|
||||
inuzari - Diona
|
||||
jademanique - Xenochimera
|
||||
ktccd - Diona
|
||||
<<<<<<< HEAD
|
||||
khanivore - Protean
|
||||
||||||| parent of 49840a5684... Merge pull request #11291 from VOREStation/Arokha/wlspeed
|
||||
liache - Black-Eyed Shadekin
|
||||
lizehrd - Xenochimera
|
||||
lordlag - Black-Eyed Shadekin
|
||||
losstinspess - Xenochimera
|
||||
magpiemayhem - Vox
|
||||
marco_barko - Protean
|
||||
=======
|
||||
liache - Black-Eyed Shadekin
|
||||
lizehrd - Xenochimera
|
||||
lordlag - Black-Eyed Shadekin
|
||||
losstinspess - Xenochimera
|
||||
magpiemayhem - Vox
|
||||
marcobarko - Protean
|
||||
>>>>>>> 49840a5684... Merge pull request #11291 from VOREStation/Arokha/wlspeed
|
||||
mewchild - Diona
|
||||
mewchild - Vox
|
||||
mrsebbi - Xenochimera
|
||||
@@ -59,4 +80,4 @@ xioen - Diona
|
||||
xioen - Xenochimera
|
||||
xonkon - Protean
|
||||
zalvine - Shadekin Empathy
|
||||
zammyman215 - Vox
|
||||
zammyman215 - Vox
|
||||
Reference in New Issue
Block a user