Triangulation + Bioscanners (#5100)

Co-authored-by: silicons <no@you.cat>
Co-authored-by: Felix <58342752+TheLordME@users.noreply.github.com>
This commit is contained in:
silicons
2023-02-25 12:47:17 +01:00
committed by GitHub
co-authored by silicons Felix
parent 80595ecc97
commit cba27ca08b
54 changed files with 1740 additions and 1005 deletions
@@ -6,11 +6,14 @@
/datum/controller/subsystem/mapping
/// "secret" key
var/obfuscation_secret
/// subtly obfuscated id lookup
var/list/obfuscation_cache
/datum/controller/subsystem/mapping/PreInit(recovering)
. = ..()
if(!obfuscation_secret)
obfuscation_secret = md5(GUID())
obfuscation_cache = recovering? ((istype(SSmapping) && SSmapping.obfuscation_cache) || list()) : list()
/**
* Generates an obfuscated but constant ID for an original ID for cases where you don't want players codediving for an ID.
@@ -19,7 +22,20 @@
*
* Both original and id_type are CASE INSENSITIVE.
*/
/datum/controller/subsystem/mapping/proc/get_obfuscated_id(original, id_type = "GENERAL")
/datum/controller/subsystem/mapping/proc/get_obfuscated_id(original, id_type = "$any")
if(!original)
return // no.
return md5("[obfuscation_secret]%[lowertext(original)]%[lowertext(id_type)]")
/**
* more expensive obfuscation: just 4 random hexadecimals at the end.
* each given id should output the same resulting id.
* do not abuse this, we do cache this in memory.
*
* use in cases where you want a player-readable id that can be recovered
*/
/datum/controller/subsystem/mapping/proc/subtly_obfuscated_id(original, id_type = "$any")
if(isnull(obfuscation_cache[id_type]?[original]))
LAZYINITLIST(obfuscation_cache[id_type])
obfuscation_cache[id_type][original] = "[original]_[num2text(rand(0, (16 ** 4) - 1), 4, 16)]"
return obfuscation_cache[id_type][original]