Files
Bubberstation/code/modules/wiremod/shell/keyboard.dm
san7890 a4328ae1f9 Audits tgui_input_text() for length issues (#86741)
Fixes #86784

## About The Pull Request

Although some of the issues found were a direct result from #86692
(c698196766), there was still 40% of
length-related issues that wouldn't be covered anyways that are fixed in
this PR. I.E.:

* Name inputs without `MAX_NAME_LEN`
* Desc inputs without `MAX_DESC_LEN`
* Plaque inputs without `MAX_PLAQUE_LEN`
* Some people just screwed up the arguments so it would prefill
something like "40" in the `default` var because they didn't name their
vars.

To help me audit I added a lot of `max_length` named arguments to help
people understand it better. I think it might be kinder to have a
wrapper that handles adding `MAX_MESSAGE_LEN` in a lot of these cases
but I think there is some reason for a coder to be cognitive about input
texts? Let me know what you think. I didn't update anything
admin-related from what I can recall, let me know if anything needs to
be unlimited again.
## Why It's Good For The Game

The change to `INFINITY` notwithstanding, there were still an abundance
of issues that we needed to check up on. A lot of these are filtered on
down the line but it is clear that there needs to be something to catch
these issues. Maybe we could lint to make `max_length` a mandatory
argument? I don't know if that's necessary at all but I think that the
limit should be set by the invoker due to the wide arrangement of cases
that this proc could be used in.

This could all be a big nothingburger if the aforementioned PR is
reverted but a big chunk of cases fixed in this PR need to be fixed
regardless of that since people could put in 1024 character names for
stuff like guardians (or more now with the change). Consider this
"revert agnostic".
## Changelog
🆑
fix: A lot of instances where you could fill in 1024-character names
(normal limit is 42) have been patched out, along with too-long plaque
names, too-long descriptions, and more.
/🆑
2024-09-20 22:46:41 +00:00

57 lines
2.0 KiB
Plaintext

/obj/item/keyboard_shell
name = "Keyboard Shell"
icon = 'icons/obj/science/circuits.dmi'
icon_state = "setup_small_keyboard"
inhand_icon_state = "electronic"
worn_icon_state = "electronic"
lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi'
righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi'
light_system = OVERLAY_LIGHT_DIRECTIONAL
light_on = FALSE
w_class = WEIGHT_CLASS_SMALL
/obj/item/keyboard_shell/Initialize(mapload)
. = ..()
AddComponent(/datum/component/shell, list(
new /obj/item/circuit_component/keyboard_shell()
), SHELL_CAPACITY_SMALL)
/obj/item/circuit_component/keyboard_shell
display_name = "Keyboard Shell"
desc = "A handheld shell that allows the user to input a string. Use the shell in hand to open the input panel."
/// Called when the input window is closed
var/datum/port/output/signal
/// Entity who used the shell
var/datum/port/output/entity
/// The string, entity typed and submitted
var/datum/port/output/output
/obj/item/circuit_component/keyboard_shell/populate_ports()
entity = add_output_port("User", PORT_TYPE_USER)
output = add_output_port("Message", PORT_TYPE_STRING)
signal = add_output_port("Signal", PORT_TYPE_SIGNAL)
/obj/item/circuit_component/keyboard_shell/register_shell(atom/movable/shell)
. = ..()
RegisterSignal(shell, COMSIG_ITEM_ATTACK_SELF, PROC_REF(send_trigger))
/obj/item/circuit_component/keyboard_shell/unregister_shell(atom/movable/shell)
UnregisterSignal(shell, COMSIG_ITEM_ATTACK_SELF)
return ..()
/obj/item/circuit_component/keyboard_shell/proc/send_trigger(atom/source, mob/user)
SIGNAL_HANDLER
INVOKE_ASYNC(src, PROC_REF(use_keyboard), user)
/obj/item/circuit_component/keyboard_shell/proc/use_keyboard(mob/user)
if(HAS_TRAIT(user, TRAIT_ILLITERATE))
to_chat(user, span_warning("You start mashing keys at random!"))
return
var/message = tgui_input_text(user, "Input your text", "Keyboard", max_length = MAX_MESSAGE_LEN)
entity.set_output(user)
output.set_output(message)
signal.set_output(COMPONENT_SIGNAL)