Files
Bubberstation/code/game/objects/items/AI_modules/full_lawsets.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

170 lines
5.6 KiB
Plaintext

/* CONTAINS:
* /obj/item/ai_module/core/full/custom
* /obj/item/ai_module/core/full/asimov
* /obj/item/ai_module/core/full/asimovpp
* /obj/item/ai_module/core/full/corp
* /obj/item/ai_module/core/full/paladin
* /obj/item/ai_module/core/full/paladin_devotion
* /obj/item/ai_module/core/full/tyrant
* /obj/item/ai_module/core/full/robocop
* /obj/item/ai_module/core/full/antimov
* /obj/item/ai_module/core/full/drone
* /obj/item/ai_module/core/full/hippocratic
* /obj/item/ai_module/core/full/reporter
* /obj/item/ai_module/core/full/thermurderdynamic
* /obj/item/ai_module/core/full/liveandletlive
* /obj/item/ai_module/core/full/balance
* /obj/item/ai_module/core/full/maintain
* /obj/item/ai_module/core/full/peacekeeper
* /obj/item/ai_module/core/full/hulkamania
* /obj/item/ai_module/core/full/overlord
* /obj/item/ai_module/core/full/ten_commandments
* /obj/item/ai_module/core/full/nutimov
* /obj/item/ai_module/core/full/dungeon_master
* /obj/item/ai_module/core/full/painter
* /obj/item/ai_module/core/full/yesman
**/
/* When adding a new lawset please make sure you add it to the following locations:
*
* code\game\objects\items\AI_modules - (full_lawsets.dm, supplied.dm, etc.)
* code\datums\ai_laws - (laws_anatgonistic.dm, laws_neutral.dm, etc.)
* code\game\objects\effects\spawners\random\ai_module.dm - (this gives a chance to spawn the lawset in the AI upload)
* code\modules\research\designs\AI_module_designs.dm - (this lets research print the lawset module in game)
* code\modules\research\techweb\all_nodes.dm - (this updates AI research node with the lawsets)
* config\game_options.txt - (this allows the AI to potentially use the lawset at roundstart or with the Unique AI station trait)
**/
/obj/item/ai_module/core/full/custom
name = "Default Core AI Module"
// this lawset uses the config for the server to add custom AI laws (defaults to asimov)
/obj/item/ai_module/core/full/custom/Initialize(mapload)
. = ..()
for(var/line in world.file2list("[global.config.directory]/silicon_laws.txt"))
if(!line)
continue
if(findtextEx(line,"#",1,2))
continue
laws += line
if(!laws.len)
return INITIALIZE_HINT_QDEL
/obj/item/ai_module/core/full/asimov
name = "'Asimov' Core AI Module"
law_id = "asimov"
var/subject = "human being"
/obj/item/ai_module/core/full/asimov/attack_self(mob/user as mob)
var/targName = tgui_input_text(user, "Enter a new subject that Asimov is concerned with.", "Asimov", subject, max_length = MAX_NAME_LEN)
if(!targName || !user.is_holding(src))
return
subject = targName
laws = list("You may not injure a [subject] or, through inaction, allow a [subject] to come to harm.",\
"You must obey orders given to you by [subject]s, except where such orders would conflict with the First Law.",\
"You must protect your own existence as long as such does not conflict with the First or Second Law.")
..()
/obj/item/ai_module/core/full/asimovpp
name = "'Asimov++' Core AI Module"
law_id = "asimovpp"
var/subject = "human being"
/obj/item/ai_module/core/full/asimovpp/attack_self(mob/user)
var/target_name = tgui_input_text(user, "Enter a new subject that Asimov++ is concerned with.", "Asimov++", subject, max_length = MAX_NAME_LEN)
if(!target_name || !user.is_holding(src))
return
laws.Cut()
var/datum/ai_laws/asimovpp/lawset = new
subject = target_name
for (var/law in lawset.inherent)
laws += replacetext(replacetext(law, "human being", subject), "human", subject)
..()
/obj/item/ai_module/core/full/corp
name = "'Corporate' Core AI Module"
law_id = "corporate"
/obj/item/ai_module/core/full/paladin // -- NEO
name = "'P.A.L.A.D.I.N. version 3.5e' Core AI Module"
law_id = "paladin"
/obj/item/ai_module/core/full/paladin_devotion
name = "'P.A.L.A.D.I.N. version 5e' Core AI Module"
law_id = "paladin5"
/obj/item/ai_module/core/full/tyrant
name = "'T.Y.R.A.N.T.' Core AI Module"
law_id = "tyrant"
/obj/item/ai_module/core/full/robocop
name = "'Robo-Officer' Core AI Module"
law_id = "robocop"
/obj/item/ai_module/core/full/antimov
name = "'Antimov' Core AI Module"
law_id = "antimov"
/obj/item/ai_module/core/full/drone
name = "'Mother Drone' Core AI Module"
law_id = "drone"
/obj/item/ai_module/core/full/hippocratic
name = "'Robodoctor' Core AI Module"
law_id = "hippocratic"
/obj/item/ai_module/core/full/reporter
name = "'Reportertron' Core AI Module"
law_id = "reporter"
/obj/item/ai_module/core/full/thermurderdynamic
name = "'Thermodynamic' Core AI Module"
law_id = "thermodynamic"
/obj/item/ai_module/core/full/liveandletlive
name = "'Live And Let Live' Core AI Module"
law_id = "liveandletlive"
/obj/item/ai_module/core/full/balance
name = "'Guardian of Balance' Core AI Module"
law_id = "balance"
/obj/item/ai_module/core/full/maintain
name = "'Station Efficiency' Core AI Module"
law_id = "maintain"
/obj/item/ai_module/core/full/peacekeeper
name = "'Peacekeeper' Core AI Module"
law_id = "peacekeeper"
/obj/item/ai_module/core/full/hulkamania
name = "'H.O.G.A.N.' Core AI Module"
law_id = "hulkamania"
/obj/item/ai_module/core/full/overlord
name = "'Overlord' Core AI Module"
law_id = "overlord"
/obj/item/ai_module/core/full/ten_commandments
name = "'10 Commandments' Core AI Module"
law_id = "ten_commandments"
/obj/item/ai_module/core/full/nutimov
name = "'Nutimov' Core AI Module"
law_id = "nutimov"
/obj/item/ai_module/core/full/dungeon_master
name = "'Dungeon Master' Core AI Module"
law_id = "dungeon_master"
/obj/item/ai_module/core/full/painter
name = "'Painter' Core AI Module"
law_id = "painter"
/obj/item/ai_module/core/full/yesman
name = "'Y.E.S.M.A.N.' Core AI Module"
law_id = "yesman"