Added network bridging OVER IRC
This commit is contained in:
parent
c6e3ff89f1
commit
4181299de5
@ -6,9 +6,12 @@ library/net.lua
|
||||
library/fs-min.lua
|
||||
library/fs-std.lua
|
||||
library/fs-ext.lua
|
||||
library/fs-util.lua
|
||||
library/base64.lua
|
||||
util/fs-automount.lua
|
||||
applications/shutil.lua
|
||||
applications/evproxy-srv.lua
|
||||
applications/evproxy-client.lua
|
||||
applications/ircbridge.lua
|
||||
applications/luash.lua
|
||||
base/footer.lua
|
||||
|
68
modules/applications/ircbridge.lua
Normal file
68
modules/applications/ircbridge.lua
Normal 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
|
Loading…
Reference in New Issue
Block a user