1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-05 08:26:16 +00:00
opus/sys/network/vnc.lua

68 lines
1.6 KiB
Lua
Raw Normal View History

2017-08-03 05:46:39 +00:00
local Event = require('event')
local Socket = require('socket')
local Util = require('util')
2016-12-11 19:24:52 +00:00
2017-10-05 17:07:48 +00:00
local function vncHost(socket)
2016-12-11 19:24:52 +00:00
local methods = { 'blit', 'clear', 'clearLine', 'setCursorPos', 'write',
'setTextColor', 'setTextColour', 'setBackgroundColor',
'setBackgroundColour', 'scroll', 'setCursorBlink', }
socket.term = multishell.term
socket.oldTerm = Util.shallowCopy(socket.term)
for _,k in pairs(methods) do
socket.term[k] = function(...)
if not socket.queue then
socket.queue = { }
2017-08-03 05:46:39 +00:00
Event.onTimeout(0, function()
socket:write(socket.queue)
socket.queue = nil
end)
2016-12-11 19:24:52 +00:00
end
table.insert(socket.queue, {
f = k,
args = { ... },
})
socket.oldTerm[k](...)
end
end
while true do
local data = socket:read()
if not data then
print('vnc: closing connection to ' .. socket.dhost)
break
end
if data.type == 'shellRemote' then
os.queueEvent(unpack(data.event))
2017-10-05 17:07:48 +00:00
elseif data.type == 'termInfo' then
socket.term.getSize = function()
return data.width, data.height
end
os.queueEvent('term_resize')
2016-12-11 19:24:52 +00:00
end
end
for k,v in pairs(socket.oldTerm) do
socket.term[k] = v
end
os.queueEvent('term_resize')
end
2017-08-03 05:46:39 +00:00
Event.addRoutine(function()
2016-12-11 19:24:52 +00:00
print('vnc: listening on port 5900')
while true do
local socket = Socket.server(5900)
print('vnc: connection from ' .. socket.dhost)
2017-10-05 17:07:48 +00:00
-- no new process - only 1 connection allowed
-- due to term size issues
vncHost(socket)
socket:close()
2016-12-11 19:24:52 +00:00
end
2017-08-03 05:46:39 +00:00
end)