made nbsrv log rather than print everything
This commit is contained in:
parent
776dca5f27
commit
9def569a2a
@ -2,26 +2,26 @@ local tA = {...}
|
|||||||
local nport = tonumber(tA[1])
|
local nport = tonumber(tA[1])
|
||||||
local fpath = tostring(tA[2])
|
local fpath = tostring(tA[2])
|
||||||
for m in component.list("modem") do
|
for m in component.list("modem") do
|
||||||
print("[nbsrv] opening port on "..m)
|
log("[nbsrv] opening port on "..m)
|
||||||
component.invoke(m,"open",nport)
|
component.invoke(m,"open",nport)
|
||||||
end
|
end
|
||||||
local f=io.open(fpath,"rb")
|
local f=io.open(fpath,"rb")
|
||||||
local nbdata = f:read("*a")
|
local nbdata = f:read("*a")
|
||||||
f:close()
|
f:close()
|
||||||
spawn("nbsrv: "..tostring(nport)..","..fpath,function() print(xpcall(function()
|
spawn("nbsrv: "..tostring(nport)..","..fpath,function() log(xpcall(function()
|
||||||
while true do
|
while true do
|
||||||
local _, laddress, raddress, port, _, payload = event.pull("modem_message")
|
local _, laddress, raddress, port, _, payload = event.pull("modem_message")
|
||||||
if port == nport and type(payload) == "string" then
|
if port == nport and type(payload) == "string" then
|
||||||
if payload:len() == 36 then
|
if payload:len() == 36 then
|
||||||
local sraddress,spayload = raddress:sub(1,8),payload:sub(1,8)
|
local sraddress,spayload = raddress:sub(1,8),payload:sub(1,8)
|
||||||
print("[nbsrv] request from "..sraddress.."/"..spayload.." on port "..tostring(port))
|
log("[nbsrv] request from "..sraddress.."/"..spayload.." on port "..tostring(port))
|
||||||
for i = 1, nbdata:len(), 2048 do
|
for i = 1, nbdata:len(), 2048 do
|
||||||
component.invoke(laddress,"send",raddress,port,nbdata:sub(i,i+2047))
|
component.invoke(laddress,"send",raddress,port,nbdata:sub(i,i+2047))
|
||||||
end
|
end
|
||||||
component.invoke(laddress,"send",raddress,port,".")
|
component.invoke(laddress,"send",raddress,port,".")
|
||||||
print("[nbsrv] served request from "..sraddress.."/"..spayload)
|
log("[nbsrv] served request from "..sraddress.."/"..spayload)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)) end)
|
end)) end)
|
||||||
print("[nbsrv] nbsrv started.")
|
log("[nbsrv] nbsrv started.")
|
||||||
|
Loading…
Reference in New Issue
Block a user