-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
executable file
·71 lines (58 loc) · 1.56 KB
/
Copy pathmain.lua
File metadata and controls
executable file
·71 lines (58 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env luajit
require('libs.sockman')
tasker = require('libs.tasker')
telnet = require('libs.telnet')
ocounter = require('libs.ocounter')
menu = require('states.menu')
local grevparse = io.popen('git rev-parse --short HEAD', 'r')
if grevparse then
GIT_COMMIT = grevparse:read('*l')
grevparse:close()
end
local function init(me)
me:sendCommand(
'IAC', 'WILL', 'ECHO',
'IAC', 'WILL', 'SUPP_GO_AHEAD'
)
me:send('Waiting for telnet to respond...')
local ww, wh = me:getDimensions()
while wh < 26 or ww < 83 do
me:fullClear()
me:send('Your terminal window is too small, resize it please.\r\n')
me:send('This check is performed only once,\r\n')
me:send('So please DON\'T resize the terminal window after this screen!\r\n')
me:send('It may lead to unexpected drawing issues\r\n')
me:send(('E: (83, 26)\r\nG: (%d, %d)'):format(ww, wh))
ww, wh = me:waitForDimsChange()
if me:isBroken() then
return false
end
coroutine.yield()
end
me:enableColors(me:supportColors())
return menu:run(me)
end
tasker:newTask(function()
menu:init()
math.randomseed(os.time())
local run = true
local server, ip, port = initServer('*', tonumber(arg[1]) or 2425)
print(('Telnet listener started on: %s:%d'):format(ip, port))
while run do
local cl
repeat
cl, err = acceptClient(server)
if cl then
local tc = telnet.init(cl, true)
tc:setHandler(init)
ocounter:install(tc)
elseif err ~= 'timeout' then
run = false
end
until cl == nil
coroutine.yield()
end
print('Server socket suddenly died')
os.exit(1)
end)
tasker:runLoop()