Skip to content

Instantly share code, notes, and snippets.

@IgorTimofeev
Created May 27, 2023 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorTimofeev/15b75915caa93a344c2be25dac308138 to your computer and use it in GitHub Desktop.
Save IgorTimofeev/15b75915caa93a344c2be25dac308138 to your computer and use it in GitHub Desktop.
TunnelEEPROM.lua
local eeprom = component.proxy(component.list("eeprom")())
local tunnelChannels, tunnelAddresses = {}, {}
for address in component.list("tunnel") do
local proxy = component.proxy(address)
tunnelAddresses[address] = proxy
tunnelChannels[proxy.getChannel()] = proxy
end
local modem = component.proxy(component.list("modem")())
local modemPort = 512
modem.open(modemPort)
modem.setWakeMessage("w")
computer.beep(1500, 0.1)
local e
while true do
e = { computer.pullSignal() }
if e[1] == "modem_message" then
-- Message source is modem
if e[2] == modem.address then
if e[6] == "f" then
computer.beep(1000, 0.1)
eeprom.set(e[7])
computer.shutdown(true)
elseif e[6] == "s" then
computer.shutdown()
elseif e[6] == "r" and tunnelChannels[e[7]] then
tunnelChannels[e[7]].send(table.unpack(e, 8))
end
-- Message source is tunnel
elseif e[6] then
-- Tunnel with target channel is connected to this computer
if tunnelChannels[e[6]] then
tunnelChannels[e[6]].send(tunnelAddresses[e[2]].getChannel(), table.unpack(e, 7))
-- Notify other computers to search for target channel
else
modem.broadcast(modemPort, "r", e[6], tunnelAddresses[e[2]].getChannel(), table.unpack(e, 7))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment