Merge pull request #8 from XeonSquared/dev

Another merge.
This commit is contained in:
Izaya 2017-05-09 09:46:00 +10:00 committed by GitHub
commit 8ac8affec7
8 changed files with 106 additions and 8 deletions

1
build.lua Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/usr/bin/env lua5.2
-- Initialization -- Initialization
log = "" log = ""
oldprint=print oldprint=print

7
configs/ircbridge.cfg Normal file
View File

@ -0,0 +1,7 @@
base/header.lua
library/net.lua
library/base64.lua
applications/rexec.lua
applications/ircbridge-embedded.lua
util/loadeeprom.lua
base/footer.lua

View File

@ -9,6 +9,7 @@ library/fs-ext.lua
library/fs-util.lua library/fs-util.lua
library/base64.lua library/base64.lua
util/fs-automount.lua util/fs-automount.lua
net/ping.lua
applications/shutil.lua applications/shutil.lua
applications/evproxy-srv.lua applications/evproxy-srv.lua
applications/evproxy-client.lua applications/evproxy-client.lua

View File

@ -0,0 +1,66 @@
_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)
local ct = computer.uptime()
while computer.uptime() < ct+5 do
C.yield()
c.finishConnect()
end
if c.finishConnect() then
local ct=computer.uptime()
local function wl(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("(.+)!(.+)@(.+)")
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
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
end
end)
s("IRC bridge",function()
while true do
if ev[1] == "modem_message"then
local pa,pb = ev[7]:match("(.+):(.+)")
if pa and pb then tircb[#tircb+1] = {pa,b64(pb)..","..b64(ev[8])..","..b64(ev[9])..","..b64(ev[10])} end
end
coroutine.yield()
end
end)
end

View File

@ -3,7 +3,11 @@ function ircb(h,p,n) -- host, port
s("IRC bridge connector", function() s("IRC bridge connector", function()
local ip,h,p = component.proxy(component.list("internet")()),h,p local ip,h,p = component.proxy(component.list("internet")()),h,p
local c=ip.connect(h,p) local c=ip.connect(h,p)
print("Connected: "..tostring(c.finishConnect())) local ct = computer.uptime()
while computer.uptime() < ct+5 do
C.yield()
c.finishConnect()
end
if c.finishConnect() then if c.finishConnect() then
local ct=computer.uptime() local ct=computer.uptime()
print("Connected successfully.") print("Connected successfully.")
@ -59,8 +63,8 @@ function ircb(h,p,n) -- host, port
s("IRC bridge",function() s("IRC bridge",function()
while true do while true do
if ev[1] == "modem_message"then if ev[1] == "modem_message"then
local pa,pb = ev[6]:match("(.+):(.+)") local pa,pb = ev[7]:match("(.+):(.+)")
if pa and pb then tircb[#tircb+1] = {pa,b64(pb)..","..b64(ev[7])..","..b64(ev[8])..","..b64(ev[9])} end if pa and pb then tircb[#tircb+1] = {pa,b64(pb)..","..b64(ev[8])..","..b64(ev[9])..","..b64(ev[10])} end
end end
coroutine.yield() coroutine.yield()
end end

6
modules/config.lua Normal file
View File

@ -0,0 +1,6 @@
-- nID = "network ID"
-- nVL = "network VLAN"
-- nP = "network port"
-- s("IRC bridge",function()
-- ircb("irc.server",6667,"bridge_name")
-- end)

View File

@ -1,7 +1,7 @@
tM,nP,nID = {}, 4096, 1 tM,nP,nID,nVL = {}, 4096, computer.address(), 1
for a,t in component.list("modem") do for a,t in component.list("modem") do
table.insert(tM,component.proxy(a)) table.insert(tM,component.proxy(a))
component.proxy(a).open(nP) component.proxy(a).open(nVL)
end end
function ns(id,po,msg) function ns(id,po,msg)
h("sendmsg",id,po,msg) h("sendmsg",id,po,msg)
@ -11,11 +11,11 @@ s("network daemon",function ()
if ev[1] == "sendmsg" then if ev[1] == "sendmsg" then
local eT = ev local eT = ev
for k,v in ipairs(tM) do for k,v in ipairs(tM) do
v.broadcast(nP,eT[2],nID,eT[3],eT[4]) v.broadcast(nVL,nP,eT[2],nID,eT[3],eT[4])
end end
elseif ev[1] == "modem_message" then elseif ev[1] == "modem_message" then
if ev[6] == nID then if ev[7] == nID then
h("net_msg",ev[7],ev[8],ev[9]) h("net_msg",ev[8],ev[9],ev[10])
end end
end end
C.yield() C.yield()

13
modules/net/ping.lua Normal file
View File

@ -0,0 +1,13 @@
s("pingd",function()
while true do
if ev[1] == "net_msg" then
if ev[3] == "ping" then
print("ping ("..ev[2].."): "..ev[4])
ns(ev[2],"pong",ev[4])
elseif ev[3] == "pong" then
print("pong ("..ev[2].."): "..ev[4])
end
end
C.yield()
end
end)