2017-10-25 03:01:40 +00:00
|
|
|
local Event = require('event')
|
|
|
|
local Socket = require('socket')
|
|
|
|
|
|
|
|
Event.addRoutine(function()
|
|
|
|
while true do
|
|
|
|
print('proxy: listening on port 188')
|
|
|
|
local socket = Socket.server(188)
|
|
|
|
|
|
|
|
print('proxy: connection from ' .. socket.dhost)
|
|
|
|
|
|
|
|
Event.addRoutine(function()
|
|
|
|
local api = socket:read(2)
|
|
|
|
if api then
|
|
|
|
local proxy = _G[api]
|
|
|
|
|
|
|
|
local methods = { }
|
|
|
|
for k,v in pairs(proxy) do
|
|
|
|
if type(v) == 'function' then
|
|
|
|
table.insert(methods, k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
socket:write(methods)
|
|
|
|
|
|
|
|
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)
|
2017-10-25 03:01:40 +00:00
|
|
|
break
|
|
|
|
end
|
2017-10-26 22:56:55 +00:00
|
|
|
socket:write({ proxy[data.fn](table.unpack(data.args)) })
|
2017-10-25 03:01:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end)
|