Merge pull request #6 from XeonSquared/dev
Bunches of networking-related stuff.
This commit is contained in:
commit
f6fd0d6930
@ -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
|
||||
|
@ -1,4 +1,5 @@
|
||||
function nshc(evPP,nid)
|
||||
write("\f")
|
||||
while true do
|
||||
if ev[1] == "net_msg" then
|
||||
local V,msg=false,tostring(ev[4])
|
||||
|
@ -1,4 +1,4 @@
|
||||
evPP,tEPs=4,{}
|
||||
evPP,tEPs="nsh",{}
|
||||
s("netsh daemon",function()
|
||||
while true do
|
||||
if ev[1] == "net_msg" then
|
||||
|
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
|
@ -1,4 +1,4 @@
|
||||
reP,tREs=4,{}
|
||||
reP,tREs="rexec",{}
|
||||
s("rexec",function()
|
||||
while true do
|
||||
if ev[1] == "net_msg" then
|
||||
|
39
modules/library/base64.lua
Normal file
39
modules/library/base64.lua
Normal file
@ -0,0 +1,39 @@
|
||||
-- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
|
||||
-- Slightly modified by Izaya/XeonSquared
|
||||
-- licensed under the terms of the LGPL2
|
||||
do
|
||||
-- character table string
|
||||
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
||||
|
||||
-- encoding
|
||||
function b64(data)
|
||||
data=tostring(data)
|
||||
return ((data:gsub('.', function(x)
|
||||
local r,b='',x:byte()
|
||||
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
|
||||
return r;
|
||||
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
|
||||
if (#x < 6) then return '' end
|
||||
local c=0
|
||||
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
|
||||
return b:sub(c+1,c+1)
|
||||
end)..({ '', '==', '=' })[#data%3+1])
|
||||
end
|
||||
|
||||
-- decoding
|
||||
function ub64(data)
|
||||
data=tostring(data)
|
||||
data = string.gsub(data, '[^'..b..'=]', '')
|
||||
return (data:gsub('.', function(x)
|
||||
if (x == '=') then return '' end
|
||||
local r,f='',(b:find(x)-1)
|
||||
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
|
||||
return r;
|
||||
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
|
||||
if (#x ~= 8) then return '' end
|
||||
local c=0
|
||||
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
|
||||
return string.char(c)
|
||||
end))
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user