cc-tweaked / CC-Tweaked

Just another ComputerCraft fork
https://tweaked.cc
882 stars 206 forks source link

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

Open fatboychummy opened 4 years ago

fatboychummy commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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.

xAnavrins commented 3 years ago

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

Lupus590 commented 3 years ago

Do modems fire peripheral events?

SquidDev commented 3 years ago

Yes.

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

fatboychummy commented 3 years ago

@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.