G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 29th, 2020 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /obj/machinery/computer/exonet/access_directory
  2.     name = "EXONET Access Controller"
  3.     desc = "A very complex machine that manages the security for an EXONET system. Looks fragile."
  4.     active_power_usage = 4 KILOWATTS
  5.     ui_template = "exonet_access_directory.tmpl"
  6.  
  7.     // These are program stateful variables.
  8.     var/file_server             // What file_server we're viewing. This is a net_tag or other.
  9.     var/editing_user            // If we're editing a user, it's assigned here.
  10.     var/awaiting_cortical_scan  // If this is true, we're waiting for someone to touch the stupid interface so that'll add a new user record.
  11.     var/last_scan               // The UID of the person last scanned by this machine. Do not deserialize this. It's worthless.
  12.     var/list/initial_grants     // List of initial grants the machine can try to make on first loadup.
  13.     var/error                   // Currently displayed error.
  14.  
  15. /obj/machinery/computer/exonet/access_directory/on_update_icon()
  16.     if(operable())
  17.         icon_state = "bus"
  18.     else
  19.         icon_state = "bus_off"
  20.  
  21. /obj/machinery/computer/exonet/access_directory/Initialize()
  22.     ..()
  23.     return INITIALIZE_HINT_LATELOAD
  24.    
  25. /obj/machinery/computer/exonet/access_directory/LateInitialize()
  26.     if(initial_grants)
  27.         var/datum/extension/exonet_device/exonet = get_extension(src, /datum/extension/exonet_device)
  28.         if(!file_server)
  29.             var/list/mainframes = exonet.get_mainframes()
  30.             if(mainframes.len <= 0)
  31.                 .["error"] = "NETWORK ERROR: No mainframes are available for storing security records."
  32.                 return .
  33.             var/obj/machinery/computer/exonet/mainframe/MF = mainframes[1]
  34.             file_server = exonet.get_network_tag(MF)
  35.             for(var/initial_grant in initial_grants)
  36.                 var/datum/computer_file/data/grant_record/GR = new()
  37.                 GR.set_value(initial_grant)
  38.                 MF.store_file(GR)
  39.         initial_grants = null
  40.  
  41. // Gets all grants on the machine we're currently linked to.
  42. /obj/machinery/computer/exonet/access_directory/proc/get_all_grants()
  43.     var/datum/extension/exonet_device/exonet = get_extension(src, /datum/extension/exonet_device)
  44.     var/obj/machinery/computer/exonet/mainframe/mainframe = exonet.get_device_by_tag(file_server)
  45.     if(!mainframe)
  46.         return list() // No connection.
  47.     var/list/grants = list()
  48.     for(var/datum/computer_file/data/grant_record/GR in mainframe.stored_files)
  49.         LAZYDISTINCTADD(grants, GR)
  50.     return grants
  51.  
  52. // Get the access record for the user we're *currently* editing.
  53. /obj/machinery/computer/exonet/access_directory/proc/get_access_record()
  54.     var/datum/extension/exonet_device/exonet = get_extension(src, /datum/extension/exonet_device)
  55.     var/obj/machinery/computer/exonet/mainframe/mainframe = exonet.get_device_by_tag(file_server)
  56.     if(!mainframe)
  57.         return
  58.     for(var/datum/computer_file/data/access_record/AR in mainframe.stored_files)
  59.         if(AR.user_id != editing_user)
  60.             continue
  61.         return AR
  62.  
  63. /obj/machinery/computer/exonet/access_directory/Topic(href, href_list)
  64.     if(..())
  65.         return 1
  66.    
  67.     var/datum/extension/exonet_device/exonet = get_extension(src, /datum/extension/exonet_device)
  68.  
  69.     if(href_list["PRG_back"])
  70.         error = null
  71.         editing_user = null
  72.     if(href_list["PRG_changefileserver"])
  73.         var/old_value = file_server
  74.         var/list/file_servers = list()
  75.         for(var/obj/machinery/computer/exonet/mainframe/mainframe in exonet.get_mainframes())
  76.             LAZYDISTINCTADD(file_servers, exonet.get_network_tag(mainframe))
  77.         file_server = sanitize(input(usr, "Choose a fileserver to view access records on:", "Select File Server") as null|anything in file_servers)
  78.         if(!file_server)
  79.             file_server = old_value // Safety check.
  80.     if(href_list["PRG_assigngrant"])
  81.         var/list/all_grants = get_all_grants()
  82.         var/list/grant_values = list()
  83.         // Make a pretty list for UI.
  84.         for(var/datum/computer_file/data/grant_record/GR in all_grants)
  85.             LAZYDISTINCTADD(grant_values, GR.stored_data)
  86.         var/selected_grant = sanitize(input(usr, "Choose a grant to assign to this user:", "Assign Grant") as null|anything in grant_values)
  87.         if(!selected_grant)
  88.             return 1 // Chose nothing.
  89.         // Resolve our selection back to a file.
  90.         var/datum/computer_file/data/grant_record/grant
  91.         for(var/datum/computer_file/data/grant_record/GR in all_grants)
  92.             if(selected_grant == GR.stored_data)
  93.                 grant = GR
  94.                 break
  95.         var/datum/computer_file/data/access_record/AR = get_access_record()
  96.         if(!AR)
  97.             error = "ERROR: Access record not found."
  98.             return 1
  99.         AR.add_grant(grant) // Add the grant to the record.    
  100.     // if(href_list["PRG_creategrant"])
  101.     // if(href_list["PRG_deletegrant"])
  102.     if(href_list["PRG_adduser"])
  103.         var/new_user_id = sanitize(input(usr, "Enter user's PLEXUS ID or leave blank to cancel:", "Add New User"))
  104.         if(!new_user_id)
  105.             return 1
  106.         var/new_user_name = sanitize(input(usr, "Enter user's desired name or leave blank to cancel:", "Add New User"))
  107.         if(!new_user_name)
  108.             return 1
  109.         // TODO: Add a check to see if this user actually exists if PLEXUS is online.
  110.         // Add the record.
  111.         var/datum/computer_file/data/access_record/new_record = new()
  112.         new_record.filename = "[replacetext(new_user_name, " ", "_")]"
  113.         new_record.user_id = new_user_id
  114.         new_record.desired_name = new_user_name
  115.         new_record.ennid = ennid
  116.         var/obj/machinery/computer/exonet/mainframe/mainframe = exonet.get_device_by_tag(file_server)
  117.         if(!mainframe)
  118.             error = "NETWORK ERROR: Lost connection to mainframe. Unable to save user access record."
  119.             return 1
  120.         if(!mainframe.try_store_file(new_record))
  121.             error = "MAINFRAME ERROR: Unable to store record on mainframe."
  122.             return 1
  123.         editing_user = new_user_id
  124.     if(href_list["PRG_viewuser"])
  125.         editing_user = href_list["PRG_viewuser"]
  126.     // if(href_list["PRG_deleteuser"])
  127.     // if(href_list["PRG_rename"])
  128.  
  129.     return 1
  130.  
  131.  
  132. /obj/machinery/computer/exonet/access_directory/build_ui_data()
  133.     . = ..()
  134.  
  135.     if(error)
  136.         .["error"] = error
  137.         return .
  138.  
  139.     var/datum/extension/exonet_device/exonet = get_extension(src, /datum/extension/exonet_device)
  140.     if(!file_server)
  141.         var/list/mainframes = exonet.get_mainframes()
  142.         if(length(mainframes) <= 0)
  143.             .["error"] = "NETWORK ERROR: No mainframes are available for storing security records."
  144.             return .
  145.         file_server = exonet.get_network_tag(mainframes[1])
  146.  
  147.     .["file_server"] = file_server
  148.     .["editing_user"] = editing_user
  149.     .["awaiting_cortical_scan"] = awaiting_cortical_scan
  150.     if(awaiting_cortical_scan)
  151.         return .
  152.  
  153.     // Let's build some data.
  154.     var/obj/machinery/computer/exonet/mainframe/mainframe = exonet.get_device_by_tag(file_server)
  155.     if(!mainframe || !mainframe.operable())
  156.         .["error"] = "NETWORK ERROR: Mainframe is offline."
  157.         return .
  158.     if(editing_user)
  159.         .["user_id"] = editing_user
  160.         var/list/grants = list()
  161.         // We're editing a user, so we only need to build a subset of data.
  162.         for(var/datum/computer_file/data/access_record/AR in mainframe.stored_files)
  163.             if(AR.user_id != editing_user)
  164.                 continue
  165.             .["desired_name"]   = AR.desired_name
  166.             .["grant_count"]    = length(AR.get_valid_grants())
  167.             .["size"]           = AR.size
  168.             // Oh hey here's the record we're looking for.
  169.             for(var/datum/computer_file/data/grant_record/GR in AR.get_valid_grants())
  170.                 grants.Add(list(
  171.                     "name" = GR.stored_data
  172.                 ))
  173.         .["grants"] = grants
  174.     else
  175.         // We're looking at all records. Or lack thereof.
  176.         var/list/users = list()
  177.         for(var/datum/computer_file/data/access_record/AR in mainframe.stored_files)
  178.             users.Add(list(
  179.                 "desired_name" = AR.desired_name,
  180.                 "user_id" = AR.user_id,
  181.                 "grant_count" = length(AR.get_valid_grants()),
  182.                 "size" = AR.size
  183.             ))
  184.         .["users"] = users
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top