1
0
mirror of https://github.com/XeonSquared/OC-Copper.git synced 2024-11-17 07:18:06 +11:00
OC-Copper/oc/occure.lua

54 lines
1.3 KiB
Lua
Raw Normal View History

-- I, 20kdc, release this into the public domain.
-- No warranty is provided, implied or otherwise.
2017-03-19 08:21:27 +11:00
-- OC/CU/RE Driver
-- (Copper w/Reliability Layer on OpenComputers/OpenOS)
-- I, 20kdc, release this into the public domain.
-- No warranty is provided, implied or otherwise.
local event = require("event")
local computer = require("computer")
local component = require("component")
local modems = {}
local args = {...}
if #args ~= 1 then error("Needs hostname") end
local host = tostring(args[1])
if package.loaded["occure"] then
error("Already installed")
end
local culib = require("culib")
2017-03-19 08:21:27 +11:00
local node = require("relib")(host, function (tgt, data)
for _, v in ipairs(modems) do
if tgt then
v.send(tgt, 4957, "copper", data)
else
v.broadcast(4957, "copper", data)
end
end
end, function (...)
computer.pushSignal("copper_packet", ...)
end, computer.uptime, culib)
2017-03-19 08:21:27 +11:00
for v, _ in component.list("modem") do
local m = component.proxy(v)
table.insert(modems, m)
m.open(4957)
end
package.loaded["occure"] = node
2017-03-19 08:21:27 +11:00
event.listen("modem_message", function (et, adto, adfrom, port, dist, magic, data)
if et ~= "modem_message" then return end
if port == 4957 then
if magic == "copper" then
if type(data) == "string" then
node.input(adfrom, data)
end
2017-03-19 08:21:27 +11:00
end
end
end)
event.timer(1, node.refresh, math.huge)