nsh improvements, now supports closing of sessions
This commit is contained in:
parent
fa3338589f
commit
3ded060771
@ -4,8 +4,10 @@ local function nshcw(h,p)
|
||||
while true do
|
||||
local sI = os.getenv("sI")
|
||||
local ev = {event.pull()}
|
||||
if ev[1] == "net_msg" and ev[2] == h and ev[3] == p then
|
||||
write(ev[4])
|
||||
if ev[1] == "net_msg" and ev[2] == h and ev[3] == p and ev[4]:sub(1,1) == "d" then
|
||||
write(ev[4]:sub(2))
|
||||
elseif ev[1] == "net_msg" and ev[2] == h and ev[3] == p and ev[4]:sub(1,1) == "\27" then
|
||||
break
|
||||
elseif ev[1] == "key" and ev[2] == sI then
|
||||
net.send(h,p,string.char(ev[3],ev[4]))
|
||||
end
|
||||
|
@ -1,30 +1,34 @@
|
||||
local tA = {...}
|
||||
local nport = tA[1] or "23"
|
||||
function nshdw(h,p,s)
|
||||
spawn("nshdw["..tostring(s).."]",function() print(pcall(function()
|
||||
spawn("nshdw["..tostring(s).."]",function() log(xpcall(function()
|
||||
while true do
|
||||
local sI = os.getenv("sI")
|
||||
local ev = {event.pull()}
|
||||
if ev[1] == "net_msg" and ev[2] == h and ev[3] == p then
|
||||
event.push("key",sI,string.byte(ev[4]:sub(1,1)),string.byte(ev[4]:sub(2,2)))
|
||||
elseif ev[1] == "key" and ev[2] == sI and ev[3] == 3 and ev[4] == 46 then
|
||||
break
|
||||
elseif ev[1] == "display" and ev[2] == sI then
|
||||
if ev[3]:len() < 1024 then
|
||||
net.send(h,p,ev[3])
|
||||
net.send(h,p,"d"..ev[3])
|
||||
else
|
||||
for i = 1, ev[3]:len(), 1024 do
|
||||
net.send(h,p,ev[3]:sub(i,i+1023))
|
||||
net.send(h,p,"d"..ev[3]:sub(i,i+1023))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
net.send(h,p,"\27")
|
||||
end)) end,{sI=s})
|
||||
end
|
||||
spawn("nshd["..tostring(nport).."]",function() print(pcall(function()
|
||||
spawn("nshd["..tostring(nport).."]",function() log(pcall(function()
|
||||
while true do
|
||||
local _, src, port, msg = event.pull("net_msg")
|
||||
if port == nport and msg == "initnsh2" then
|
||||
local cport = math.random(65535-1024,65535)
|
||||
local ns = "nsh-"..tostring(cport)
|
||||
log("[nshd] Starting nsh session "..tostring(cport).." for "..src)
|
||||
net.send(src,port,tostring(cport))
|
||||
luash(ns)
|
||||
nshdw(src,cport,ns)
|
||||
|
Loading…
Reference in New Issue
Block a user