From e39b509cd894e463c8c63a51fea5502e4325300c Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 17 Jan 2022 01:02:26 +0100 Subject: [PATCH] [MIRROR] Safe code documentation [MDB IGNORE] (#10758) * Safe code documentation (#64096) Adds better documentation and variable naming to safe code. Also removed one variable that hasn't done anything in years. * Safe code documentation Co-authored-by: dragomagol <66640614+dragomagol@users.noreply.github.com> --- code/game/objects/items/storage/secure.dm | 113 +++++++++--------- .../mission_code/stationCollision.dm | 7 +- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/code/game/objects/items/storage/secure.dm b/code/game/objects/items/storage/secure.dm index 852ba4b72ff..4a9bba6ea12 100644 --- a/code/game/objects/items/storage/secure.dm +++ b/code/game/objects/items/storage/secure.dm @@ -7,23 +7,31 @@ * Wall Safe */ -// ----------------------------- -// Generic Item -// ----------------------------- +///Generic Safe /obj/item/storage/secure name = "secstorage" - var/icon_locking = "secureb" - var/icon_sparking = "securespark" - var/icon_opened = "secure0" - var/code = "" - var/l_code = null - var/l_set = FALSE - var/l_setshort = FALSE - var/l_hacking = FALSE - var/open = FALSE - var/can_hack_open = TRUE - w_class = WEIGHT_CLASS_NORMAL desc = "This shouldn't exist. If it does, create an issue report." + w_class = WEIGHT_CLASS_NORMAL + + /// icon_state of locked safe + var/icon_locking = "secureb" + /// icon_state of sparking safe + var/icon_sparking = "securespark" + /// icon_state of opened safe + var/icon_opened = "secure0" + /// The code entered by the user + var/entered_code + /// The code that will open this safe + var/lock_code + /// Does this lock have a code set? + var/lock_set = FALSE + /// Is this lock currently being hacked? + var/lock_hacking = FALSE + /// Is the safe service panel open? + var/panel_open = FALSE + /// Is this door hackable? + var/can_hack_open = TRUE + /obj/item/storage/secure/ComponentInitialize() . = ..() @@ -34,30 +42,30 @@ /obj/item/storage/secure/examine(mob/user) . = ..() if(can_hack_open) - . += "The service panel is currently [open ? "unscrewed" : "screwed shut"]." + . += "The service panel is currently [panel_open ? "unscrewed" : "screwed shut"]." -/obj/item/storage/secure/attackby(obj/item/W, mob/user, params) +/obj/item/storage/secure/attackby(obj/item/weapon, mob/user, params) if(can_hack_open && SEND_SIGNAL(src, COMSIG_IS_STORAGE_LOCKED)) - if (W.tool_behaviour == TOOL_SCREWDRIVER) - if (W.use_tool(src, user, 20)) - open = !open - to_chat(user, span_notice("You [open ? "open" : "close"] the service panel.")) + if (weapon.tool_behaviour == TOOL_SCREWDRIVER) + if (weapon.use_tool(src, user, 20)) + panel_open = !panel_open + to_chat(user, span_notice("You [panel_open ? "open" : "close"] the service panel.")) return - if (W.tool_behaviour == TOOL_WIRECUTTER) + if (weapon.tool_behaviour == TOOL_WIRECUTTER) to_chat(user, span_danger("[src] is protected from this sort of tampering, yet it appears the internal memory wires can still be pulsed.")) return - if (W.tool_behaviour == TOOL_MULTITOOL) - if(l_hacking) + if (weapon.tool_behaviour == TOOL_MULTITOOL) + if(lock_hacking) to_chat(user, span_danger("This safe is already being hacked.")) return - if(open == TRUE) + if(panel_open == TRUE) to_chat(user, span_danger("Now attempting to reset internal memory, please hold.")) - l_hacking = TRUE - if (W.use_tool(src, user, 400)) + lock_hacking = TRUE + if (weapon.use_tool(src, user, 400)) to_chat(user, span_danger("Internal memory reset - lock has been disengaged.")) - l_set = FALSE + lock_set = FALSE - l_hacking = FALSE + lock_hacking = FALSE return to_chat(user, span_warning("You must unscrew the service panel before you can pulse the wiring!")) @@ -71,11 +79,9 @@ user.set_machine(src) var/dat = text("[]
\n\nLock Status: []",src, (locked ? "LOCKED" : "UNLOCKED")) var/message = "Code" - if ((l_set == 0) && (!l_setshort)) + if (lock_set == 0) dat += text("

\n5-DIGIT PASSCODE NOT SET.
ENTER NEW PASSCODE.
") - if (l_setshort) - dat += text("

\nALERT: MEMORY SYSTEM ERROR - 6040 201") - message = text("[]", code) + message = text("[]", entered_code) if (!locked) message = "*****" dat += text("


\n>[]
\n1-2-3
\n4-5-6
\n7-8-9
\nR-0-E
\n
", message) @@ -87,26 +93,26 @@ return if (href_list["type"]) if (href_list["type"] == "E") - if (!l_set && (length(code) == 5) && (!l_setshort) && (code != "ERROR")) - l_code = code - l_set = TRUE - else if ((code == l_code) && l_set) + if (!lock_set && (length(entered_code) == 5) && (entered_code != "ERROR")) + lock_code = entered_code + lock_set = TRUE + else if ((entered_code == lock_code) && lock_set) SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, FALSE) cut_overlays() add_overlay(icon_opened) - code = null + entered_code = null else - code = "ERROR" + entered_code = "ERROR" else - if ((href_list["type"] == "R") && (!l_setshort)) + if (href_list["type"] == "R") SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, TRUE) cut_overlays() - code = null + entered_code = null SEND_SIGNAL(src, COMSIG_TRY_STORAGE_HIDE_FROM, usr) else - code += text("[]", sanitize_text(href_list["type"])) - if (length(code) > 5) - code = "ERROR" + entered_code += text("[]", sanitize_text(href_list["type"])) + if (length(entered_code) > 5) + entered_code = "ERROR" add_fingerprint(usr) for(var/mob/M in viewers(1, loc)) if ((M.client && M.machine == src)) @@ -114,10 +120,7 @@ return return - -// ----------------------------- -// Secure Briefcase -// ----------------------------- +///Secure Briefcase /obj/item/storage/secure/briefcase name = "secure briefcase" icon = 'icons/obj/storage.dmi' @@ -144,21 +147,17 @@ STR.max_combined_w_class = 21 STR.max_w_class = WEIGHT_CLASS_NORMAL -//Syndie variant of Secure Briefcase. Contains space cash, slightly more robust. +///Syndie variant of Secure Briefcase. Contains space cash, slightly more robust. /obj/item/storage/secure/briefcase/syndie force = 15 /obj/item/storage/secure/briefcase/syndie/PopulateContents() ..() - var/datum/component/storage/STR = GetComponent(/datum/component/storage) - for(var/i in 1 to STR.max_items - 2) + var/datum/component/storage/storage_space = GetComponent(/datum/component/storage) + for(var/i in 1 to storage_space.max_items - 2) new /obj/item/stack/spacecash/c1000(src) - -// ----------------------------- -// Secure Safe -// ----------------------------- - +///Secure Safe /obj/item/storage/secure/safe name = "secure safe" icon = 'icons/obj/storage.dmi' @@ -216,8 +215,8 @@ MAPPING_DIRECTIONAL_HELPERS(/obj/item/storage/secure/safe/caps_spare, 32) /obj/item/storage/secure/safe/caps_spare/Initialize(mapload) . = ..() - l_code = SSid_access.spare_id_safe_code - l_set = TRUE + lock_code = SSid_access.spare_id_safe_code + lock_set = TRUE SEND_SIGNAL(src, COMSIG_TRY_STORAGE_SET_LOCKSTATE, TRUE) /obj/item/storage/secure/safe/caps_spare/PopulateContents() diff --git a/code/modules/awaymissions/mission_code/stationCollision.dm b/code/modules/awaymissions/mission_code/stationCollision.dm index 23edb44f689..bf939b7c6de 100644 --- a/code/modules/awaymissions/mission_code/stationCollision.dm +++ b/code/modules/awaymissions/mission_code/stationCollision.dm @@ -90,6 +90,7 @@ GLOBAL_VAR_INIT(sc_safecode5, "[rand(0,9)]") /obj/item/paper/fluff/awaymissions/stationcollision/safehint_paper_hydro name = "shredded paper" + /obj/item/paper/fluff/awaymissions/stationcollision/safehint_paper_hydro/Initialize(mapload) . = ..() info = "Although the paper is shredded, you can clearly see the number: '[GLOB.sc_safecode2]'" @@ -101,6 +102,7 @@ GLOBAL_VAR_INIT(sc_safecode5, "[rand(0,9)]") /obj/item/paper/fluff/awaymissions/stationcollision/safehint_paper_bible name = "hidden paper" + /obj/item/paper/fluff/awaymissions/stationcollision/safehint_paper_bible/Initialize(mapload) . = ..() info = {"It would appear that the pen hidden with the paper had leaked ink over the paper. @@ -128,10 +130,9 @@ GLOBAL_VAR_INIT(sc_safecode5, "[rand(0,9)]") /obj/item/storage/secure/safe/sc_ssafe/Initialize(mapload) . = ..() - l_code = "[GLOB.sc_safecode1][GLOB.sc_safecode2][GLOB.sc_safecode3][GLOB.sc_safecode4][GLOB.sc_safecode5]" - l_set = 1 + lock_code = "[GLOB.sc_safecode1][GLOB.sc_safecode2][GLOB.sc_safecode3][GLOB.sc_safecode4][GLOB.sc_safecode5]" + lock_set = TRUE new /obj/item/gun/energy/mindflayer(src) new /obj/item/soulstone(src) new /obj/item/clothing/suit/hooded/cultrobes/hardened(src) - //new /obj/item/teleportation_scroll(src) new /obj/item/stack/ore/diamond(src)