OC-PsychOS/exec/nsh.lua

27 lines
718 B
Lua
Raw Normal View History

2017-09-01 09:07:07 +10:00
tA = {...}
2017-09-10 03:14:46 +10:00
local h,p = tA[1], tonumber(tA[2]) or 23
2017-09-01 09:07:07 +10:00
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 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
2017-09-01 09:07:07 +10:00
elseif ev[1] == "key" and ev[2] == sI then
net.send(h,p,string.char(ev[3],ev[4]))
end
end
end
2017-09-10 03:14:46 +10:00
net.send(h,p,"initnsh2")
2017-09-01 09:07:07 +10:00
local bt = os.time()
local tp,src,port,msg
repeat
tp, src, port, msg = event.pull()
until (tp == "net_msg" and src == h and port == p) or os.time() > bt+16
if tp == "net_msg" then
nshcw(h,tonumber(msg))
else
print("timeout.")
end