Added network bridging OVER IRC

This commit is contained in:
Izaya 2017-05-04 00:54:38 +10:00
parent c6e3ff89f1
commit 4181299de5
2 changed files with 71 additions and 0 deletions

View File

@ -6,9 +6,12 @@ library/net.lua
library/fs-min.lua library/fs-min.lua
library/fs-std.lua library/fs-std.lua
library/fs-ext.lua library/fs-ext.lua
library/fs-util.lua
library/base64.lua
util/fs-automount.lua util/fs-automount.lua
applications/shutil.lua applications/shutil.lua
applications/evproxy-srv.lua applications/evproxy-srv.lua
applications/evproxy-client.lua applications/evproxy-client.lua
applications/ircbridge.lua
applications/luash.lua applications/luash.lua
base/footer.lua base/footer.lua

View File

@ -0,0 +1,68 @@
_G.tircb = {}
function ircb(h,p,n) -- host, port
s("IRC bridge connector", function()
local ip,h,p = component.proxy(component.list("internet")()),h,p
local c=ip.connect(h,p)
print("Connected: "..tostring(c.finishConnect()))
if c.finishConnect() then
local ct=computer.uptime()
print("Connected successfully.")
local function wl(s)
print("-->| "..s)
c.write(s.."\n")
end
_G.wil = wl
function sc(u,s) wl("PRIVMSG "..u.." :"..s) end
local function prs(line)
h,m = string.match(line,":?(.-):(.+)") tH = {}
for w in h:gmatch("%S+") do tH[#tH+1] = w end
if tH[1] == "PING" then
wl("PONG :"..m)
elseif tH[2] == "PRIVMSG" then
local n,r,h = tH[1]:match("(.+)!(.+)@(.+)")
print(n.." ("..r.."@"..h.."): "..m)
local t,f,p,ms = m:match("(.+),(.+),(.+),(.+)")
if t and f and p and ms then
t,f,p,ms = ub64(t),n..":"..ub64(f),ub64(p),ub64(ms)
for k,v in ipairs(tM) do
v.broadcast(nP,t,f,p,ms)
end
end
else
print("|<-- "..line)
end
end
wl("NICK "..n)
wl("USER "..n.." "..n.." "..n.." "..n)
while c.finishConnect() do
coroutine.yield()
local d=c.read()
if type(d) == "string" then
if d ~= "" and d ~= "\n" then
for line in d:gmatch("[^\r\n]+") do
pcall(prs,line)
end
end
end
if ct+0.25 < computer.uptime() then
if #tircb > 0 then
sc(T.unpack(T.remove(tircb,1)))
end
ct=computer.uptime()
end
end
else
print("Failed to connect:")
print(c.finishConnect())
end
end)
s("IRC bridge",function()
while true do
if ev[1] == "modem_message"then
local pa,pb = ev[6]:match("(.+):(.+)")
if pa and pb then tircb[#tircb+1] = {pa,b64(pb)..","..b64(ev[7])..","..b64(ev[8])..","..b64(ev[9])} end
end
coroutine.yield()
end
end)
end