From 53a08275f98fb37686d9b4c7ae143d0313f7c9c5 Mon Sep 17 00:00:00 2001
From: Drathek <76988376+Drulikar@users.noreply.github.com>
Date: Thu, 21 Dec 2023 09:46:01 -0800
Subject: [PATCH] Additional ui_act checks for tacmap (#5255)
# About the pull request
This PR adds additional checks for the ui_acts when using the tacmap
interface.
# Explain why it's good for the game
Should shore up most flaws allowing weird usage of it.
# Testing Photographs and Procedure
Screenshots & Videos
![image](https://github.com/cmss13-devs/cmss13/assets/76988376/efbf579c-814d-41fd-bea4-d2581b4bf4f7)
# Changelog
No player facing changes.
---
code/controllers/subsystem/minimap.dm | 80 ++++++++++++-------
tgui/packages/tgui/interfaces/TacticalMap.tsx | 4 +-
2 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/code/controllers/subsystem/minimap.dm b/code/controllers/subsystem/minimap.dm
index 50aec8845dd0..e2ebffe55959 100644
--- a/code/controllers/subsystem/minimap.dm
+++ b/code/controllers/subsystem/minimap.dm
@@ -1,3 +1,6 @@
+#define CANVAS_COOLDOWN_TIME 4 MINUTES
+#define FLATTEN_MAP_COOLDOWN_TIME 3 MINUTES
+
/**
* # Minimaps subsystem
*
@@ -438,11 +441,11 @@ SUBSYSTEM_DEF(minimaps)
if(faction == FACTION_MARINE)
if(!COOLDOWN_FINISHED(GLOB, uscm_flatten_map_icon_cooldown))
return FALSE
- COOLDOWN_START(GLOB, uscm_flatten_map_icon_cooldown, flatten_map_cooldown_time)
+ COOLDOWN_START(GLOB, uscm_flatten_map_icon_cooldown, FLATTEN_MAP_COOLDOWN_TIME)
else if(faction == XENO_HIVE_NORMAL)
if(!COOLDOWN_FINISHED(GLOB, xeno_flatten_map_icon_cooldown))
return FALSE
- COOLDOWN_START(GLOB, xeno_flatten_map_icon_cooldown, flatten_map_cooldown_time)
+ COOLDOWN_START(GLOB, xeno_flatten_map_icon_cooldown, FLATTEN_MAP_COOLDOWN_TIME)
else
return FALSE
@@ -500,6 +503,8 @@ SUBSYSTEM_DEF(minimaps)
qdel(svg_store_overlay)
debug_log("SVG coordinates for [faction] are not implemented!")
+#define can_draw(faction, user) ((faction == FACTION_MARINE && skillcheck(user, SKILL_LEADERSHIP, SKILL_LEAD_EXPERT)) || (faction == XENO_HIVE_NORMAL && isqueen(user)))
+
/datum/controller/subsystem/minimaps/proc/fetch_tacmap_datum(zlevel, flags)
var/hash = "[zlevel]-[flags]"
if(hashed_tacmaps[hash])
@@ -625,9 +630,6 @@ SUBSYSTEM_DEF(minimaps)
var/toolbar_color_selection = "black"
var/toolbar_updated_selection = "black"
- var/canvas_cooldown_time = 4 MINUTES
- var/flatten_map_cooldown_time = 3 MINUTES
-
/// boolean value to keep track if the canvas has been updated or not, the value is used in tgui state.
var/updated_canvas = FALSE
/// current flattend map
@@ -740,7 +742,6 @@ SUBSYSTEM_DEF(minimaps)
else
data["canvasCooldown"] = max(GLOB.uscm_canvas_cooldown - world.time, 0)
- data["nextCanvasTime"] = canvas_cooldown_time
data["updatedCanvas"] = updated_canvas
data["lastUpdateTime"] = last_update_time
@@ -750,6 +751,7 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/ui_static_data(mob/user)
var/list/data = list()
+
data["mapRef"] = map_holder?.map_ref
data["canDraw"] = FALSE
data["canViewTacmap"] = TRUE
@@ -761,6 +763,7 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/drawing/ui_static_data(mob/user)
var/list/data = list()
+ data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapRef"] = map_holder?.map_ref
data["canDraw"] = FALSE
data["mapFallback"] = wiki_map_fallback
@@ -773,7 +776,7 @@ SUBSYSTEM_DEF(minimaps)
data["canViewTacmap"] = is_xeno
data["canViewCanvas"] = faction == FACTION_MARINE || faction == XENO_HIVE_NORMAL
- if(faction == FACTION_MARINE && skillcheck(user, SKILL_LEADERSHIP, SKILL_LEAD_EXPERT) || faction == XENO_HIVE_NORMAL && isqueen(user))
+ if(can_draw(faction, user))
data["canDraw"] = TRUE
data["canViewTacmap"] = TRUE
@@ -781,6 +784,8 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/drawing/status_tab_view/ui_static_data(mob/user)
var/list/data = list()
+
+ data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapFallback"] = wiki_map_fallback
data["canDraw"] = FALSE
data["canViewTacmap"] = FALSE
@@ -791,6 +796,8 @@ SUBSYSTEM_DEF(minimaps)
/datum/tacmap/drawing/status_tab_view/xeno/ui_static_data(mob/user)
var/list/data = list()
+
+ data["canvasCooldownDuration"] = CANVAS_COOLDOWN_TIME
data["mapFallback"] = wiki_map_fallback
data["canDraw"] = FALSE
data["canViewTacmap"] = FALSE
@@ -814,16 +821,21 @@ SUBSYSTEM_DEF(minimaps)
var/mob/user = ui.user
var/mob/living/carbon/xenomorph/xeno = user
var/faction = istype(xeno) ? xeno.hivenumber : user.faction
- if(faction == FACTION_NEUTRAL && isobserver(user))
+ var/is_observer = isobserver(user)
+ if(faction == FACTION_NEUTRAL && is_observer)
faction = allowed_flags == MINIMAP_FLAG_XENO ? XENO_HIVE_NORMAL : FACTION_MARINE
+ var/drawing_allowed = !is_observer && can_draw(faction, user)
- switch (action)
- if ("menuSelect")
+ switch(action)
+ if("menuSelect")
if(params["selection"] != "new canvas")
if(updated_canvas)
updated_canvas = FALSE
toolbar_updated_selection = toolbar_color_selection // doing this if it == canvas can cause a latency issue with the stroke.
else
+ if(!drawing_allowed)
+ msg_admin_niche("[key_name(user)] made an unauthorized attempt to 'menuSelect' the 'new canvas' panel of the [faction] tacmap!")
+ return FALSE
distribute_current_map_png(faction)
last_update_time = world.time
// An attempt to get the image to load on first try in the interface, but doesn't seem always reliable
@@ -832,60 +844,68 @@ SUBSYSTEM_DEF(minimaps)
old_map = get_tacmap_data_png(faction)
current_svg = get_tacmap_data_svg(faction)
- if ("updateCanvas")
- // forces state change, this will export the svg.
+ if("updateCanvas")
toolbar_updated_selection = "export"
updated_canvas = TRUE
action_queue_change += 1
- if ("clearCanvas")
+ if("clearCanvas")
toolbar_updated_selection = "clear"
updated_canvas = FALSE
action_queue_change += 1
- if ("undoChange")
+ if("undoChange")
toolbar_updated_selection = "undo"
updated_canvas = FALSE
action_queue_change += 1
- if ("selectColor")
+ if("selectColor")
var/newColor = params["color"]
if(newColor)
toolbar_color_selection = newColor
toolbar_updated_selection = newColor
action_queue_change += 1
- if ("onDraw")
+ if("onDraw")
updated_canvas = FALSE
- if ("selectAnnouncement")
+ if("selectAnnouncement")
+ if(!drawing_allowed)
+ msg_admin_niche("[key_name(user)] made an unauthorized attempt to 'selectAnnouncement' the [faction] tacmap!")
+ return FALSE
+
if(!istype(params["image"], /list)) // potentially very serious?
return FALSE
+ var/cooldown_satisfied = FALSE
if(faction == FACTION_MARINE)
- GLOB.uscm_flat_tacmap_data += new_current_map
+ cooldown_satisfied = COOLDOWN_FINISHED(GLOB, uscm_canvas_cooldown)
else if(faction == XENO_HIVE_NORMAL)
- GLOB.xeno_flat_tacmap_data += new_current_map
-
- store_current_svg_coords(faction, params["image"], user)
- current_svg = get_tacmap_data_svg(faction)
- old_map = get_tacmap_data_png(faction)
+ cooldown_satisfied = COOLDOWN_FINISHED(GLOB, xeno_canvas_cooldown)
+ if(!cooldown_satisfied)
+ msg_admin_niche("[key_name(user)] attempted to 'selectAnnouncement' the [faction] tacmap while it is still on cooldown!")
+ return FALSE
if(faction == FACTION_MARINE)
- COOLDOWN_START(GLOB, uscm_canvas_cooldown, canvas_cooldown_time)
- var/mob/living/carbon/human/human_leader = user
+ GLOB.uscm_flat_tacmap_data += new_current_map
+ COOLDOWN_START(GLOB, uscm_canvas_cooldown, CANVAS_COOLDOWN_TIME)
for(var/datum/squad/current_squad in GLOB.RoleAuthority.squads)
current_squad.send_maptext("Tactical map update in progress...", "Tactical Map:")
+ var/mob/living/carbon/human/human_leader = user
human_leader.visible_message(SPAN_BOLDNOTICE("Tactical map update in progress..."))
playsound_client(human_leader.client, "sound/effects/sos-morse-code.ogg")
notify_ghosts(header = "Tactical Map", message = "The USCM tactical map has been updated.", ghost_sound = "sound/effects/sos-morse-code.ogg", notify_volume = 80, action = NOTIFY_USCM_TACMAP, enter_link = "uscm_tacmap=1", enter_text = "View", source = owner)
-
else if(faction == XENO_HIVE_NORMAL)
- var/mutable_appearance/appearance = mutable_appearance(icon('icons/mob/hud/actions_xeno.dmi'), "toggle_queen_zoom")
- COOLDOWN_START(GLOB, xeno_canvas_cooldown, canvas_cooldown_time)
+ GLOB.xeno_flat_tacmap_data += new_current_map
+ COOLDOWN_START(GLOB, xeno_canvas_cooldown, CANVAS_COOLDOWN_TIME)
xeno_maptext("The Queen has updated our hive mind map", "We sense something unusual...", faction)
+ var/mutable_appearance/appearance = mutable_appearance(icon('icons/mob/hud/actions_xeno.dmi'), "toggle_queen_zoom")
notify_ghosts(header = "Tactical Map", message = "The Xenomorph tactical map has been updated.", ghost_sound = "sound/voice/alien_distantroar_3.ogg", notify_volume = 50, action = NOTIFY_XENO_TACMAP, enter_link = "xeno_tacmap=1", enter_text = "View", source = user, alert_overlay = appearance)
+ store_current_svg_coords(faction, params["image"], user)
+ current_svg = get_tacmap_data_svg(faction)
+ old_map = get_tacmap_data_png(faction)
+
toolbar_updated_selection = toolbar_color_selection
message_admins("[key_name(user)] has updated the tactical map for [faction].")
updated_canvas = FALSE
@@ -995,3 +1015,7 @@ SUBSYSTEM_DEF(minimaps)
if(XENO_HIVE_RENEGADE)
return MINIMAP_FLAG_XENO_RENEGADE
return 0
+
+#undef CANVAS_COOLDOWN_TIME
+#undef FLATTEN_MAP_COOLDOWN_TIME
+#undef can_draw
diff --git a/tgui/packages/tgui/interfaces/TacticalMap.tsx b/tgui/packages/tgui/interfaces/TacticalMap.tsx
index 92996038719f..0888212a83fb 100644
--- a/tgui/packages/tgui/interfaces/TacticalMap.tsx
+++ b/tgui/packages/tgui/interfaces/TacticalMap.tsx
@@ -23,7 +23,7 @@ interface TacMapProps {
mapRef: string;
currentMenu: string;
lastUpdateTime: any;
- nextCanvasTime: any;
+ canvasCooldownDuration: any;
canvasCooldown: any;
exportedTacMapImage: any;
tacmapReady: number;
@@ -192,7 +192,7 @@ const OldMapPanel = (props, context) => {
const DrawMapPanel = (props, context) => {
const { data, act } = useBackend(context);
- const timeLeftPct = data.canvasCooldown / data.nextCanvasTime;
+ const timeLeftPct = data.canvasCooldown / data.canvasCooldownDuration;
const canUpdate = data.canvasCooldown <= 0 && !data.updatedCanvas;
const handleTacMapExport = (image: any) => {