28 lines
649 B
Lua
28 lines
649 B
Lua
net = {}
|
|
net.id = computer.address():sub(1,8)
|
|
net.vlan = 1
|
|
net.np = 4096
|
|
net.tm = {}
|
|
function net.send(id,po,msg) -- id, port, message
|
|
event.push("sendmsg",id,po,msg)
|
|
end
|
|
spawn("network daemon",function ()
|
|
for a,t in component.list("modem") do
|
|
table.insert(net.tm,component.proxy(a))
|
|
component.proxy(a).open(net.vlan)
|
|
end
|
|
while true do
|
|
local ev = {event.pull()}
|
|
if ev[1] == "sendmsg" then
|
|
local eT = ev
|
|
for k,v in ipairs(net.tm) do
|
|
v.broadcast(net.vlan,net.np,eT[2],net.id,eT[3],eT[4])
|
|
end
|
|
elseif ev[1] == "modem_message" then
|
|
if ev[7] == net.id then
|
|
event.push("net_msg",ev[8],ev[9],ev[10])
|
|
end
|
|
end
|
|
end
|
|
end)
|