/******************** Requests Console ********************/
/** Originally written by errorage, updated by: Carn, needs more work though. I just added some security fixes */
//Requests Console Department Types
#define RC_ASSIST 1 //Request Assistance
#define RC_SUPPLY 2 //Request Supplies
#define RC_INFO 4 //Relay Info
//Requests Console Screens
#define RCS_MAINMENU 0 // Main menu
#define RCS_RQASSIST 1 // Request supplies
#define RCS_RQSUPPLY 2 // Request assistance
#define RCS_SENDINFO 3 // Relay information
#define RCS_SENTPASS 4 // Message sent successfully
#define RCS_SENTFAIL 5 // Message sent unsuccessfully
#define RCS_VIEWMSGS 6 // View messages
#define RCS_MESSAUTH 7 // Authentication before sending
#define RCS_ANNOUNCE 8 // Send announcement
#define RCS_FORMS 9 // Forms database
var/req_console_assistance = list()
var/req_console_supplies = list()
var/req_console_information = list()
var/list/obj/machinery/requests_console/allConsoles = list()
/obj/machinery/requests_console
name = "Requests Console"
desc = "A console intended to send requests to different departments on the station."
icon = 'icons/obj/terminals.dmi'
icon_state = "req_comp"
component_types = list(
/obj/item/circuitboard/requestconsole,
/obj/item/stock_parts/capacitor,
/obj/item/stock_parts/console_screen,
)
anchored = TRUE
appearance_flags = TILE_BOUND // prevents people from viewing the overlay through a wall
var/department = "Unknown" //The list of all departments on the station (Determined from this variable on each unit) Set this to the same thing if you want several consoles in one department
var/list/message_log = list() //List of all messages
var/departmentType = 0 //Bitflag. Zero is reply-only. Map currently uses raw numbers instead of defines.
var/newmessagepriority = 0
// 0 = no new message
// 1 = normal priority
// 2 = high priority
var/screen = RCS_MAINMENU
var/silent = 0 // set to 1 for it not to beep all the time
// var/hackState = 0
// 0 = not hacked
// 1 = hacked
var/announcementConsole = 0
// 0 = This console cannot be used to send department announcements
// 1 = This console can send department announcementsf
var/open = 0 // 1 if open
var/announceAuth = 0 //Will be set to 1 when you authenticate yourself for announcements
var/msgVerified = "" //Will contain the name of the person who varified it
var/msgStamped = "" //If a message is stamped, this will contain the stamp name
var/message = "";
var/recipient = ""; //the department which will be receiving the message
var/priority = -1 ; //Priority of the message being sent
//Form intregration
var/SQLquery
var/paperstock = 10
var/lid = 0
//End Form Integration
var/datum/announcement/announcement = new
var/list/obj/item/device/pda/alert_pdas = list() //The PDAs we alert upon a request receipt.
var/global/list/screen_overlays
/obj/machinery/requests_console/proc/generate_overlays(var/force = 0)
if(LAZYLEN(screen_overlays) && !force)
return
LAZYINITLIST(screen_overlays)
screen_overlays["req_comp-idle"] = make_screen_overlay(icon, "req_comp-idle")
screen_overlays["req_comp-alert"] = make_screen_overlay(icon, "req_comp-alert")
screen_overlays["req_comp-redalert"] = make_screen_overlay(icon, "req_comp-redalert")
screen_overlays["req_comp-yellowalert"] = make_screen_overlay(icon, "req_comp-yellowalert")
screen_overlays["req_comp-scanline"] = make_screen_overlay(icon, "req_comp-scanline")
/obj/machinery/requests_console/power_change()
..()
update_icon()
/obj/machinery/requests_console/update_icon()
cut_overlays()
if(stat & NOPOWER)
icon_state = initial(icon_state)
set_light(FALSE)
else
switch(newmessagepriority)
if(0)
add_overlay(screen_overlays["req_comp-idle"])
set_light(1.4, 1, COLOR_CYAN)
if(1)
add_overlay(screen_overlays["req_comp-alert"])
set_light(1.4, 1, COLOR_CYAN)
if(2)
add_overlay(screen_overlays["req_comp-redalert"])
set_light(1.4, 1, COLOR_ORANGE)
if(3)
add_overlay(screen_overlays["req_comp-yellowalert"])
set_light(1.4, 1, COLOR_ORANGE)
add_overlay(screen_overlays["req_comp-scanline"])
/obj/machinery/requests_console/Initialize(mapload, var/dir, var/building = 0)
. = ..()
if(building)
if(dir)
src.set_dir(dir)
pixel_x = (dir & 3)? 0 : (dir == 4 ? -24 : 24)
pixel_y = (dir & 3)? (dir ==1 ? -24 : 24) : 0
update_icon()
return
announcement.title = "[department] announcement"
announcement.newscast = 1
name = "[department] Requests Console"
allConsoles += src
if (departmentType & RC_ASSIST)
req_console_assistance |= department
if (departmentType & RC_SUPPLY)
req_console_supplies |= department
if (departmentType & RC_INFO)
req_console_information |= department
generate_overlays()
update_icon()
/obj/machinery/requests_console/Destroy()
allConsoles -= src
var/lastDeptRC = 1
for (var/obj/machinery/requests_console/Console in allConsoles)
if (Console.department == department)
lastDeptRC = 0
break
if(lastDeptRC)
if (departmentType & RC_ASSIST)
req_console_assistance -= department
if (departmentType & RC_SUPPLY)
req_console_supplies -= department
if (departmentType & RC_INFO)
req_console_information -= department
if (LAZYLEN(alert_pdas))
for (var/pp in alert_pdas)
var/obj/item/device/pda/P = pp
P.linked_consoles -= src
alert_pdas.Cut()
return ..()
/obj/machinery/requests_console/attack_hand(user as mob)
if(..(user))
return
ui_interact(user)
/obj/machinery/requests_console/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
var/data[0]
data["department"] = department
data["screen"] = screen
data["message_log"] = message_log
data["newmessagepriority"] = newmessagepriority
data["silent"] = silent
data["announcementConsole"] = announcementConsole
data["assist_dept"] = req_console_assistance
data["supply_dept"] = req_console_supplies
data["info_dept"] = req_console_information
data["message"] = message
data["recipient"] = recipient
data["priortiy"] = priority
data["msgStamped"] = msgStamped
data["msgVerified"] = msgVerified
data["announceAuth"] = announceAuth
if (screen == RCS_FORMS)
if (!establish_db_connection(dbcon))
data["sql_error"] = 1
else
if (!SQLquery)
SQLquery = "SELECT id, name, department FROM ss13_forms ORDER BY id"
var/DBQuery/query = dbcon.NewQuery(SQLquery)
query.Execute()
var/list/forms = list()
while (query.NextRow())
forms += list(list("id" = query.item[1], "name" = query.item[2], "department" = query.item[3]))
if (!forms.len)
data["sql_error"] = 1
data["forms"] = forms
data["pda_list"] = list()
for (var/A in alert_pdas)
var/obj/item/device/pda/pda = A
data["pda_list"] += list(list("name" = alert_pdas[pda], "pda" = "\ref[pda]"))
data["lid"] = lid
data["paper"] = paperstock
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
if (!ui)
ui = new(user, src, ui_key, "requests_console.tmpl", "[department] Requests Console", 520, 410)
ui.set_initial_data(data)
ui.open()
/obj/machinery/requests_console/Topic(href, href_list)
if(..()) return
usr.set_machine(src)
add_fingerprint(usr)
if(reject_bad_text(href_list["write"]))
recipient = href_list["write"] //write contains the string of the receiving department's name
var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
if(new_message)
message = new_message
screen = RCS_MESSAUTH
switch(href_list["priority"])
if("1") priority = 1
if("2") priority = 2
else priority = 0
else
reset_message(1)
if(href_list["writeAnnouncement"])
var/new_message = sanitize(input("Write your message:", "Awaiting Input", ""))
if(new_message)
message = new_message
else
reset_message(1)
if(href_list["sendAnnouncement"])
if(!announcementConsole) return
announcement.Announce(message, msg_sanitized = 1)
reset_message(1)
if( href_list["department"] && message )
var/log_msg = message
var/pass = 0
screen = RCS_SENTFAIL
for (var/obj/machinery/message_server/MS in SSmachinery.processing_machines)
if(!MS.active) continue
MS.send_rc_message(ckey(href_list["department"]),department,log_msg,msgStamped,msgVerified,priority)
pass = 1
if(pass)
screen = RCS_SENTPASS
message_log += "Message sent to [recipient]
[message]"
else
audible_message(text("[icon2html(src, viewers(get_turf(src)))] *The Requests Console beeps: 'NOTICE: No server detected!'"),,4)
//Handle screen switching
if(href_list["setScreen"])
var/tempScreen = text2num(href_list["setScreen"])
if(tempScreen == RCS_ANNOUNCE && !announcementConsole)
return
if(tempScreen == RCS_VIEWMSGS)
for (var/obj/machinery/requests_console/Console in allConsoles)
if (Console.department == department)
Console.newmessagepriority = 0
Console.icon_state = "req_comp0"
Console.set_light(0)
if(tempScreen == RCS_MAINMENU)
reset_message()
screen = tempScreen
//Handle silencing the console
if(href_list["toggleSilent"])
silent = !silent
// Link a PDA
if(href_list["linkpda"])
var/obj/item/device/pda/pda = usr.get_active_hand()
if (!pda || !istype(pda))
to_chat(usr, "You need to be holding a PDA to link it.")
else if (pda in alert_pdas)
to_chat(usr, "\The [pda] appears to be already linked.")
//Update the name real quick.
alert_pdas[pda] = pda.name
else
LAZYADD(pda.linked_consoles, src)
alert_pdas += pda
alert_pdas[pda] = pda.name
to_chat(usr, "You link \the [pda] to \the [src]. It will now ping upon the arrival of a fax to this machine.")
// Unlink a PDA.
if(href_list["unlink"])
var/obj/item/device/pda/pda = locate(href_list["unlink"])
if (pda && istype(pda))
if (pda in alert_pdas)
to_chat(usr, "You unlink [alert_pdas[pda]] from \the [src]. It will no longer be notified of new faxes.")
alert_pdas -= pda
// Sort the forms.
if(href_list["sort"])
var/sortdep = sanitizeSQL(href_list["sort"])
SQLquery = "SELECT id, name, department FROM ss13_forms WHERE department LIKE '%[sortdep]%' ORDER BY id"
if (href_list["resetSQL"])
SQLquery = "SELECT id, name, department FROM ss13_forms ORDER BY id"
// Print a form.
if(href_list["print"])
var/printid = sanitizeSQL(href_list["print"])
establish_db_connection(dbcon)
if(!dbcon.IsConnected())
alert("Connection to the database lost. Aborting.")
if(!printid)
alert("Invalid query. Try again.")
var/DBQuery/query = dbcon.NewQuery("SELECT id, name, data FROM ss13_forms WHERE id=[printid]")
query.Execute()
while(query.NextRow())
var/id = query.item[1]
var/name = query.item[2]
var/data = query.item[3]
var/obj/item/paper/C = new()
C.color = "#fff9e8"
//Let's start the BB >> HTML conversion!
data = html_encode(data)
C.set_content("NFC-[id] - [name]", data)
print(C)
paperstock--
// Get extra information about the form.
if(href_list["whatis"])
var/whatisid = sanitizeSQL(href_list["whatis"])
establish_db_connection(dbcon)
if(!dbcon.IsConnected())
alert("Connection to the database lost. Aborting.")
if(!whatisid)
alert("Invalid query. Try again.")
var/DBQuery/query = dbcon.NewQuery("SELECT id, name, department, info FROM ss13_forms WHERE id=[whatisid]")
query.Execute()
var/dat = "