CC-Tweaked icon indicating copy to clipboard operation
CC-Tweaked copied to clipboard

Ability to connect peripherals to a modem via lua (modem api?)

Open fatboychummy opened this issue 5 years ago • 6 comments

So I was making a thing today with turtles which builds some furnaces and etc on top of modems. I, however, ran into a problem which cannot be solved via any available APIs.

I cannot connect said furnaces to the network, unless I walk my character to the location manually and do it myself.

I am requesting a simple addon to the modem API to be able to do this.

It would look something like the following:

local modem = peripheral.wrap("modem_bla")
modem.connect()
modem.disconnect()

this would connect/disconnect all peripherals attached to the modem to the network, and (potentially) return names of the newly added peripherals (much like right-clicking the modem block does). This would be useful not only for plethora, but also when using a turtle to build a computer-cluster attached to modems in 'vanilla' (just cc:tweaked).

fatboychummy avatar Jul 03 '19 23:07 fatboychummy

This could also be addressed by #125, having the ability to right-click a modem would help as well (and do exactly as is stated here). However, a computer would not be able to connect modems.

fatboychummy avatar Jul 03 '19 23:07 fatboychummy

Just adding another idea to this because random thoughts are random:

Having modem_[dis]connected events for when a modem is manually connected or disconnected would be helpful as well for a mainframe to ensure security in a wired network.

fatboychummy avatar Nov 24 '20 04:11 fatboychummy

@fatboychummy peripheral/peripheral_detach events should work on remote peripherals if I'm not mistaken.

xAnavrins avatar Nov 24 '20 09:11 xAnavrins

Do modems fire peripheral events?

Lupus590 avatar Nov 24 '20 11:11 Lupus590

Yes.

https://github.com/SquidDev-CC/CC-Tweaked/blob/fff8353451451be5ae31e0f63d8e529b127fd186/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/WiredModemPeripheral.java#L324-L334

SquidDev avatar Nov 24 '20 11:11 SquidDev

@fatboychummy peripheral/peripheral_detach events should work on remote peripherals if I'm not mistaken.

While yes they do exist, if we get the ability to 'enable or disable' modems via Lua commands, it would be nice to know if the modem has been enabled so we can disable it immediately if need be, rather than looping through each modem to see what modem the peripheral returned by peripheral_attach is attached to.

Alternatively, reenabling modems that got accidentally right-clicked or something.

fatboychummy avatar Nov 26 '20 00:11 fatboychummy