1
0
mirror of https://github.com/XeonSquared/OC-Copper.git synced 2024-11-14 22:08:05 +11:00
OC-Copper/oc/occure.lua

54 lines
1.3 KiB
Lua

-- I, 20kdc, release this into the public domain.
-- No warranty is provided, implied or otherwise.
-- 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")
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)
for v, _ in component.list("modem") do
local m = component.proxy(v)
table.insert(modems, m)
m.open(4957)
end
package.loaded["occure"] = node
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
end
end
end)
event.timer(1, node.refresh, math.huge)