Files
Aurora.3/code/modules/modular_computers/file_system/computer_file.dm
dapocalypse c5f5f8c68d PasswordProtectedFiles (#5067)
This PR adds password protected files. When creating a file an additional prompt will come up. This will ask if you would like to set a password. If left blank a password will not be set and the file will function normally. If a password is set, when viewing, cloning, renaming, or deleting a file, the password prompt will again come up asking for the previously set password. When cloned, the cloned file retains the password.
2018-09-23 14:38:47 +03:00

53 lines
1.8 KiB
Plaintext

var/global/file_uid = 0
/datum/computer_file/
var/filename = "NewFile" // Placeholder. No spacebars
var/filetype = "XXX" // File full names are [filename].[filetype] so like NewFile.XXX in this case
var/size = 1 // File size in GQ. Integers only!
var/obj/item/weapon/computer_hardware/hard_drive/holder // Holder that contains this file.
var/unsendable = 0 // Whether the file may be sent to someone via NTNet transfer or other means.
var/undeletable = 0 // Whether the file may be deleted. Setting to 1 prevents deletion/renaming/etc.
var/password = "" // Placeholder for password protected files.
var/uid // UID of this file
/datum/computer_file/New()
..()
uid = file_uid
file_uid++
/datum/computer_file/Destroy()
if(!holder)
return ..()
holder.remove_file(src)
// holder.holder is the computer that has drive installed. If we are Destroy()ing program that's currently running kill it.
if(holder.holder2 && holder.holder2.active_program == src)
holder.holder2.kill_program(1)
holder = null
return ..()
// Returns independent copy of this file.
/datum/computer_file/proc/clone(var/rename = 0)
var/datum/computer_file/temp = new type
temp.unsendable = unsendable
temp.undeletable = undeletable
temp.size = size
temp.password = password
if(rename)
temp.filename = filename + "(Copy)"
else
temp.filename = filename
temp.filetype = filetype
return temp
/datum/computer_file/proc/can_access_file(var/mob/user, input_password = "")
if(!password)
return TRUE
else
if (!input_password)
input_password = sanitize(input(user, "Please enter a password to access file '[filename]':"))
if (input_password == password)
return TRUE
else
return FALSE