-
-
Save IgorTimofeev/15b75915caa93a344c2be25dac308138 to your computer and use it in GitHub Desktop.
TunnelEEPROM.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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