Skip to content

Allows players to load circuits via files/json input at the module duplicator using a circuit multitool#89

Open
hyperjll wants to merge 3 commits intopeppyrmynt:masterfrom
hyperjll:Load-Circuit-For-Players
Open

Allows players to load circuits via files/json input at the module duplicator using a circuit multitool#89
hyperjll wants to merge 3 commits intopeppyrmynt:masterfrom
hyperjll:Load-Circuit-For-Players

Conversation

@hyperjll
Copy link
Copy Markdown
Contributor

About The Pull Request

Gives players an option to quickly load circuits they've made and saved in JSON code. It's sad there's no option to save circuits between rounds.

Why It's Good For The Game

Cuts down on a LOT of repetition in making circuits, as well as allowing players to preserve any progress they've made should a round end too quickly.

Changelog

🆑
add: Using a circuit multitool on a module duplicator allows you to load circuits via local files or JSON input.
/:cl:

Using a circuit multitool on the module duplicator allows players to utilize the "Load Circuit" verb which is sorely under-utilized.
@forgman6
Copy link
Copy Markdown
Collaborator

forgman6 commented Dec 14, 2025

Hi I dont know how to comment on files but load_circuit_data() needs to be configured to sanitize external player input.
It looks like players can spawn any item by imputing the json.
code\modules\wiremod\core\duplicator.dm

/obj/item/integrated_circuit/proc/load_circuit_data(json_data, list/errors)
  var/list/general_data = json_decode(json_data)
  ... 
  var/list/external_objects = general_data["external_objects"]
	  for(var/identifier in external_objects)
		  var/list/object_data = external_objects[identifier]
		  var/type = text2path(object_data["type"])
		  if(!ispath(type))
			  LOG_ERROR(errors, "Invalid path for external object, expected a path, got [type]")
			  continue
		  var/atom/movable/object = new type(drop_location())

This needs to be fixed for the PR to work

	admin_only = general_data["admin_only"]

@hyperjll
Copy link
Copy Markdown
Contributor Author

Got any examples for me to work with? I'd prefer having the code look like something the maintainers want as opposed to whatever code spaghetti I might cook up.

@forgman6
Copy link
Copy Markdown
Collaborator

Ill check tomorrow, maybe

@forgman6
Copy link
Copy Markdown
Collaborator

I didnt see anything I liked, but heres some things it should do.

  • use safe_json_decode instead of json_decode
  • limit text input to 1000 chars. Remove fileinput option.
  • to sanitize, remove anything thats not alphanumeric or syntax, do this before json decode
  • create a new proc load_circuit_data_external, and rename load_circuit_data to load_circuit_data_internal so they aren't confused
  • admin_only should always be false
  • instead of creating components and programming them, make it so you still have to add components manually, but you can program them with the tool

Removes file upload option, and makes the loading of circuit data safer by preventing runtimes and preventing the circuit from being admin-only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants