Merge pull request #14176 from Kyep/tgui_keycard_auth

[TGUI] Keycard Swiper
This commit is contained in:
AffectedArc07
2020-09-15 20:43:01 +01:00
committed by GitHub
4 changed files with 204 additions and 97 deletions
@@ -4,17 +4,17 @@
icon = 'icons/obj/monitors.dmi'
icon_state = "auth_off"
var/active = 0 //This gets set to 1 on all devices except the one where the initial request was made.
var/event = ""
var/screen = 1
var/active = FALSE // This gets set to TRUE on all devices except the one where the initial request was made.
var/event
var/swiping = FALSE // on swiping screen?
var/list/ert_chosen = list()
var/confirmed = 0 //This variable is set by the device that confirms the request.
var/confirm_delay = 20 //(2 seconds)
var/busy = 0 //Busy when waiting for authentication or an event request has been sent from this device.
var/confirmed = FALSE // This variable is set by the device that confirms the request.
var/confirm_delay = 5 SECONDS // time allowed for a second person to confirm a swipe.
var/busy = FALSE // Busy when waiting for authentication or an event request has been sent from this device.
var/obj/machinery/keycard_auth/event_source
var/mob/event_triggered_by
var/mob/event_confirmed_by
var/ert_reason = "Reason for ERT"
var/ert_reason
anchored = 1
use_power = IDLE_POWER_USE
@@ -35,16 +35,19 @@
return
if(istype(W, /obj/item/card/id) || istype(W, /obj/item/pda))
if(check_access(W))
if(active == 1)
if(active)
//This is not the device that made the initial request. It is the device confirming the request.
if(event_source)
event_source.confirmed = 1
event_source.confirmed = TRUE
event_source.event_confirmed_by = usr
else if(screen == 2)
if(event == "Emergency Response Team" && ert_reason == "Reason for ERT")
to_chat(user, "<span class='notice'>Supply a reason for calling the ERT first!</span>")
SStgui.update_uis(event_source)
SStgui.update_uis(src)
else if(swiping)
if(event == "Emergency Response Team" && !ert_reason)
to_chat(user, "<span class='warning'>Supply a reason for calling the ERT first!</span>")
return
event_triggered_by = usr
SStgui.update_uis(src)
broadcast_request() //This is the device making the initial event request. It needs to broadcast to other devices
else
to_chat(user, "<span class='warning'>Access denied.</span>")
@@ -59,57 +62,58 @@
stat |= NOPOWER
/obj/machinery/keycard_auth/attack_ghost(mob/user)
ui_interact(user)
tgui_interact(user)
/obj/machinery/keycard_auth/attack_hand(mob/user as mob)
/obj/machinery/keycard_auth/attack_hand(mob/user)
if(..())
return 1
ui_interact(user)
return TRUE
tgui_interact(user)
/obj/machinery/keycard_auth/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
if(busy)
to_chat(user, "This device is busy.")
return
user.set_machine(src)
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, force_open)
/obj/machinery/keycard_auth/tgui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = TRUE, datum/tgui/master_ui = null, datum/tgui_state/state = GLOB.tgui_default_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "keycard_auth.tmpl", "Keycard Authentication Device UI", 540, 320)
ui = new(user, src, ui_key, "KeycardAuth", name, 540, 300, master_ui, state)
ui.open()
/obj/machinery/keycard_auth/ui_data(mob/user, ui_key = "main", datum/topic_state/state = GLOB.default_state)
var/data[0]
data["screen"] = screen
data["event"] = event
data["ertreason"] = ert_reason
/obj/machinery/keycard_auth/tgui_data()
var/list/data = list()
data["redAvailable"] = GLOB.security_level == SEC_LEVEL_RED ? FALSE : TRUE
data["swiping"] = swiping
data["busy"] = busy
data["event"] = active && event_source && event_source.event ? event_source.event : event
data["ertreason"] = active && event_source && event_source.ert_reason ? event_source.ert_reason : ert_reason
data["isRemote"] = active ? TRUE : FALSE
data["hasSwiped"] = event_triggered_by ? TRUE : FALSE
data["hasConfirm"] = event_confirmed_by || (active && event_source && event_source.event_confirmed_by) ? TRUE : FALSE
return data
/obj/machinery/keycard_auth/Topic(href, href_list)
/obj/machinery/keycard_auth/tgui_act(action, params)
if(..())
return 1
if(busy)
to_chat(usr, "This device is busy.")
return
if(busy)
to_chat(usr, "<span class='warning'>This device is busy.</span>")
return
if(!allowed(usr))
to_chat(usr, "<span class='warning'>Access denied.</span>")
return
. = TRUE
switch(action)
if("ert")
ert_reason = stripped_input(usr, "Reason for ERT Call:", "", "")
if("reset")
reset()
if("triggerevent")
event = params["triggerevent"]
swiping = TRUE
if(href_list["triggerevent"])
event = href_list["triggerevent"]
screen = 2
if(href_list["reset"])
reset()
if(href_list["ert"])
ert_reason = stripped_input(usr, "Reason for ERT Call:", "", "")
SSnanoui.update_uis(src)
add_fingerprint(usr)
return
/obj/machinery/keycard_auth/proc/reset()
active = 0
event = ""
screen = 1
confirmed = 0
active = FALSE
event = null
swiping = FALSE
confirmed = FALSE
event_source = null
icon_state = "auth_off"
event_triggered_by = null
@@ -125,7 +129,7 @@
sleep(confirm_delay)
if(confirmed)
confirmed = 0
confirmed = FALSE
trigger_event(event)
log_game("[key_name(event_triggered_by)] triggered and [key_name(event_confirmed_by)] confirmed event [event]")
message_admins("[key_name_admin(event_triggered_by)] triggered and [key_name_admin(event_confirmed_by)] confirmed event [event]", 1)
@@ -135,16 +139,17 @@
if(stat & (BROKEN|NOPOWER))
return
event_source = source
busy = 1
active = 1
busy = TRUE
active = TRUE
SStgui.update_uis(src)
icon_state = "auth_on"
sleep(confirm_delay)
event_source = null
icon_state = "auth_off"
active = 0
busy = 0
active = FALSE
busy = FALSE
/obj/machinery/keycard_auth/proc/trigger_event()
switch(event)
@@ -178,7 +183,7 @@
if(fullmin_count)
GLOB.ert_request_answered = TRUE
ERT_Announce(ert_reason , event_triggered_by, 0)
ert_reason = "Reason for ERT"
ert_reason = null
feedback_inc("alert_keycard_auth_ert",1)
spawn(3000)
if(!GLOB.ert_request_answered)
-39
View File
@@ -1,39 +0,0 @@
<!--
Title: Keycard Authentication Device UI
Used In File(s): \code\modules\security_levels\keycard_authentication.dm
-->
<style type="text/css">
.event {
font-size: 16px;
font-weight: bold;
margin-bottom: 15px;
text-align: center;
}
</style>
<div class="item">
<h1>Keycard Authentication Device</h1>
This device is used to trigger certain high security events. It requires the simultaneous swipe of two high-level ID cards.
<div class="item">
{{if data.screen == 1}}
<h2>Trigger Event</h2>
{{:helper.link('Red Alert', 'exclamation-triangle', { 'triggerevent' : 'Red Alert' })}}
{{:helper.link('Emergency Response Team', 'exclamation-triangle', { 'triggerevent' : 'Emergency Response Team' })}}
{{:helper.link('Grant Emergency Maintenance Access', 'unlock', { 'triggerevent' : 'Grant Emergency Maintenance Access' })}}
{{:helper.link('Revoke Emergency Maintenance Access', 'lock', { 'triggerevent' : 'Revoke Emergency Maintenance Access' })}}
{{:helper.link('Activate Station-Wide Emergency Access', 'unlock', { 'triggerevent' : 'Activate Station-Wide Emergency Access' })}}
{{:helper.link('Deactivate Station-Wide Emergency Access', 'lock', { 'triggerevent' : 'Deactivate Station-Wide Emergency Access' })}}
{{else data.screen == 2}}
{{if data.event == 'Emergency Response Team'}}
<div class="item">
<div class="itemLabel">Reason for ERT Call:</div>
<div class="itemContent">
{{:helper.link(data.ertreason, 'exclamation-triangle', { 'ert' : 'callreason' })}}
</div>
</div>
{{/if}}
<h2 class="bad" style="text-align: center;">Please swipe your card to authorize the following event:</h2>
<div class="event">{{:data.event}}</div>
{{:helper.link('Back', 'close', { 'reset' : 1 })}}
{{/if}}
</div>
</div>
@@ -0,0 +1,141 @@
import { Fragment } from 'inferno';
import { useBackend } from '../backend';
import { Box, Button, Section, LabeledList } from '../components';
import { Window } from '../layouts';
export const KeycardAuth = (props, context) => {
const { act, data } = useBackend(context);
let infoBox = (
<Section title="Keycard Authentication Device">
<Box>
This device is used to trigger certain high security events.
It requires the simultaneous swipe of two high-level ID cards.
</Box>
</Section>
);
if (!data.swiping && !data.busy) {
return (
<Window>
<Window.Content>
{infoBox}
<Section title="Choose Action">
<LabeledList>
<LabeledList.Item
label="Red Alert">
<Button
icon="exclamation-triangle"
disabled={!data.redAvailable}
onClick={() => act('triggerevent',
{ 'triggerevent': 'Red Alert' })}
content="Red Alert" />
</LabeledList.Item>
<LabeledList.Item label="ERT">
<Button
icon="broadcast-tower"
onClick={() => act('triggerevent',
{ 'triggerevent': 'Emergency Response Team' })}
content="Call ERT" />
</LabeledList.Item>
<LabeledList.Item label="Emergency Maint Access">
<Button
icon="door-open"
onClick={() => act('triggerevent',
{ 'triggerevent':
'Grant Emergency Maintenance Access' })}
content="Grant" />
<Button
icon="door-closed"
onClick={() => act('triggerevent',
{ 'triggerevent':
'Revoke Emergency Maintenance Access' })}
content="Revoke" />
</LabeledList.Item>
<LabeledList.Item label="Emergency Station-Wide Access">
<Button
icon="door-open"
onClick={() => act('triggerevent',
{ 'triggerevent':
'Activate Station-Wide Emergency Access' })}
content="Grant" />
<Button
icon="door-closed"
onClick={() => act('triggerevent',
{ 'triggerevent':
'Deactivate Station-Wide Emergency Access' })}
content="Revoke" />
</LabeledList.Item>
</LabeledList>
</Section>
</Window.Content>
</Window>
);
} else {
let swipeInfo = (
<Box color="red">
Waiting for YOU to swipe your ID...
</Box>
);
if (!data.hasSwiped && !data.ertreason
&& data.event === "Emergency Response Team") {
swipeInfo = (
<Box color="red">
Fill out the reason for your ERT request.
</Box>
);
} else if (data.hasConfirm) {
swipeInfo = (
<Box color="green">
Request Confirmed!
</Box>
);
} else if (data.isRemote) {
swipeInfo = (
<Box color="orange">
Swipe your card to CONFIRM the remote request.
</Box>
);
} else if (data.hasSwiped) {
swipeInfo = (
<Box color="orange">
Waiting for second person to confirm...
</Box>
);
}
return (
<Window>
<Window.Content>
{infoBox}
{data.event === 'Emergency Response Team' && (
<Section title="Reason for ERT Call">
<Box>
<Button
color={data.ertreason
? ""
: "red"}
icon={data.ertreason
? "check"
: "pencil-alt"}
content={data.ertreason
? data.ertreason
: "-----"}
disabled={data.busy}
onClick={() => act('ert')}
/>
</Box>
</Section>
)}
<Section title={data.event} buttons={
<Button
icon="arrow-circle-left"
content="Back"
disabled={data.busy || data.hasConfirm}
onClick={() => act('reset')} />
}>
{swipeInfo}
</Section>
</Window.Content>
</Window>
);
}
};
File diff suppressed because one or more lines are too long