Files
Bubberstation/code/modules/interview/interview.dm
Bobbahbrown 4e48e1379d Interview System / Soft Panic Bunker (#54465)
About The Pull Request

Ports and improves my interview system that has been previously used in the summer ball and toolbox tournament events. Allows for a 'softer' panic bunker, wherein players who fall below the required living time limit can still join the server and be restricted to filling out a questionnaire. Upon completing the questionnaire, the player may be allowed into the server by an administrator. If the application is approved, they get a notification that they will be reconnected and upon reconnecting will have all verbs as they usually would. If the application is denied the user is put on a cooldown after which they may submit a new questionnaire.

Players who are being interviewed (herein interviewees) have no verbs other than those required for the stat panel to function, as well as a verb to pull up the interview panel. Interviews do not persist through restarts, and the ability to join that is granted by an accepted interview is only valid for the duration of that round.

Open interviews are listed under a new 'interviews' tab for admins, which is VERY similar to the existing tickets tab.

Below is what a player who is flagged as an interviewee will see when they join the server. They can do nothing but respond to the questionnaire or leave.
image

This is what an administrator sees after an interview is submitted, they will also see a corresponding message within their chatbox, and an age-old BWOINK when an interview is submitted.
image

The interviews tab, which is similar to the tickets menu. You can open the interview manager panel to view all active (including non-submitted) interviews, queued (submitted) interviews, and closed interviews.

image
FAQ:

What happens if someone submits an interview when no admins are on? It's treated like adminhelps are, the message gets sent to TGS to be dispatched off to configured end-points (like Discord or IRC), and the user is notified that their interview was handled this way.

Can you configure the questions? Yes, in config/ there is now a interviews.txt file in which the welcome message and the individual questions can be set and modified.

Can this be turned on and off during a round? Yes, it can be toggled like the panic bunker. It requires the panic bunker to be raised in order to function.

Can interviewees have further questions asked to them? Yes, if you admin-pm them, which is possible using regular means or a conveniently placed button on the interview UI, they will be able to respond to the message.
Technical details

To use the interview system you must have the panic bunker enabled, this is an additional setting for the panic bunker. It can be set through the PANIC_BUNKER_INTERVIEW setting in config.txt, or alternatively enabled in-game as prompted during the panic bunker toggling process. It also can be toggled on its own using a verb added for this purpose, Toggle PB Interviews found under the server tab. These new actions are included in the logging for the panic bunker. I have also added a reporting stat to the world topic status keyword, which now reports if the interview system is on using the keyword interviews.

As mentioned above, for server operators, configure the questions and welcome message in config/interviews.txt.

Note to maintainers and those with big brains I had to add a call to init_verbs on the stat panel window being ready because seemingly a race condition exists wherein the add_verb of the 'view my interview' verb doesn't cause a refresh of the tabs (and therefore doesn't show the 'Interview' tab) when running in dream daemon but running it directly from visual studio code properly shows the tab. Adding a init_verbs call directly after adding the verb didn't seem to help.
A note for downstreams

If you don't use the HTML stat panel (which may not be a bad thing) then you will have to do some conversion from the HTML stat panel stuff used here to the old style stat panels. It's pretty trivial, but just be aware of that. You can see how I used to use the old stat panels in my PR from the summer ball, here, which should be helpful.
Why It's Good For The Game

This allows for a softer version of the panic bunker which impedes the flow of malicious players while allowing genuine players a chance to enter a round to gain enough time to not be affected by the panic bunker's restrictions.
Changelog

🆑 bobbahbrown
add: Added the interview system, a 'soft' panic bunker which lets players who would normally be blocked from joining be interviewed by admins to be selectively allowed to play.
/🆑
2020-10-25 14:10:06 +13:00

163 lines
6.0 KiB
Plaintext

/// State when an interview has been approved
#define INTERVIEW_APPROVED "interview_approved"
/// State when an interview as been denied
#define INTERVIEW_DENIED "interview_denied"
/// State when an interview has had no action on it yet
#define INTERVIEW_PENDING "interview_pending"
/**
* Represents a new-player interview form
*
* Represents a new-player interview form, enabled by configuration to require
* players with low playtime to request access to the server. To do so, they will
* out a brief questionnaire, and are otherwise unable to do anything while they
* wait for a response.
*/
/datum/interview
/// Unique ID of the interview
var/id
/// Atomic ID for incrementing unique IDs
var/static/atomic_id = 0
/// The /client who owns this interview, the intiator
var/client/owner
/// The Ckey of the owner, used for when a client could disconnect
var/owner_ckey
/// The welcome message shown at the top of the interview panel
var/welcome_message
/// The questions to display on the questionnaire of the interview
var/list/questions
/// The stored responses, will be filled as the questionnaire is answered
var/list/responses = list()
/// Boolean operator controlling if the questionnaire's contents can be edited
var/read_only = FALSE
/// Integer that contains the current position in the interview queue, used for rendering
var/pos_in_queue
/// Contains the state of the form, used for rendering and sanity checking
var/status = INTERVIEW_PENDING
/datum/interview/New(client/interviewee)
if(!interviewee)
qdel(src)
return
id = ++atomic_id
owner = interviewee
owner_ckey = owner.ckey
questions = CONFIG_GET(str_list/interview_questions)
responses.len = questions.len
welcome_message = CONFIG_GET(string/interview_welcome_msg)
/**
* Approves the interview, forces reconnect of owner if relevant.
*
* Approves the interview, and if relevant will force the owner to reconnect so that they have the proper
* verbs returned to them.
* Arguments:
* * approved_by - The user who approved the interview, used for logging
*/
/datum/interview/proc/approve(client/approved_by)
status = INTERVIEW_APPROVED
read_only = TRUE
GLOB.interviews.approved_ckeys |= owner_ckey
GLOB.interviews.close_interview(src)
log_admin_private("[key_name(approved_by)] has approved interview #[id] for [owner_ckey][!owner ? "(DC)": ""].")
message_admins("<span class='adminnotice'>[key_name(approved_by)] has approved interview #[id] for [owner_ckey][!owner ? "(DC)": ""].</span>")
if (owner)
SEND_SOUND(owner, sound('sound/effects/adminhelp.ogg'))
to_chat(owner, "<font color='red' size='4'><b>-- Interview Update --</b></font>" \
+ "\n<span class='adminsay'>Your interview was approved, you will now be reconnected in 5 seconds.</span>", confidential = TRUE)
addtimer(CALLBACK(src, .proc/reconnect_owner), 50)
/**
* Denies the interview and adds the owner to the cooldown for new interviews.
*
* Arguments:
* * denied_by - The user who denied the interview, used for logging
*/
/datum/interview/proc/deny(client/denied_by)
status = INTERVIEW_DENIED
read_only = TRUE
GLOB.interviews.close_interview(src)
GLOB.interviews.cooldown_ckeys |= owner_ckey
log_admin_private("[key_name(denied_by)] has denied interview #[id] for [owner_ckey][!owner ? "(DC)": ""].")
message_admins("<span class='adminnotice'>[key_name(denied_by)] has denied interview #[id] for [owner_ckey][!owner ? "(DC)": ""].</span>")
addtimer(CALLBACK(GLOB.interviews, /datum/interview_manager.proc/release_from_cooldown, owner_ckey), 180)
if (owner)
SEND_SOUND(owner, sound('sound/effects/adminhelp.ogg'))
to_chat(owner, "<font color='red' size='4'><b>-- Interview Update --</b></font>" \
+ "\n<span class='adminsay'>Unfortunately your interview was denied. Please try submitting another questionnaire." \
+ " You may do this in three minutes.</span>", confidential = TRUE)
/**
* Forces client to reconnect, used in the callback from approval
*/
/datum/interview/proc/reconnect_owner()
if (!owner)
return
winset(owner, null, "command=.reconnect")
/**
* Verb for opening the existing interview, or if relevant creating a new interview if possible.
*/
/mob/dead/new_player/proc/open_interview()
set name = "Open Interview"
set category = "Interview"
var/mob/dead/new_player/M = usr
if (M?.client?.interviewee)
var/datum/interview/I = GLOB.interviews.interview_for_client(M.client)
if (I) // we can be returned nothing if the user is on cooldown
I.ui_interact(M)
else
to_chat(usr, "<span class='adminsay'>You are on cooldown for interviews. Please" \
+ " wait at least 3 minutes before starting a new questionnaire.</span>", confidential = TRUE)
/datum/interview/ui_interact(mob/user, datum/tgui/ui = null)
ui = SStgui.try_update_ui(user, src, ui)
if (!ui)
ui = new(user, src, "Interview")
ui.open()
/datum/interview/ui_state(mob/user)
return GLOB.new_player_state
/datum/interview/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
if (..())
return
switch(action)
if ("update_answer")
if (!read_only)
responses[text2num(params["qidx"])] = copytext_char(params["answer"], 1, 501) // byond indexing moment
. = TRUE
if ("submit")
if (!read_only)
read_only = TRUE
GLOB.interviews.enqueue(src)
. = TRUE
if ("approve")
if (usr.client?.holder && status == INTERVIEW_PENDING)
src.approve(usr)
. = TRUE
if ("deny")
if (usr.client?.holder && status == INTERVIEW_PENDING)
src.deny(usr)
. = TRUE
if ("adminpm")
if (usr.client?.holder && owner)
usr.client.cmd_admin_pm(owner, null)
/datum/interview/ui_data(mob/user)
. = list(
"welcome_message" = welcome_message,
"questions" = list(),
"read_only" = read_only,
"queue_pos" = pos_in_queue,
"is_admin" = !!(user?.client && user.client.holder),
"status" = status,
"connected" = !!owner)
for (var/i in 1 to questions.len)
var/list/data = list(
"qidx" = i,
"question" = questions[i],
"response" = responses.len < i ? null : responses[i]
)
.["questions"] += list(data)