added an okay-enough netbooting system, can somewhat build images on its own

This commit is contained in:
Izaya 2017-07-12 04:15:41 +10:00
parent 5ce319c0e4
commit 43f00e7669

49
modules/net/nbsrv.lua Normal file
View File

@ -0,0 +1,49 @@
for k,v in ipairs(tM) do v.open(9671) end
s("nbsrv",function() print(pcall(function()
print("[netboot] loading data")
local f,tnbd=io.open("boot:/nbsrv.csv"),{}
setmetatable(tnbd,{__index=function(t,k)
return rawget(t,k) or {}
end})
if f then
local c=f:read("*a")
f:close()
for l in c:gmatch("[^\n]+") do
local c,i = 1,""
for d in l:gmatch("[^,]+") do
if c == 1 then
i=d
tnbd[i]={}
else
tnbd[i][#tnbd[i]+1]=d
end
c=c+1
end
end
end
local d,d2="",""
local f=io.open("boot:/nbstart.lua")
if f then
d=f:read("*a")
f:close()
end
local f=io.open("boot:/nbend.lua")
if f then
d2=f:read("*a")
f:close()
end
while true do
if ev[1] == "modem_message" and ev[4] == 9671 then
print("[netboot] request from "..ev[3])
for k,v in ipairs(tnbd[ev[3]]) do
d=d..v.."\n"
end
d=d..d2
for i = 1, d:len(), 2048 do
component.invoke(ev[2],"send",ev[3],9671,d:sub(i,i+2047))
end
component.invoke(ev[2],"send",ev[3],9671,".")
end
C.yield()
end
end)) end)