This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
faxmachine.dm
280 lines (239 loc) · 10 KB
/
faxmachine.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
GLOBAL_LIST_EMPTY(allfaxes)
GLOBAL_LIST_EMPTY(alldepartments)
/obj/machinery/photocopier/faxmachine
name = "fax machine"
icon = 'whitesands/icons/obj/library.dmi'
icon_state = "fax"
insert_anim = "faxsend"
density = FALSE
pixel_y = 4
///Animation played on recieving a fax
var/print_anim = "faxreceive"
///Fax network. Either local or CC quantum entanglement
var/fax_network = "Local Fax Network"
///If this can send faxes to centcom.
var/long_range_enabled = FALSE
req_one_access = list(ACCESS_LAWYER, ACCESS_HEADS, ACCESS_ARMORY)
use_power = TRUE
idle_power_usage = 30
active_power_usage = 200
///The person who authenticated it followed by their job
var/authenticated = FALSE
///Sending cooldown
var/sendcooldown = 0
///Time for every cooldown
var/cooldown_time = 1800
///The fax machine's department
var/department = "Unknown"
///The department we're sending to
var/destination
///Departments that just redirect to admins. Accessible by all long-range faxes.
var/list/static/admin_departments = list("Central Command")
///Departments that redirect to admins that are accessible by any emagged long-range faxes.
var/list/static/hidden_admin_departments = list("Syndicate")
/obj/machinery/photocopier/faxmachine/Initialize()
. = ..()
GLOB.allfaxes += src
if(!(("[department]" in GLOB.alldepartments) || ("[department]" in admin_departments)) && department != "Unknown")
LAZYADD(GLOB.alldepartments, department)
/obj/machinery/photocopier/faxmachine/longrange
name = "long range fax machine"
fax_network = "Central Command Quantum Entanglement Network"
long_range_enabled = TRUE
icon_state = "longfax"
insert_anim = "longfaxsend"
print_anim = "longfaxreceive"
/obj/machinery/photocopier/faxmachine/emag_act(mob/user)
if(!long_range_enabled)
to_chat(user, "<span class='warning'>You swipe the card through [src], but nothing happens. This doesn't seem to be a powerful enough fax...</span>")
return
if(obj_flags & EMAGGED)
to_chat(user, "<span class='warning'>You swipe the card through [src], but nothing happens.</span>")
return
obj_flags |= EMAGGED
to_chat(user, "<span class='notice'>The transmitters realign to an unknown source!</span>")
/obj/machinery/photocopier/faxmachine/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "FaxMachine")
ui.open()
/obj/machinery/photocopier/faxmachine/ui_data(mob/user)
var/data = ..()
var/is_authenticated = is_authenticated(user)
data["authenticated"] = authenticated
data["network"] = is_authenticated ? fax_network : null
if(obj_flags & EMAGGED)
data["network"] = "ERR*?*%!*"
if(paper_copy)
data["paper"] = paper_copy.name
data["paperinserted"] = TRUE
else if(photo_copy)
data["paper"] = photo_copy.name
data["paperinserted"] = TRUE
else if(document_copy)
data["paper"] = document_copy.name
data["paperinserted"] = TRUE
else
data["paper"] = "-----"
data["paperinserted"] = FALSE
data["destination"] = destination ? destination : "Not Selected"
data["cooldown"] = sendcooldown
if((destination in admin_departments) || (destination in hidden_admin_departments))
data["respectcooldown"] = TRUE
else
data["respectcooldown"] = FALSE
return data
/obj/machinery/photocopier/faxmachine/ui_act(action, params)
. = ..()
if (.)
return
var/is_authenticated = is_authenticated(usr)
switch(action)
if("send")
if((paper_copy || photo_copy || document_copy) && is_authenticated)
if((destination in admin_departments) || (destination in hidden_admin_departments))
send_admin_fax(usr, destination)
else
sendfax(destination,usr)
if(sendcooldown)
addtimer(CALLBACK(src, .proc/handle_cooldown, action, params), sendcooldown)
if("paper")
if(paper_copy)
remove_photocopy(paper_copy, usr)
paper_copy = null
else if(photo_copy)
remove_photocopy(photo_copy, usr)
photo_copy = null
else if(document_copy)
remove_photocopy(document_copy, usr)
document_copy = null
else
attackby(usr.get_active_held_item(), usr)
if("dept")
if(is_authenticated)
var/lastdestination = destination
var/list/combineddepartments = GLOB.alldepartments.Copy()
if(long_range_enabled)
combineddepartments += admin_departments.Copy()
if(obj_flags & EMAGGED)
combineddepartments += hidden_admin_departments.Copy()
destination = input(usr, "To which department?", "Choose a department", "") as null|anything in combineddepartments
if(!destination)
destination = lastdestination
if("auth")
if(!is_authenticated)
if(check_access(usr.get_idcard(FALSE)))
var/obj/item/card/id/I = usr.get_idcard(FALSE)
authenticated = "[I.registered_name] ([I.assignment])"
else if(is_authenticated)
authenticated = null
if("rename")
if(paper_copy || photo_copy)
var/obj/to_rename = paper_copy ? paper_copy : photo_copy
var/n_name = sanitize(copytext(input(usr, "What would you like to label the fax?", "Fax Labelling", to_rename.name) as text, 1, MAX_MESSAGE_LEN))
if(usr.stat == 0)
to_rename.name = "[(n_name ? text("[n_name]") : to_rename.name)]"
/obj/machinery/photocopier/faxmachine/proc/handle_cooldown(action, params)
sendcooldown = 0
/obj/machinery/photocopier/faxmachine/proc/is_authenticated(mob/user)
if(authenticated)
return TRUE
else if(IsAdminGhost(user))
return TRUE
return FALSE
/obj/machinery/photocopier/faxmachine/proc/sendfax(destination, mob/sender)
if(machine_stat & (BROKEN|NOPOWER))
return
if(!length(paper_copy?.info)) //doesn't get called if there's no paper inserted
visible_message("<span class='notice'>[src] beeps, \"The supplied paper is blank. Aborting.\"</span>")
return FALSE
use_power(200)
var/success = FALSE
var/obj/to_send = paper_copy ? paper_copy : photo_copy ? photo_copy : document_copy
for(var/thing in GLOB.allfaxes)
var/obj/machinery/photocopier/faxmachine/F = thing
if(F.department == destination)
success = F.receivefax(to_send)
if(success != FALSE && department != destination)
var/datum/fax/F = new /datum/fax()
F.name = to_send.name
F.from_department = department
F.to_department = destination
F.origin = src
F.message = to_send
F.sent_by = sender
F.sent_at = world.time
visible_message("<span class='notice'>[src] beeps, \"Message transmitted successfully.\"</span>")
else if(destination == department)
visible_message("<span class='notice'>[src] beeps, \"Error transmitting message. [src] cannot send faxes to itself.\"</span>")
else if(destination == "Not Selected")
visible_message("<span class='notice'>[src] beeps, \"Error transmitting message. Select a destination.\"</span>")
else if(destination == "Unknown")
visible_message("<span class='notice'>[src] beeps, \"Error transmitting message. Cannot transmit to Unknown.\"</span>")
else
visible_message("<span class='notice'>[src] beeps, \"Error transmitting message.\"</span>")
/obj/machinery/photocopier/faxmachine/proc/receivefax(obj/item/incoming)
if(machine_stat & (BROKEN|NOPOWER))
return FALSE
if(department == "Unknown" || department == destination)
return FALSE //You can't send faxes to "Unknown" or yourself
addtimer(CALLBACK(src, .proc/handle_copying, incoming), 10)
/obj/machinery/photocopier/faxmachine/do_copy_loop(datum/callback/copy_cb, mob/user, obj/item/tocopy)
..()
handle_animation()
//Prevents copypasta for evil faxes
/obj/machinery/photocopier/faxmachine/proc/handle_animation()
flick(print_anim, src)
playsound(loc, 'goon/sound/machinery/printer_dotmatrix.ogg', 50, 1)
/obj/machinery/photocopier/faxmachine/proc/handle_copying(obj/item/incoming)
use_power(active_power_usage)
if(istype(incoming, /obj/item/paper))
if(istype(incoming, /obj/item/paper/contract/employment))
do_copy_loop(CALLBACK(src, .proc/make_devil_paper_copy, incoming), usr, TRUE)
return TRUE
do_copy_loop(CALLBACK(src, .proc/make_paper_copy, incoming), usr, TRUE)
else if(istype(incoming, /obj/item/photo))
do_copy_loop(CALLBACK(src, .proc/make_photo_copy, incoming), usr, TRUE)
else if(istype(incoming, /obj/item/documents))
do_copy_loop(CALLBACK(src, .proc/make_document_copy, incoming), usr, TRUE)
else
return FALSE
return TRUE
/obj/machinery/photocopier/faxmachine/proc/send_admin_fax(mob/sender, destination)
if(machine_stat & (BROKEN|NOPOWER))
return
if(sendcooldown)
return
use_power(200)
var/obj/item/to_send
if(paper_copy)
to_send = make_paper_copy()
else if(photo_copy)
to_send = make_photo_copy()
else if(document_copy)
to_send = make_document_copy()
to_send.moveToNullspace()
var/datum/fax/admin/A = new /datum/fax/admin()
A.name = to_send.name
A.from_department = department
A.to_department = destination
A.origin = src
A.message = to_send
A.sent_by = sender
A.sent_at = world.time
//message badmins that a fax has arrived
switch(destination)
if("Central Command")
send_to_admins(sender, "CENTCOM FAX", destination, to_send, "#006100")
if("Syndicate")
send_to_admins(sender, "SYNDICATE FAX", destination, to_send, "#DC143C")
sendcooldown = cooldown_time
visible_message("<span class='notice'>[src] beeps, \"Message transmitted successfully.\"</span>")
/obj/machinery/photocopier/faxmachine/proc/send_to_admins(mob/sender, faxname, faxtype, obj/item/sent, font_colour="#9A04D1")
var/msg = "<span class='boldnotice'><font color='[font_colour]'>[faxname]: </font> [ADMIN_LOOKUP(sender)] | REPLY: [ADMIN_CENTCOM_REPLY(sender)] [ADMIN_FAX(sender, src, faxtype, sent)] [ADMIN_SM(sender)] | REJECT: (<A HREF='?_src_=holder;[HrefToken(TRUE)];FaxReplyTemplate=[REF(sender)];originfax=[REF(src)]'>TEMPLATE</A>) [ADMIN_SMITE(sender)] (<A HREF='?_src_=holder;[HrefToken(TRUE)];EvilFax=[REF(sender)];originfax=[REF(src)]'>EVILFAX</A>) </span>: Receiving '[sent.name]' via secure connection... <a href='?_src_=holder;[HrefToken(TRUE)];AdminFaxView=[REF(sent)]'>view message</a>"
if(istype(sent, /obj/item/paper))
var/obj/item/paper/paper = sent
SSredbot.send_discord_message("admin", "New [faxname] ([paper.name]) Sent by [sender]: [strip_booktext(paper.info, 30)]")
else
SSredbot.send_discord_message("admin", "New [faxname] ([sent.name]) Sent by [sender].")
message_admins(msg)