made the network driver use _G.net for configuration.

This commit is contained in:
Izaya 2017-08-02 23:51:30 +10:00
parent 308c0acad5
commit 581edc74a1

View File

@ -1,21 +1,25 @@
function _G.net_send(id,po,msg) -- id, port, message
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 ()
tM,nP,_G.nID,nVL = {}, 4096, computer.address():sub(1,8), 1
for a,t in component.list("modem") do -- open the port of the vlan on all network interfaces
table.insert(tM,component.proxy(a))
component.proxy(a).open(nVL)
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()} -- this totally isn't just MultICE code with a fancy wrapper
local ev = {event.pull()}
if ev[1] == "sendmsg" then
local eT = ev
for k,v in ipairs(tM) do
v.broadcast(nVL,nP,eT[2],nID,eT[3],eT[4])
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] == nID then
if ev[7] == net.id then
event.push("net_msg",ev[8],ev[9],ev[10])
end
end