Merge pull request #9662 from dapocalypse/PasswordProtectedFiles

Adds password protected files to modular computers.
This commit is contained in:
variableundefined
2018-10-20 11:01:35 +08:00
committed by GitHub
3 changed files with 49 additions and 5 deletions
@@ -4,10 +4,11 @@ var/global/file_uid = 0
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/computer_hardware/hard_drive/holder // Holder that contains this file.
var/obj/item/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/uid // UID of this file
var/password = "" // Placeholder for password.
/datum/computer_file/New()
..()
@@ -36,4 +37,14 @@ var/global/file_uid = 0
else
temp.filename = filename
temp.filetype = filetype
return temp
temp.password = password
return temp
/datum/computer_file/proc/can_access_file(mob/user, input_password = "")
if(!password)
return TRUE
if(!input_password)
input_password = sanitize(input(user, "Please enter a password to access file '[filename]':"))
if(input_password == password)
return TRUE
return FALSE
@@ -55,7 +55,8 @@
"name" = F.filename,
"type" = F.filetype,
"size" = F.size,
"undeletable" = F.undeletable
"undeletable" = F.undeletable,
"encrypted" = !!F.password
)))
data["files"] = files
if(RHDD)
@@ -66,7 +67,8 @@
"name" = F.filename,
"type" = F.filetype,
"size" = F.size,
"undeletable" = F.undeletable
"undeletable" = F.undeletable,
"encrypted" = !!F.password
)))
data["usbfiles"] = usbfiles
@@ -83,6 +85,9 @@
switch(href_list["action"])
if("PRG_openfile")
. = 1
var/datum/computer_file/F = HDD.find_file_by_name(href_list["name"])
if(!F.can_access_file(usr))
return
open_file = href_list["name"]
if("PRG_newtextfile")
. = 1
@@ -197,4 +202,27 @@
if(!F || !istype(F))
return 1
var/datum/computer_file/C = F.clone(0)
HDD.store_file(C)
HDD.store_file(C)
if("PRG_encrypt")
. = 1
if(!HDD)
return 1
var/datum/computer_file/F = HDD.find_file_by_name(href_list["name"])
if(!F || F.undeletable)
return 1
if(F.password)
return
var/new_password = sanitize(input(usr, "Enter an encryption key:", "Encrypt File"))
if(!new_password)
to_chat(usr, "<span class='warning'>File not encrypted.</span>")
return
F.password=new_password
if("PRG_decrypt")
. = 1
if(!HDD)
return 1
var/datum/computer_file/F = HDD.find_file_by_name(href_list["name"])
if(!F || F.undeletable)
return 1
if(F.can_access_file(usr))
F.password = ""