Skip to content

Commit

Permalink
Ahelp claiming system (#2130)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
Very loosely inspired by the concept of bee's system, entirely my own
code.

Interacting with a ticket "claims" it, giving a warning to all other
admins that it's already claimed. They can easily override, and you can
"unclaim" it by clicking the claim button at the top of the ticket
display.

Should fix #1692 completely

## Why It's Good For The Game
Stops so many duplicate ahelp responses from multiple admins.

## Changelog

:cl:
admin: Adds ticket claiming, interacting with a ticket will "claim" it
and present a warning to all other admins who try to interact also.
/:cl:

<!-- Both :cl:'s are required for the changelog to work! You can put
your name to the right of the first :cl: if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

---------

Co-authored-by: Mothblocks <[email protected]>
  • Loading branch information
MarkSuckerberg and Mothblocks authored Jul 21, 2023
1 parent 4339abc commit 910b4be
Show file tree
Hide file tree
Showing 14 changed files with 352 additions and 159 deletions.
2 changes: 1 addition & 1 deletion check_regex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ standards:

- exactly:
[
292,
291,
"non-bitwise << uses",
'(?<!\d)(?<!\d\s)(?<!<)<<(?!=|\s\d|\d|<|\/)',
]
Expand Down
7 changes: 7 additions & 0 deletions code/__DEFINES/dcs/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@
#define COMSIG_ITEM_SPLIT_PROFIT "item_split_profits" //Called when getting the item's exact ratio for cargo's profit.
#define COMSIG_ITEM_SPLIT_PROFIT_DRY "item_split_profits_dry" //Called when getting the item's exact ratio for cargo's profit, without selling the item.

/// Admin helps
/// From /datum/admin_help/RemoveActive().
/// Fired when an adminhelp is made inactive either due to closing or resolving.
#define COMSIG_ADMIN_HELP_MADE_INACTIVE "admin_help_made_inactive"

/// Called when the player replies. From /client/proc/cmd_admin_pm().
#define COMSIG_ADMIN_HELP_REPLIED "admin_help_replied"

// /obj/item/clothing signals
#define COMSIG_SHOES_STEP_ACTION "shoes_step_action" //from base of obj/item/clothing/shoes/proc/step_action(): ()
Expand Down
3 changes: 3 additions & 0 deletions code/__DEFINES/layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,7 @@

#define SPLASHSCREEN_LAYER 54
#define SPLASHSCREEN_PLANE 54

#define ADMIN_POPUP_LAYER 1

#define SPLASHSCREEN_RENDER_TARGET "SPLASHSCREEN_PLANE"
3 changes: 2 additions & 1 deletion code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@

/datum/config_entry/flag/allow_metadata // Metadata is supported.

/datum/config_entry/flag/popup_admin_pm // adminPMs to non-admins show in a pop-up 'reply' window when set
/// Gives the ability to send players a maptext popup.
/datum/config_entry/flag/popup_admin_pm

/datum/config_entry/number/fps
config_entry_value = 20
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/blackbox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ Versioning
key = new_key
key_type = new_key_type

/datum/controller/subsystem/blackbox/proc/LogAhelp(ticket, action, message, recipient, sender)
/datum/controller/subsystem/blackbox/proc/log_ahelp(ticket, action, message, recipient, sender)
if(!SSdbcore.Connect())
return

Expand Down
125 changes: 125 additions & 0 deletions code/datums/components/admin_popup.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/// Applied to clients when they receive an admin popup, alerting them to
/// their ticket.
/datum/component/admin_popup
/// The user's most active ticket. If this is resolved, closed, or replied to,
/// then the component will delete itself.
var/datum/admin_help/ticket

var/atom/movable/screen/admin_popup/admin_popup

/datum/component/admin_popup/Initialize(datum/admin_help/ticket)
if (!istype(parent, /client))
return COMPONENT_INCOMPATIBLE

if (!istype(ticket))
return COMPONENT_INCOMPATIBLE

create_notice()

RegisterSignal(
ticket,
list(
COMSIG_ADMIN_HELP_MADE_INACTIVE,
COMSIG_ADMIN_HELP_REPLIED,
COMSIG_PARENT_QDELETING,
),
.proc/delete_self,
)

/datum/component/admin_popup/Destroy(force, silent)
var/client/parent_client = parent

parent_client?.screen -= admin_popup
QDEL_NULL(admin_popup)

if (!QDELETED(ticket))
UnregisterSignal(ticket, list(
COMSIG_ADMIN_HELP_MADE_INACTIVE,
COMSIG_ADMIN_HELP_REPLIED,
COMSIG_PARENT_QDELETING,
))

ticket = null

return ..()

/datum/component/admin_popup/proc/create_notice()
if(admin_popup)
qdel(admin_popup)
admin_popup = new

var/client/parent_client = parent
admin_popup.maptext_width = getviewsize(parent_client.view_size.getView())[1] * world.icon_size
parent_client.screen += admin_popup

/datum/component/admin_popup/proc/delete_self()
SIGNAL_HANDLER
qdel(src)

/// The UI element for admin popups
/atom/movable/screen/admin_popup
icon = null
icon_state = null
plane = ABOVE_HUD_PLANE
layer = ADMIN_POPUP_LAYER
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
screen_loc = "TOP-5,LEFT"
maptext_height = 480
maptext_width = 480
maptext = ""

var/static/list/colors = list(
COLOR_RED,
COLOR_ORANGE,
COLOR_YELLOW,
COLOR_LIME,
COLOR_CYAN,
COLOR_PURPLE,
)

/// The last color chosen in the animation, sourced from the static list colors.
var/last_color_index = 0

/// The `world.time` when the last color update occurred.
var/last_update_time = 0

/atom/movable/screen/admin_popup/New(loc, ...)
. = ..()

START_PROCESSING(SSobj, src)
update_text()

/atom/movable/screen/admin_popup/Destroy()
STOP_PROCESSING(SSobj, src)
return ..()

/atom/movable/screen/admin_popup/process(delta_time)
update_text()

/atom/movable/screen/admin_popup/proc/update_text()
// Even if processing time changes, we want this to remain slow.
// We want to pester them into reading their ticket, not give them a seizure!
if (world.time - last_update_time < 2 SECONDS)
return

last_color_index = (last_color_index % colors.len) + 1

var/message = "<b style='color: [colors[last_color_index]]; text-align: center; font-size: 32px'>"
message += "HEY! An admin is trying to talk to you!<br>Check your chat window, and click their name to respond!"
message += "</b>"

maptext = MAPTEXT(message)
last_update_time = world.time

/// Tries to give the target an admin popup.
/// If it fails, will send the error to the passed admin.
/proc/give_admin_popup(client/target, client/admin, message)
log_admin("[key_name(admin)] sent an admin popup to [key_name(target)].")

var/datum/admin_help/current_ticket = target.current_ticket
if (!current_ticket)
to_chat(admin, span_warning("[key_name(target)] had no active ahelp, aborting."))
return

admin.cmd_admin_pm(target, message)
target.AddComponent(/datum/component/admin_popup, current_ticket)
2 changes: 1 addition & 1 deletion code/modules/admin/chat_commands.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
all_params.Cut(1, 2)
var/id = text2num(target)
if(id != null)
var/datum/admin_help/AH = GLOB.ahelp_tickets.TicketByID(id)
var/datum/admin_help/AH = GLOB.ahelp_tickets.ticket_by_id(id)
if(AH)
target = AH.initiator_ckey
else
Expand Down
2 changes: 1 addition & 1 deletion code/modules/admin/sql_ban_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
if(roles_to_ban[1] == "Server" && (!is_admin || (is_admin && applies_to_admins)))
qdel(C)
if(roles_to_ban[1] == "Server" && AH)
AH.Resolve()
AH.resolve()
for(var/client/i in GLOB.clients - C)
if(i.address == player_ip || i.computer_id == player_cid)
build_ban_cache(i)
Expand Down
20 changes: 18 additions & 2 deletions code/modules/admin/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
var/ahelp_ref = href_list["ahelp"]
var/datum/admin_help/AH = locate(ahelp_ref)
if(AH)
AH.Action(href_list["ahelp_action"])
AH.action(usr, href_list["ahelp_action"])
else
to_chat(usr, "Ticket [ahelp_ref] has been deleted!", confidential = TRUE)

else if(href_list["ahelp_tickets"])
GLOB.ahelp_tickets.BrowseTickets(text2num(href_list["ahelp_tickets"]))
GLOB.ahelp_tickets.browse_tickets(text2num(href_list["ahelp_tickets"]))

else if(href_list["stickyban"])
stickyban(href_list["stickyban"],href_list)
Expand Down Expand Up @@ -1260,6 +1260,22 @@
message_admins("[key_name(H)] has their hands full, so they did not receive their [initial(cookiealt.name)], spawned by [key_name(src.owner)].")
// WS - End

else if (href_list["adminpopup"])
if (!check_rights(R_ADMIN))
return

var/message = input(owner, "As well as a popup, they'll also be sent a message to reply to. What do you want that to be?", "Message") as text|null
if (!message)
to_chat(owner, span_notice("Popup cancelled."))
return

var/client/target = locate(href_list["adminpopup"])
if (!istype(target))
to_chat(owner, span_notice("The mob doesn't exist anymore!"))
return

give_admin_popup(target, owner, message)

else if(href_list["adminsmite"])
if(!check_rights(R_ADMIN|R_FUN))
return
Expand Down
Loading

0 comments on commit 910b4be

Please sign in to comment.