2017-10-25 03:01:40 +00:00
|
|
|
local Event = require('event')
|
|
|
|
local Socket = require('socket')
|
|
|
|
|
|
|
|
Event.addRoutine(function()
|
2018-01-24 22:39:38 +00:00
|
|
|
while true do
|
|
|
|
print('proxy: listening on port 188')
|
|
|
|
local socket = Socket.server(188)
|
2017-10-25 03:01:40 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
print('proxy: connection from ' .. socket.dhost)
|
2017-10-25 03:01:40 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
Event.addRoutine(function()
|
|
|
|
local api = socket:read(2)
|
|
|
|
if api then
|
2017-10-25 03:01:40 +00:00
|
|
|
local proxy = _G[api]
|
|
|
|
|
2018-02-06 13:45:43 +00:00
|
|
|
if not proxy then
|
|
|
|
print('proxy: invalid API')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
local methods = { }
|
2017-10-25 03:01:40 +00:00
|
|
|
for k,v in pairs(proxy) do
|
|
|
|
if type(v) == 'function' then
|
|
|
|
table.insert(methods, k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
socket:write(methods)
|
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
while true do
|
|
|
|
local data = socket:read()
|
|
|
|
if not data then
|
2017-10-26 22:56:55 +00:00
|
|
|
print('proxy: lost connection from ' .. socket.dhost)
|
2018-01-24 22:39:38 +00:00
|
|
|
break
|
|
|
|
end
|
2019-02-23 23:36:17 +00:00
|
|
|
socket:write({ proxy[data[1]](table.unpack(data, 2)) })
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2017-10-25 03:01:40 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|