OC-PsychOS/exec/nshd.lua

38 lines
1.1 KiB
Lua
Raw Normal View History

2017-09-01 09:07:07 +10:00
local tA = {...}
local nport = tA[1] or "23"
function nshdw(h,p,s)
spawn("nshdw["..tostring(s).."]",function() log(xpcall(function()
2017-09-01 09:07:07 +10:00
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
2017-09-01 09:07:07 +10:00
elseif ev[1] == "display" and ev[2] == sI then
if ev[3]:len() < 1024 then
net.send(h,p,"d"..ev[3])
2017-09-01 09:07:07 +10:00
else
for i = 1, ev[3]:len(), 1024 do
net.send(h,p,"d"..ev[3]:sub(i,i+1023))
2017-09-01 09:07:07 +10:00
end
end
end
end
net.send(h,p,"\27")
2017-09-01 09:07:07 +10:00
end)) end,{sI=s})
end
spawn("nshd["..tostring(nport).."]",function() log(pcall(function()
2017-09-01 09:07:07 +10:00
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)
2017-09-01 09:07:07 +10:00
net.send(src,port,tostring(cport))
luash(ns)
nshdw(src,cport,ns)
end
end
end)) end)