added fget/fgetd, a simple file server.

This commit is contained in:
Izaya 2017-07-16 00:58:08 +10:00
parent a2a5925399
commit 74ae2b3523
4 changed files with 54 additions and 1 deletions

View File

@ -23,6 +23,8 @@ net/nshc.lua
net/nshd-auth.lua net/nshd-auth.lua
net/nshc-auth.lua net/nshc-auth.lua
net/pxesrv.lua net/pxesrv.lua
net/fget.lua
net/fgetd.lua
applications/shutil.lua applications/shutil.lua
applications/skex2.lua applications/skex2.lua
applications/luash-login.lua applications/luash-login.lua

View File

@ -2,11 +2,12 @@ base/header.lua
library/print.lua library/print.lua
library/net.lua library/net.lua
library/readline.lua library/readline.lua
net/nshd.lua
library/crc32.lua library/crc32.lua
library/chauth.lua library/chauth.lua
net/nshd.lua net/nshd.lua
net/nshd-auth.lua net/nshd-auth.lua
net/fgetd.lua
net/fget.lua
applications/luash-login.lua applications/luash-login.lua
applications/shutil.lua applications/shutil.lua
library/fs-min.lua library/fs-min.lua

15
modules/net/fget.lua Normal file
View File

@ -0,0 +1,15 @@
function fget(addr,path,port)
local port,S = port or "fget",""
ns(addr,port,path)
while true do
if ev[1] == "net_msg" and ev[2] == addr and ev[3] == port then
if ev[4] == "." then
break
else
S=S..ev[4]
end
end
C.yield()
end
return S
end

35
modules/net/fgetd.lua Normal file
View File

@ -0,0 +1,35 @@
function fgetd_w(evPP,nid,pth)
local c,S = "",false
if pth:sub(-1) == "/" then
local ft=flist(pth)
if ft then
for k,v in ipairs(ft) do c=c..v.."\n" end S=true
else
c="failed to open dir"
end
else
local f=io.open(pth)
if f then
c=f:read("*a")
f:close()
S=true
else
c="failed to open file"
end
end
print(c)
for i = 1, c:len(), 2048 do
ns(nid,evPP,c:sub(i,i+2047))
C.yield()
end
ns(nid,evPP,".")
return S
end
function fgetd(evPP,preP)
while true do
if ev[1] == "net_msg" and ev[3] == evPP then -- f,p,m
print("[fget] "..TS(ev[4])..": "..tostring(fgetd_w(ev[3],ev[2],preP.."/"..ev[4])))
end
C.yield()
end
end