2017-09-05 06:09:31 +00:00
|
|
|
requireInjector(getfenv(1))
|
|
|
|
|
|
|
|
local Event = require('event')
|
|
|
|
local Socket = require('socket')
|
2016-12-11 19:24:52 +00:00
|
|
|
local Terminal = require('terminal')
|
2017-09-05 06:09:31 +00:00
|
|
|
local Util = require('util')
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
local remoteId
|
|
|
|
local args = { ... }
|
|
|
|
if #args == 1 then
|
|
|
|
remoteId = tonumber(args[1])
|
|
|
|
else
|
|
|
|
print('Enter host ID')
|
|
|
|
remoteId = tonumber(read())
|
|
|
|
end
|
|
|
|
|
|
|
|
if not remoteId then
|
|
|
|
error('Syntax: telnet <host ID>')
|
|
|
|
end
|
|
|
|
|
|
|
|
print('connecting...')
|
|
|
|
local socket = Socket.connect(remoteId, 23)
|
|
|
|
|
|
|
|
if not socket then
|
|
|
|
error('Unable to connect to ' .. remoteId .. ' on port 23')
|
|
|
|
end
|
|
|
|
|
|
|
|
local ct = Util.shallowCopy(term.current())
|
|
|
|
if not ct.isColor() then
|
|
|
|
Terminal.toGrayscale(ct)
|
|
|
|
end
|
|
|
|
|
|
|
|
local w, h = ct.getSize()
|
|
|
|
socket:write({
|
|
|
|
width = w,
|
|
|
|
height = h,
|
|
|
|
isColor = ct.isColor(),
|
|
|
|
})
|
|
|
|
|
2017-07-24 02:37:07 +00:00
|
|
|
Event.addRoutine(function()
|
2016-12-11 19:24:52 +00:00
|
|
|
while true do
|
|
|
|
local data = socket:read()
|
|
|
|
if not data then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
for _,v in ipairs(data) do
|
|
|
|
ct[v.f](unpack(v.args))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
ct.clear()
|
|
|
|
ct.setCursorPos(1, 1)
|
|
|
|
|
2017-05-20 07:43:19 +00:00
|
|
|
local filter = Util.transpose({
|
2017-08-09 14:19:00 +00:00
|
|
|
'char', 'paste', 'key', 'key_up', 'terminate',
|
2017-05-26 01:06:17 +00:00
|
|
|
'mouse_scroll', 'mouse_click', 'mouse_drag', 'mouse_up',
|
2017-05-10 10:11:25 +00:00
|
|
|
})
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
while true do
|
2017-08-09 14:19:00 +00:00
|
|
|
local e = { os.pullEventRaw() }
|
2016-12-11 19:24:52 +00:00
|
|
|
local event = e[1]
|
|
|
|
|
2017-08-09 14:19:00 +00:00
|
|
|
if filter[event] then
|
|
|
|
socket:write(e)
|
|
|
|
else
|
|
|
|
Event.processEvent(e)
|
|
|
|
end
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
if not socket.connected then
|
|
|
|
print()
|
|
|
|
print('Connection lost')
|
|
|
|
print('Press enter to exit')
|
2017-09-05 06:09:31 +00:00
|
|
|
pcall(read)
|
2016-12-11 19:24:52 +00:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|