2018-07-28 23:50:24 +10:00
|
|
|
|
-- This is released into the public domain.
|
|
|
|
|
-- No warranty is provided, implied or otherwise.
|
|
|
|
|
|
2020-04-03 08:07:14 +11:00
|
|
|
|
-- app-telnet.lua : just a utility now
|
2018-07-28 23:50:24 +10:00
|
|
|
|
-- Authors: 20kdc
|
|
|
|
|
|
|
|
|
|
local inet = neo.requireAccess("c.internet", "internet").list()()
|
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
local _, _, termId = ...
|
|
|
|
|
local ok = pcall(function ()
|
|
|
|
|
assert(string.sub(termId, 1, 12) == "x.neo.pub.t/")
|
|
|
|
|
end)
|
2018-07-28 23:50:24 +10:00
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
local termClose
|
2018-07-28 23:50:24 +10:00
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
if not ok then
|
|
|
|
|
termId = nil
|
|
|
|
|
assert(neo.executeAsync("svc-t", function (res)
|
|
|
|
|
termId = res.access
|
|
|
|
|
termClose = res.close
|
|
|
|
|
neo.scheduleTimer(0)
|
|
|
|
|
end, "kmt"))
|
|
|
|
|
while true do
|
|
|
|
|
if coroutine.yield() == "k.timer" then break end
|
2018-07-28 23:50:24 +10:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-03 00:33:14 +11:00
|
|
|
|
local term = neo.requireAccess(termId, "terminal")
|
2018-07-28 23:50:24 +10:00
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
term.write([[
|
|
|
|
|
┎┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┒
|
|
|
|
|
┋ ┃ ╱ ┃╲ ╱┃ ▀▀┃▀▀ ┋
|
|
|
|
|
┋ ┃╳ ┃ ╲ ╱ ┃ ┃ ┋
|
|
|
|
|
┋ ┃ ╲ ┃ ╲╱ ┃ ┃ ┋
|
|
|
|
|
┋ ┋
|
|
|
|
|
┋ KittenOS NEO MUD Terminal ┋
|
|
|
|
|
┖┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┚
|
2020-04-03 07:39:30 +11:00
|
|
|
|
export TERM=ansi.sys <- IMPORTANT!!!
|
2020-04-03 00:33:14 +11:00
|
|
|
|
Enter target server:port...
|
|
|
|
|
]])
|
2018-07-28 23:50:24 +10:00
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
local targetBuffer = ""
|
2018-07-28 23:50:24 +10:00
|
|
|
|
|
2020-04-03 00:33:14 +11:00
|
|
|
|
neo.scheduleTimer(0)
|
2018-07-28 23:50:24 +10:00
|
|
|
|
while true do
|
|
|
|
|
local e = {coroutine.yield()}
|
|
|
|
|
if e[1] == "k.timer" then
|
2020-04-03 00:33:14 +11:00
|
|
|
|
while tcp do
|
2018-07-29 02:20:43 +10:00
|
|
|
|
local b, e = tcp.read(neo.readBufSize)
|
2018-07-28 23:50:24 +10:00
|
|
|
|
if not b then
|
|
|
|
|
if e then
|
2020-04-03 00:33:14 +11:00
|
|
|
|
term.write("\nkmt: " .. tostring(e) .. "\n")
|
2018-07-28 23:50:24 +10:00
|
|
|
|
tcp.close()
|
2020-04-03 00:33:14 +11:00
|
|
|
|
tcp = nil
|
2018-07-28 23:50:24 +10:00
|
|
|
|
end
|
|
|
|
|
elseif b == "" then
|
|
|
|
|
break
|
2018-07-29 02:20:43 +10:00
|
|
|
|
else
|
2020-04-03 00:33:14 +11:00
|
|
|
|
term.write(b)
|
2018-07-28 23:50:24 +10:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-03 00:33:14 +11:00
|
|
|
|
neo.scheduleTimer(os.uptime() + 0.049)
|
|
|
|
|
elseif e[1] == "k.procdie" then
|
|
|
|
|
if e[3] == term.pid then
|
|
|
|
|
break
|
|
|
|
|
end
|
|
|
|
|
elseif e[1] == termId then
|
|
|
|
|
if targetBuffer and e[2] == "data" then
|
|
|
|
|
targetBuffer = targetBuffer .. e[3]:gsub("\r", "")
|
|
|
|
|
local p = targetBuffer:find("\n")
|
|
|
|
|
if p then
|
|
|
|
|
local ok, res, rer = pcall(inet.connect, targetBuffer:sub(1, p - 1))
|
|
|
|
|
targetBuffer = targetBuffer:sub(p + 1):gsub("\n", "\r\n")
|
|
|
|
|
if not ok then
|
|
|
|
|
-- Likes to return this kind
|
|
|
|
|
term.write("kmt: " .. tostring(res) .. "\n")
|
|
|
|
|
elseif not res then
|
|
|
|
|
-- Could theoretically return this kind
|
|
|
|
|
term.write("kmt: " .. tostring(rer) .. "\n")
|
|
|
|
|
else
|
|
|
|
|
-- Hopefully this kind
|
|
|
|
|
term.write("kmt: Connecting...\n")
|
|
|
|
|
tcp = res
|
|
|
|
|
tcp.write(targetBuffer)
|
|
|
|
|
targetBuffer = nil
|
2018-07-28 23:50:24 +10:00
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-03 00:33:14 +11:00
|
|
|
|
elseif tcp and e[2] == "data" or e[2] == "telnet" then
|
|
|
|
|
tcp.write(e[3])
|
2018-07-28 23:50:24 +10:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2020-04-03 00:33:14 +11:00
|
|
|
|
|
|
|
|
|
if tcp then
|
|
|
|
|
tcp.close()
|
|
|
|
|
end
|
|
|
|
|
|