[REVIEW] Ports Modular Computers from Baystation

This commit is contained in:
Neerti
2019-04-28 22:06:27 -04:00
committed by VirgoBot
parent 96669c91f0
commit 16b3b58259
242 changed files with 13200 additions and 6636 deletions
@@ -0,0 +1,65 @@
var/global/ntnrc_uid = 0
/datum/ntnet_conversation/
var/id = null
var/title = "Untitled Conversation"
var/datum/computer_file/program/chatclient/operator // "Administrator" of this channel. Creator starts as channel's operator,
var/list/messages = list()
var/list/clients = list()
var/password
/datum/ntnet_conversation/New()
id = ntnrc_uid
ntnrc_uid++
if(ntnet_global)
ntnet_global.chat_channels.Add(src)
..()
/datum/ntnet_conversation/proc/add_message(var/message, var/username)
message = "[stationtime2text()] [username]: [message]"
messages.Add(message)
trim_message_list()
/datum/ntnet_conversation/proc/add_status_message(var/message)
messages.Add("[stationtime2text()] -!- [message]")
trim_message_list()
/datum/ntnet_conversation/proc/trim_message_list()
if(messages.len <= 50)
return
messages.Cut(1, (messages.len-49))
/datum/ntnet_conversation/proc/add_client(var/datum/computer_file/program/chatclient/C)
if(!istype(C))
return
clients.Add(C)
add_status_message("[C.username] has joined the channel.")
// No operator, so we assume the channel was empty. Assign this user as operator.
if(!operator)
changeop(C)
/datum/ntnet_conversation/proc/remove_client(var/datum/computer_file/program/chatclient/C)
if(!istype(C) || !(C in clients))
return
clients.Remove(C)
add_status_message("[C.username] has left the channel.")
// Channel operator left, pick new operator
if(C == operator)
operator = null
if(clients.len)
var/datum/computer_file/program/chatclient/newop = pick(clients)
changeop(newop)
/datum/ntnet_conversation/proc/changeop(var/datum/computer_file/program/chatclient/newop)
if(istype(newop))
operator = newop
add_status_message("Channel operator status transferred to [newop.username].")
/datum/ntnet_conversation/proc/change_title(var/newtitle, var/datum/computer_file/program/chatclient/client)
if(operator != client)
return 0 // Not Authorised
add_status_message("[client.username] has changed channel title from [title] to [newtitle]")
title = newtitle
@@ -0,0 +1,184 @@
var/global/datum/ntnet/ntnet_global = new()
// This is the NTNet datum. There can be only one NTNet datum in game at once. Modular computers read data from this.
/datum/ntnet/
var/list/relays = list()
var/list/logs = list()
var/list/available_station_software = list()
var/list/available_antag_software = list()
var/list/available_news = list()
var/list/chat_channels = list()
var/list/fileservers = list()
var/list/email_accounts = list() // I guess we won't have more than 999 email accounts active at once in single round, so this will do until Servers are implemented someday.
var/list/banned_nids = list()
// Amount of logs the system tries to keep in memory. Keep below 999 to prevent byond from acting weirdly.
// High values make displaying logs much laggier.
var/setting_maxlogcount = 100
// These only affect wireless. LAN (consoles) are unaffected since it would be possible to create scenario where someone turns off NTNet, and is unable to turn it back on since it refuses connections
var/setting_softwaredownload = 1
var/setting_peertopeer = 1
var/setting_communication = 1
var/setting_systemcontrol = 1
var/setting_disabled = 0 // Setting to 1 will disable all wireless, independently on relays status.
var/intrusion_detection_enabled = 1 // Whether the IDS warning system is enabled
var/intrusion_detection_alarm = 0 // Set when there is an IDS warning due to malicious (antag) software.
// If new NTNet datum is spawned, it replaces the old one.
/datum/ntnet/New()
if(ntnet_global && (ntnet_global != src))
ntnet_global = src // There can be only one.
for(var/obj/machinery/ntnet_relay/R in machines)
relays.Add(R)
R.NTNet = src
build_software_lists()
build_news_list()
build_emails_list()
add_log("NTNet logging system activated.")
/datum/ntnet/proc/add_log_with_ids_check(var/log_string, var/obj/item/weapon/computer_hardware/network_card/source = null)
if(intrusion_detection_enabled)
add_log(log_string, source)
// Simplified logging: Adds a log. log_string is mandatory parameter, source is optional.
/datum/ntnet/proc/add_log(var/log_string, var/obj/item/weapon/computer_hardware/network_card/source = null)
var/log_text = "[stationtime2text()] - "
if(source)
log_text += "[source.get_network_tag()] - "
else
log_text += "*SYSTEM* - "
log_text += log_string
logs.Add(log_text)
if(logs.len > setting_maxlogcount)
// We have too many logs, remove the oldest entries until we get into the limit
for(var/L in logs)
if(logs.len > setting_maxlogcount)
logs.Remove(L)
else
break
/datum/ntnet/proc/check_banned(var/NID)
if(!relays || !relays.len)
return FALSE
for(var/obj/machinery/ntnet_relay/R in relays)
if(R.operable())
return (NID in banned_nids)
return FALSE
// Checks whether NTNet operates. If parameter is passed checks whether specific function is enabled.
/datum/ntnet/proc/check_function(var/specific_action = 0)
if(!relays || !relays.len) // No relays found. NTNet is down
return 0
var/operating = 0
// Check all relays. If we have at least one working relay, network is up.
for(var/obj/machinery/ntnet_relay/R in relays)
if(R.operable())
operating = 1
break
if(setting_disabled)
return 0
if(specific_action == NTNET_SOFTWAREDOWNLOAD)
return (operating && setting_softwaredownload)
if(specific_action == NTNET_PEERTOPEER)
return (operating && setting_peertopeer)
if(specific_action == NTNET_COMMUNICATION)
return (operating && setting_communication)
if(specific_action == NTNET_SYSTEMCONTROL)
return (operating && setting_systemcontrol)
return operating
// Builds lists that contain downloadable software.
/datum/ntnet/proc/build_software_lists()
available_station_software = list()
available_antag_software = list()
for(var/F in typesof(/datum/computer_file/program))
var/datum/computer_file/program/prog = new F
// Invalid type (shouldn't be possible but just in case), invalid filetype (not executable program) or invalid filename (unset program)
if(!prog || !istype(prog) || prog.filename == "UnknownProgram" || prog.filetype != "PRG")
continue
// Check whether the program should be available for station/antag download, if yes, add it to lists.
if(prog.available_on_ntnet)
available_station_software.Add(prog)
if(prog.available_on_syndinet)
available_antag_software.Add(prog)
// Builds lists that contain downloadable software.
/datum/ntnet/proc/build_news_list()
available_news = list()
for(var/F in typesof(/datum/computer_file/data/news_article/))
var/datum/computer_file/data/news_article/news = new F(1)
if(news.stored_data)
available_news.Add(news)
// Generates service email list. Currently only used by broadcaster service
/datum/ntnet/proc/build_emails_list()
for(var/F in subtypesof(/datum/computer_file/data/email_account/service))
new F()
// Attempts to find a downloadable file according to filename var
/datum/ntnet/proc/find_ntnet_file_by_name(var/filename)
for(var/datum/computer_file/program/P in available_station_software)
if(filename == P.filename)
return P
for(var/datum/computer_file/program/P in available_antag_software)
if(filename == P.filename)
return P
// Resets the IDS alarm
/datum/ntnet/proc/resetIDS()
intrusion_detection_alarm = 0
/datum/ntnet/proc/toggleIDS()
resetIDS()
intrusion_detection_enabled = !intrusion_detection_enabled
// Removes all logs
/datum/ntnet/proc/purge_logs()
logs = list()
add_log("-!- LOGS DELETED BY SYSTEM OPERATOR -!-")
// Updates maximal amount of stored logs. Use this instead of setting the number, it performs required checks.
/datum/ntnet/proc/update_max_log_count(var/lognumber)
if(!lognumber)
return 0
// Trim the value if necessary
lognumber = between(MIN_NTNET_LOGS, lognumber, MAX_NTNET_LOGS)
setting_maxlogcount = lognumber
add_log("Configuration Updated. Now keeping [setting_maxlogcount] logs in system memory.")
/datum/ntnet/proc/toggle_function(var/function)
if(!function)
return
function = text2num(function)
switch(function)
if(NTNET_SOFTWAREDOWNLOAD)
setting_softwaredownload = !setting_softwaredownload
add_log("Configuration Updated. Wireless network firewall now [setting_softwaredownload ? "allows" : "disallows"] connection to software repositories.")
if(NTNET_PEERTOPEER)
setting_peertopeer = !setting_peertopeer
add_log("Configuration Updated. Wireless network firewall now [setting_peertopeer ? "allows" : "disallows"] peer to peer network traffic.")
if(NTNET_COMMUNICATION)
setting_communication = !setting_communication
add_log("Configuration Updated. Wireless network firewall now [setting_communication ? "allows" : "disallows"] instant messaging and similar communication services.")
if(NTNET_SYSTEMCONTROL)
setting_systemcontrol = !setting_systemcontrol
add_log("Configuration Updated. Wireless network firewall now [setting_systemcontrol ? "allows" : "disallows"] remote control of station's systems.")
/datum/ntnet/proc/does_email_exist(var/login)
for(var/datum/computer_file/data/email_account/A in ntnet_global.email_accounts)
if(A.login == login)
return 1
return 0
@@ -0,0 +1,136 @@
// Relays don't handle any actual communication. Global NTNet datum does that, relays only tell the datum if it should or shouldn't work.
/obj/machinery/ntnet_relay
name = "NTNet Quantum Relay"
desc = "A very complex router and transmitter capable of connecting electronic devices together. Looks fragile."
use_power = 2
active_power_usage = 20000 //20kW, apropriate for machine that keeps massive cross-Zlevel wireless network operational.
idle_power_usage = 100
icon_state = "bus"
anchored = 1
density = 1
var/datum/ntnet/NTNet = null // This is mostly for backwards reference and to allow varedit modifications from ingame.
var/enabled = 1 // Set to 0 if the relay was turned off
var/dos_failure = 0 // Set to 1 if the relay failed due to (D)DoS attack
var/list/dos_sources = list() // Backwards reference for qdel() stuff
// Denial of Service attack variables
var/dos_overload = 0 // Amount of DoS "packets" in this relay's buffer
var/dos_capacity = 500 // Amount of DoS "packets" in buffer required to crash the relay
var/dos_dissipate = 1 // Amount of DoS "packets" dissipated over time.
// TODO: Implement more logic here. For now it's only a placeholder.
/obj/machinery/ntnet_relay/operable()
if(!..(EMPED))
return 0
if(dos_failure)
return 0
if(!enabled)
return 0
return 1
/obj/machinery/ntnet_relay/update_icon()
if(operable())
icon_state = "bus"
else
icon_state = "bus_off"
/obj/machinery/ntnet_relay/process()
if(operable())
use_power = 2
else
use_power = 1
if(dos_overload)
dos_overload = max(0, dos_overload - dos_dissipate)
// If DoS traffic exceeded capacity, crash.
if((dos_overload > dos_capacity) && !dos_failure)
dos_failure = 1
update_icon()
ntnet_global.add_log("Quantum relay switched from normal operation mode to overload recovery mode.")
// If the DoS buffer reaches 0 again, restart.
if((dos_overload == 0) && dos_failure)
dos_failure = 0
update_icon()
ntnet_global.add_log("Quantum relay switched from overload recovery mode to normal operation mode.")
..()
/obj/machinery/ntnet_relay/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1, var/datum/topic_state/state = default_state)
var/list/data = list()
data["enabled"] = enabled
data["dos_capacity"] = dos_capacity
data["dos_overload"] = dos_overload
data["dos_crashed"] = dos_failure
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "ntnet_relay.tmpl", "NTNet Quantum Relay", 500, 300, state = state)
ui.set_initial_data(data)
ui.open()
ui.set_auto_update(1)
/obj/machinery/ntnet_relay/attack_hand(var/mob/living/user)
ui_interact(user)
/obj/machinery/ntnet_relay/Topic(href, href_list)
if(..())
return 1
if(href_list["restart"])
dos_overload = 0
dos_failure = 0
update_icon()
ntnet_global.add_log("Quantum relay manually restarted from overload recovery mode to normal operation mode.")
return 1
else if(href_list["toggle"])
enabled = !enabled
ntnet_global.add_log("Quantum relay manually [enabled ? "enabled" : "disabled"].")
update_icon()
return 1
else if(href_list["purge"])
ntnet_global.banned_nids.Cut()
ntnet_global.add_log("Manual override: Network blacklist cleared.")
return 1
/obj/machinery/ntnet_relay/New()
uid = gl_uid
gl_uid++
component_parts = list()
component_parts += new /obj/item/stack/cable_coil(src,15)
component_parts += new /obj/item/weapon/circuitboard/ntnet_relay(src)
if(ntnet_global)
ntnet_global.relays.Add(src)
NTNet = ntnet_global
ntnet_global.add_log("New quantum relay activated. Current amount of linked relays: [NTNet.relays.len]")
..()
/obj/machinery/ntnet_relay/Destroy()
if(ntnet_global)
ntnet_global.relays.Remove(src)
ntnet_global.add_log("Quantum relay connection severed. Current amount of linked relays: [NTNet.relays.len]")
NTNet = null
for(var/datum/computer_file/program/ntnet_dos/D in dos_sources)
D.target = null
D.error = "Connection to quantum relay severed"
..()
/obj/machinery/ntnet_relay/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
if(W.is_screwdriver())
playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1)
panel_open = !panel_open
to_chat(user, "You [panel_open ? "open" : "close"] the maintenance hatch")
return
if(W.is_crowbar())
if(!panel_open)
to_chat(user, "Open the maintenance panel first.")
return
playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1)
to_chat(user, "You disassemble \the [src]!")
for(var/atom/movable/A in component_parts)
A.forceMove(src.loc)
new /obj/structure/frame(src.loc)
qdel(src)
return
..()
@@ -0,0 +1,82 @@
/datum/computer_file/data/email_account/
var/list/inbox = list()
var/list/spam = list()
var/list/deleted = list()
var/login = ""
var/password = ""
var/can_login = TRUE // Whether you can log in with this account. Set to false for system accounts
var/suspended = FALSE // Whether the account is banned by the SA.
/datum/computer_file/data/email_account/calculate_size()
size = 1
for(var/datum/computer_file/data/email_message/stored_message in all_emails())
stored_message.calculate_size()
size += stored_message.size
/datum/computer_file/data/email_account/New()
ntnet_global.email_accounts.Add(src)
..()
/datum/computer_file/data/email_account/Destroy()
ntnet_global.email_accounts.Remove(src)
. = ..()
/datum/computer_file/data/email_account/proc/all_emails()
return (inbox | spam | deleted)
/datum/computer_file/data/email_account/proc/send_mail(var/recipient_address, var/datum/computer_file/data/email_message/message, var/relayed = 0)
var/datum/computer_file/data/email_account/recipient
for(var/datum/computer_file/data/email_account/account in ntnet_global.email_accounts)
if(account.login == recipient_address)
recipient = account
break
if(!istype(recipient))
return 0
if(!recipient.receive_mail(message, relayed))
return
ntnet_global.add_log_with_ids_check("EMAIL LOG: [login] -> [recipient.login] title: [message.title].")
return 1
/datum/computer_file/data/email_account/proc/receive_mail(var/datum/computer_file/data/email_message/received_message, var/relayed)
received_message.set_timestamp()
if(!ntnet_global.intrusion_detection_enabled)
inbox.Add(received_message)
return 1
// Spam filters may occassionally let something through, or mark something as spam that isn't spam.
if(received_message.spam)
if(prob(98))
spam.Add(received_message)
else
inbox.Add(received_message)
else
if(prob(1))
spam.Add(received_message)
else
inbox.Add(received_message)
return 1
// Address namespace (@internal-services.nt) for email addresses with special purpose only!.
/datum/computer_file/data/email_account/service/
can_login = FALSE
/datum/computer_file/data/email_account/service/broadcaster/
login = "broadcast@internal-services.nt"
/datum/computer_file/data/email_account/service/broadcaster/receive_mail(var/datum/computer_file/data/email_message/received_message, var/relayed)
if(!istype(received_message) || relayed)
return 0
// Possibly exploitable for user spamming so keep admins informed.
if(!received_message.spam)
log_and_message_admins("Broadcast email address used by [usr]. Message title: [received_message.title].")
spawn(0)
for(var/datum/computer_file/data/email_account/email_account in ntnet_global.email_accounts)
var/datum/computer_file/data/email_message/new_message = received_message.clone()
send_mail(email_account.login, new_message, 1)
sleep(2)
return 1
@@ -0,0 +1,32 @@
// Currently not actually represented in file systems, though the support for it is in place already.
/datum/computer_file/data/email_message/
stored_data = ""
var/title = ""
var/source = ""
var/spam = FALSE
var/timestamp = ""
var/datum/computer_file/attachment = null
/datum/computer_file/data/email_message/clone()
var/datum/computer_file/data/email_message/temp = ..()
temp.title = title
temp.source = source
temp.spam = spam
temp.timestamp = timestamp
if(attachment)
temp.attachment = attachment.clone()
return temp
// Turns /email_message/ file into regular /data/ file.
/datum/computer_file/data/email_message/proc/export()
var/datum/computer_file/data/dat = new/datum/computer_file/data()
dat.stored_data = "Received from [source] at [timestamp]."
dat.stored_data += "\[b\][title]\[/b\]"
dat.stored_data += stored_data
dat.calculate_size()
return dat
/datum/computer_file/data/email_message/proc/set_timestamp()
timestamp = stationtime2text()