Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] Fixes network bugs and adjusts program access #307

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@
return
data["connected"] = TRUE
data["default_state"] = auto_deny_all
var/list/grants = list()
var/list/grants_data = list()
if(!network.access_controller)
return
for(var/datum/computer_file/data/grant_record/GR in network.access_controller.get_all_grants())
grants.Add(list(list(
grants_data.Add(list(list(
"grant_name" = GR.stored_data,
"assigned" = (GR.stored_data in grants)
)))
data["grants"] = grants
data["grants"] = grants_data

/obj/item/stock_parts/network_lock/OnTopic(mob/user, href_list, datum/topic_state/state)
. = ..()
Expand Down
5 changes: 5 additions & 0 deletions code/game/objects/items/weapons/cards_ids.dm
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ var/const/NO_EMAG_ACT = -50
to_chat(usr, SPAN_WARNING("Pressing the synchronization button on the card causes a red LED to flash three times."))

/obj/item/card/id/network/proc/refresh_access_record(var/datum/computer_network/network)
if(!network)
var/datum/extension/network_device/D = get_extension(src, /datum/extension/network_device)
network = D.get_network()
if(!network)
return
for(var/datum/extension/network_device/mainframe/mainframe in network.get_mainframes_by_role(MF_ROLE_CREW_RECORDS))
for(var/datum/computer_file/report/crew_record/ar in mainframe.get_all_files())
if(ar.user_id != user_id)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/merchant/merchant_programs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
nanomodule_path = /datum/nano_module/program/merchant
size = 12
usage_flags = PROGRAM_CONSOLE
required_access = access_merchant
required_access = list(access_merchant)
var/obj/machinery/merchant_pad/pad = null
var/current_merchant = 0
var/show_trades = 0
Expand Down
42 changes: 25 additions & 17 deletions code/modules/modular_computers/file_system/program.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/datum/computer_file/program
filetype = "PRG"
filename = "UnknownProgram" // File name. FILE NAME MUST BE UNIQUE IF YOU WANT THE PROGRAM TO BE DOWNLOADABLE FROM NETWORK!
var/required_access = null // List of required accesses to run/download the program.
var/list/required_access = list() // List of required accesses to run/download the program.
var/requires_access_to_run = 1 // Whether the program checks for required_access when run.
var/requires_access_to_download = 1 // Whether the program checks for required_access when downloading.
var/datum/nano_module/NM = null // If the program uses NanoModule, put it here and it will be automagically opened. Otherwise implement ui_interact.
Expand Down Expand Up @@ -83,32 +83,40 @@
// Check if the user can run program. Only humans can operate computer. Automatically called in run_program()
// User has to wear their ID or have it inhand for ID Scan to work.
// Can also be called manually, with optional parameter being access_to_check to scan the user's ID
/datum/computer_file/program/proc/can_run(var/mob/living/user, var/loud = 0, var/access_to_check)
/datum/computer_file/program/proc/can_run(var/mob/living/user, var/loud = 0, var/list/accesses_to_check, var/datum/computer_network/network)
if(!requires_access_to_run)
return 1
// Defaults to required_access
if(!access_to_check)
access_to_check = required_access
if(!access_to_check) // No required_access, allow it.
return 1
return TRUE
// Checks to see if network access is enabled, and then defaults to required_access if not.
if(!accesses_to_check)
if(network)
var/datum/extension/network_device/acl/access_controller = network.access_controller
if(access_controller && access_controller.program_control)
accesses_to_check = access_controller.get_program_access(filename)

if(!length(accesses_to_check))
accesses_to_check = required_access

if(!length(accesses_to_check)) // No required_access, allow it.
return TRUE

// Admin override - allows operation of any computer as aghosted admin, as if you had any required access.
if(isghost(user) && check_rights(R_ADMIN, 0, user))
return 1
return TRUE

if(!istype(user))
return 0
return FALSE

var/obj/item/card/id/I = user.GetIdCard()
if(!I)
if(loud)
to_chat(user, "<span class='notice'>\The [computer] flashes an \"RFID Error - Unable to scan ID\" warning.</span>")
return 0

if(access_to_check in I.access)
return 1
else if(loud)
to_chat(user, "<span class='notice'>\The [computer] flashes an \"Access Denied\" warning.</span>")
to_chat(user, SPAN_WARNING("The OS flashes an \"RFID Error - Unable to scan ID\" warning."))
return FALSE

if(has_access(accesses_to_check, I.access))
return TRUE
if(loud)
to_chat(user, SPAN_WARNING("The OS flashes an \"Access Denied\" warning."))
return FALSE

// This attempts to retrieve header data for NanoUIs. If implementing completely new device of different type than existing ones
// always include the device here in this proc. This proc basically relays the request to whatever is running the program.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
program_menu_icon = "flag"
nanomodule_path = /datum/nano_module/program/comm
extended_desc = "Used to command and control. Can relay long-range communications. This program can not be run on tablet computers."
required_access = access_bridge
required_access = list(access_bridge)
requires_network = 1
size = 12
usage_flags = PROGRAM_CONSOLE | PROGRAM_LAPTOP
Expand Down Expand Up @@ -109,7 +109,7 @@

/datum/nano_module/program/comm/proc/is_autenthicated(var/mob/user)
if(program)
return program.can_run(user)
return program.can_run(user, program.computer.get_network())
return 1

/datum/nano_module/program/comm/proc/obtain_message_listener()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
program_key_state = "atmos_key"
program_menu_icon = "shuffle"
extended_desc = "This program allows remote control of air alarms. This program can not be run on tablet computers."
required_access = access_atmospherics
required_access = list(access_atmospherics)
requires_network = 1
network_destination = "atmospheric control system"
requires_network_feature = NETWORK_SYSTEMCONTROL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
program_menu_icon = "battery-3"
extended_desc = "This program connects to sensors to provide information about electrical systems"
ui_header = "power_norm.gif"
required_access = access_engine
required_access = list(access_engine)
requires_network = 1
network_destination = "power monitoring system"
size = 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
program_key_state = "rd_key"
program_menu_icon = "power"
extended_desc = "This program allows remote control of power distribution systems. This program can not be run on tablet computers."
required_access = access_engine
required_access = list(access_engine)
network_destination = "RCON remote control system"
requires_network_feature = NETWORK_SYSTEMCONTROL
usage_flags = PROGRAM_LAPTOP | PROGRAM_CONSOLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
program_menu_icon = "notice"
extended_desc = "This program connects to specially calibrated supermatter sensors to provide information on the status of supermatter-based engines."
ui_header = "smmon_0.gif"
required_access = access_engine
required_access = list(access_engine)
network_destination = "supermatter monitoring system"
size = 5
category = PROG_ENG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
filename = "deckmngr"
filedesc = "Deck Management"
nanomodule_path = /datum/nano_module/deck_management
required_access = list(list(access_cargo, access_bridge))
program_icon_state = "request"
program_key_state = "rd_key"
program_menu_icon = "clock"
Expand All @@ -25,8 +26,6 @@
var/datum/computer_file/report/selected_report //A report being viewed/edited.
var/list/report_prototypes = list() //Stores report prototypes to use for UI purposes.
var/datum/shuttle/prototype_shuttle //The shuttle for which the prototypes were built (to avoid excessive prototype rebuilding)
//The default access needed to properly use. Should be set in map files.
var/default_access = list(access_cargo, access_bridge) //The format is (needs one of list(these access constants or lists of access constants))

/datum/nano_module/deck_management/New()
..()
Expand All @@ -45,7 +44,6 @@
var/logs = SSshuttle.shuttle_logs

data["prog_state"] = prog_state
data["default_access"] = get_default_access(user)

switch(prog_state)
if(DECK_HOME)
Expand Down Expand Up @@ -171,11 +169,6 @@
mission_data["queued"] = 1
return mission_data

/datum/nano_module/deck_management/proc/get_default_access(mob/user)
for(var/access_pattern in default_access)
if(check_access(user, access_pattern))
return 1

/datum/nano_module/deck_management/proc/get_shuttle_access(mob/user, datum/shuttle/shuttle)
return shuttle.logging_access ? (check_access(user, shuttle.logging_access) || check_access(user, access_bridge)) : 0

Expand Down Expand Up @@ -211,8 +204,6 @@
if(..())
return 1

if(!get_default_access(user))
return 1 //No program access if you don't have the right access.
if(text2num(href_list["warning"])) //Gives the user a chance to avoid losing unsaved reports.
if(alert(user, "Are you sure you want to do this? Data may be lost.",, "Yes.", "No.") == "No.")
return 1 //If yes, proceed to the actual action instead.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/datum/computer_file/program/docking
filename = "docking"
filedesc = "Docking Control"
<<<<<<< HEAD
required_access = access_bridge
nanomodule_path = /datum/nano_module/docking
=======
required_access = list(access_bridge)
nanomodule_path = /datum/nano_module/program/docking
>>>>>>> af4c29a77e... Merge pull request #1053 from NataKilar/network-fixes
program_icon_state = "supply"
program_key_state = "rd_key"
program_menu_icon = "triangle-2-e-w"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@
if(!network)
return TOPIC_REFRESH
// Helper for some user-friendliness. Try to select the first available mainframe.
var/list/file_servers = network.get_file_server_tags()
var/list/file_servers = network.get_file_server_tags(MF_ROLE_FILESERVER, user)
var/datum/file_storage/network/N = current_filesource
if(!file_servers.len)
N.server = null // Don't allow players to see files on mainframes they cannot access.
return TOPIC_REFRESH
var/datum/file_storage/network/N = current_filesource
N.server = file_servers[1]
return TOPIC_REFRESH

Expand Down Expand Up @@ -163,26 +164,26 @@
ui_header = null
return TOPIC_REFRESH

if(href_list["PRG_copyto"])
if(href_list["PRG_transferto"])
. = TOPIC_REFRESH
var/datum/computer_file/F = current_filesource.get_file(href_list["PRG_copyto"])
if(!F || !istype(F))
error = "I/O ERROR: Unable to open file."
var/datum/computer_file/F = current_filesource.get_file(href_list["PRG_transferto"])
if(!F || !istype(F) || F.unsendable)
error = "I/O ERROR: Unable to transfer file."
return
var/list/choices = list()
for(var/T in file_sources)
var/datum/file_storage/FS = file_sources[T]
if(FS == current_filesource)
continue
choices[FS.name] = FS
var/file_source = input(usr, "Choose a destination storage medium:", "Copy To Another Medium") as null|anything in choices
var/file_source = input(usr, "Choose a destination storage medium:", "Transfer To Another Medium") as null|anything in choices
if(file_source)
var/datum/file_storage/dst = choices[file_source]
var/nope = dst.check_errors()
if(nope)
to_chat(user, SPAN_WARNING("Cannot copy file to [dst] for following reason: [nope]"))
to_chat(user, SPAN_WARNING("Cannot transfer file to [dst] for following reason: [nope]"))
return
current_transfer = new(current_filesource, dst, F)
current_transfer = new(current_filesource, dst, F, FALSE)
ui_header = "downloader_running.gif"

/datum/computer_file/program/filemanager/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = GLOB.default_state)
Expand Down Expand Up @@ -215,7 +216,8 @@
"name" = F.filename,
"type" = F.filetype,
"size" = F.size,
"undeletable" = F.undeletable
"undeletable" = F.undeletable,
"unsendable" = F.unsendable
)))
data["files"] = files

Expand All @@ -239,12 +241,12 @@
if(QDELETED(current_transfer)) //either completely
error = "I/O ERROR: Unknown error during the file transfer."
else //or during the saving at the destination
error = "I/O ERROR: Unable to store '[current_transfer.copying.filename]' at [current_transfer.copying_to]"
error = "I/O ERROR: Unable to store '[current_transfer.transferring.filename]' at [current_transfer.transfer_to]"
qdel(current_transfer)
current_transfer = null
ui_header = null
return
else if(!current_transfer.left_to_copy) //done
else if(!current_transfer.left_to_transfer) //done
QDEL_NULL(current_transfer)
ui_header = null

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
source.server = net.find_file_location(filename, MF_ROLE_SOFTWARE)
if(source.check_errors() || destination.check_errors())
return 0
current_transfer = new(source, destination, PRG)
current_transfer = new(source, destination, PRG, TRUE)

ui_header = "downloader_running.gif"
generate_network_log("Downloading file [filename] from [source.server].")
Expand Down Expand Up @@ -77,11 +77,11 @@
if(QDELETED(current_transfer)) //either completely
downloaderror = "I/O ERROR: Unknown error during the file transfer."
else //or during the saving at the destination
downloaderror = "I/O ERROR: Unable to store '[current_transfer.copying.filename]' at [current_transfer.copying_to]"
downloaderror = "I/O ERROR: Unable to store '[current_transfer.transferring.filename]' at [current_transfer.transfer_to]"
qdel(current_transfer)
current_transfer = null
ui_header = "downloader_finished.gif"
else if(!current_transfer.left_to_copy) //done
else if(!current_transfer.left_to_transfer) //done
QDEL_NULL(current_transfer)
ui_header = "downloader_finished.gif"
if(!current_transfer && downloads_queue.len > 0)
Expand All @@ -94,7 +94,7 @@
if(href_list["PRG_downloadfile"])
if(!current_transfer)
begin_file_download(href_list["PRG_downloadfile"])
else if(check_file_download(href_list["PRG_downloadfile"]) && !downloads_queue.Find(href_list["PRG_downloadfile"]) && current_transfer.copying.filename != href_list["PRG_downloadfile"])
else if(check_file_download(href_list["PRG_downloadfile"]) && !downloads_queue.Find(href_list["PRG_downloadfile"]) && current_transfer.transferring.filename != href_list["PRG_downloadfile"])
downloads_queue |= href_list["PRG_downloadfile"]
return 1
if(href_list["PRG_removequeued"])
Expand Down Expand Up @@ -123,7 +123,7 @@
if(prog.current_transfer) // Download running. Wait please..
data |= prog.current_transfer.get_ui_data()
data["downloadspeed"] = prog.current_transfer.get_transfer_speed()
var/datum/computer_file/program/P = prog.current_transfer.copying
var/datum/computer_file/program/P = prog.current_transfer.transferring
if(istype(P))
data["transfer_desc"] = P.extended_desc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
channel = null
return 1
var/mob/living/user = usr
if(can_run(usr, 1, access_network))
if(can_run(usr, 1, list(access_network)))
if(channel)
var/response = alert(user, "Really engage admin-mode? You will be disconnected from your current channel!", "NTNRC Admin mode", "Yes", "No")
if(response == "Yes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
program_key_state = "med_key"
program_menu_icon = "heart"
extended_desc = "This program connects to life signs monitoring system to provide basic information on crew health."
required_access = access_medical
required_access = list(access_medical)
network_destination = "crew lifesigns monitoring system"
size = 11
category = PROG_MONITOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
program_menu_icon = "person"
extended_desc = "This program is capable of reconstructing damaged AI systems. It can also be used to upload basic laws to the AI. Requires direct AI connection via inteliCard slot."
size = 12
required_access = access_bridge
required_access = list(access_bridge)
requires_access_to_run = 0
available_on_network = 1
nanomodule_path = /datum/nano_module/program/computer_aidiag/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
requires_network = 1
available_on_network = 1
nanomodule_path = /datum/nano_module/program/email_administration
required_access = access_network
required_access = list(access_network)
category = PROG_ADMIN

/datum/nano_module/program/email_administration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GLOBAL_LIST(all_warrants)
program_menu_icon = "star"
requires_network = 1
available_on_network = 1
required_access = access_security
required_access = list(access_security)
nanomodule_path = /datum/nano_module/program/digitalwarrant/
category = PROG_SEC

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
program_menu_icon = "locked"
requires_network = 1
available_on_network = 1
required_access = access_armory
required_access = list(access_armory)
nanomodule_path = /datum/nano_module/program/forceauthorization/
category = PROG_SEC

Expand Down
Loading