Files
Bubberstation/code/modules/wiremod/components/admin/input_request.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

103 lines
3.1 KiB
Plaintext

#define COMP_INPUT_STRING "string"
#define COMP_INPUT_NUMBER "number"
#define COMP_INPUT_LIST "list"
/**
* # Input Request Component
*
* Requests an input from someone.
*/
/obj/item/circuit_component/input_request
display_name = "Input Request"
desc = "Converts a string into a typepath. Useful for adding components."
category = "Admin"
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_ADMIN
/// Options for input requests
var/datum/port/input/option/input_options
/// The input path to convert into a typepath
var/datum/port/input/entity
/// The custom parameter of the option
var/datum/port/input/parameter
/// The response from the player
var/datum/port/output/input_response
/// Triggered when the input is received
var/datum/port/output/input_triggered
/// Triggered when the player fails to give an input.
var/datum/port/output/input_failed
/obj/item/circuit_component/input_request/populate_options()
var/static/list/component_options = list(
COMP_INPUT_STRING,
COMP_INPUT_NUMBER,
COMP_INPUT_LIST
)
input_options = add_option_port("Option", component_options)
/obj/item/circuit_component/input_request/populate_ports()
entity = add_input_port("Entity", PORT_TYPE_ATOM)
input_response = add_output_port("Response", PORT_TYPE_ANY)
input_triggered = add_output_port("Input Sent", PORT_TYPE_SIGNAL)
input_failed = add_output_port("Input Failed", PORT_TYPE_SIGNAL)
update_options()
/obj/item/circuit_component/input_request/input_received(datum/port/input/port)
var/mob/player = entity.value
if(!istype(player))
return
INVOKE_ASYNC(src, PROC_REF(request_input_from_player), player)
/obj/item/circuit_component/input_request/proc/request_input_from_player(mob/player)
var/new_option = input_options.value
switch(new_option)
if(COMP_INPUT_STRING)
var/player_input = tgui_input_text(player, "Input a value", "Input value", max_length = MAX_MESSAGE_LEN)
if(isnull(player_input))
return
input_response.set_output(player_input)
if(COMP_INPUT_NUMBER)
var/player_input = tgui_input_number(player, "Input a value", "Input value")
if(isnull(player_input))
return
input_response.set_output(player_input)
if(COMP_INPUT_LIST)
var/list/data = parameter.value
if(!islist(data))
return
var/player_input = tgui_input_list(player, "Input a value", "Input value", data)
if(isnull(player_input))
return
input_response.set_output(player_input)
input_triggered.set_output(COMPONENT_SIGNAL)
/obj/item/circuit_component/input_request/pre_input_received(datum/port/input/port)
if(port == input_options)
update_options(port)
/obj/item/circuit_component/input_request/proc/update_options(datum/port/input/port)
var/new_option = input_options.value
if(parameter)
remove_input_port(parameter)
parameter = null
switch(new_option)
if(COMP_INPUT_STRING)
input_response.set_datatype(PORT_TYPE_STRING)
if(COMP_INPUT_NUMBER)
input_response.set_datatype(PORT_TYPE_NUMBER)
if(COMP_INPUT_LIST)
parameter = add_input_port("Options List", PORT_TYPE_LIST(PORT_TYPE_ANY))
input_response.set_datatype(PORT_TYPE_STRING)
#undef COMP_INPUT_STRING
#undef COMP_INPUT_NUMBER
#undef COMP_INPUT_LIST