Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local enable_sides
- local config_file = fs.open("/branch_config.cfg", "r")
- if config_file then
- local sides = textutils.unserialise(config_file.readAll())
- if sides then
- enable_sides = sides
- else
- print("Malformed config file!")
- end
- else
- print("No config file!")
- end
- if #args < 1 then
- error("Usage: branch <station_name>")
- end
- local station_name = args[1]
- print("Starting branch as station "..station_name)
- local modem = peripheral.find("modem")
- if not modem then
- error("No modem found!")
- end
- modem.open(15) --listen for feeders on channel 15
- os.startTimer(0.05)
- modem.transmit(43, 15, "feeder " .. os.getComputerID() .. " " .. station_name)
- while true do
- local event, ev1, ev2, ev3, ev4, ev5 = os.pullEvent()
- if event == "modem_message" then
- if ev4 == "hub_boot" or ev4 == "hub_scan" then
- modem.transmit(43, 15, "feeder " .. os.getComputerID() .. " " .. station_name)
- else
- local words = {}
- for word in ev4:gmatch("%S+") do
- table.insert(words, word)
- end
- if tonumber(words[1]) == os.getComputerID() then
- if words[2] == "command" then
- --handle a command
- if words[3] == "redstone" then
- redstone.setOutput(words[4], words[5] == "on")
- end
- elseif words[2] == "ping" then
- --return a ping
- modem.transmit(43, 15, "ping_reply " .. os.getComputerID())
- elseif words[2] == "enable" then
- for k, v in pairs(enable_sides) do
- redstone.setOutput(k, v == "true")
- end
- elseif words[2] == "disable" then
- for k, v in pairs(enable_sides) do
- redstone.setOutput(k, v ~= "true")
- end
- end
- end
- end
- elseif event == "timer" then
- os.startTimer(0.05)
- else
- print(event)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment