Posted 22 March 2012 - 06:32 PM
okay, here is the code, i am trying to use runTerm()
local mode="node"
local nodes={}
local terms={}
local side="right"
local mem
local netp="123"
function Smode(a)
mode=a
end
function con(a)
for i=1, #terms, 1 do
if terms[i]==a then return true end
end
return false
end
function add(a,:(/>/>
if b==netp then table.insert(nodes, a) end
if b=="term" then table.insert(terms, a) end
end
function ping()
if mode=="term" then rednet.broadcast("ping") else rednet.broadcast(netp) end
os.startTimer(3)
local a,b,c=os.pullEvent()
while a~="timer" do
if a=="rednet_message" and (c==netp or c=="term") then add(b,c) end
end
end
function pong(b,c)
if mode=="node" and c==netp then
rednet.send(b, netp)
else
rednet.send(b,"term")
end
return true
end
function getID(message)
local id=""
local text=""
id=string.sub(message,3,4)
text=string.sub(message,5)
return tonumber(id), text
end
function route(a, r)
for i=1,#nodes,1 do
if nodes[i]~=r then
rednet.send(nodes[i],a)
end
end
return false
end
function relay(message, r)
local id, a=getID(message)
if not con(id) then
if message==mem then return false end
route(message, r)
else rednet.send(id, a)
end
end
function runNode()
rednet.open(side)
Smode("node")
ping()
while true do
a,b,c=os.pullEvent("rednet_message")
if c==netp or c=="ping" then pong(b,c)
else relay(c,:)/>/>
end
end
end
function runTerm()
rednet.open(side)
Smode("term")
ping()
while true do
a,b,c=os.pullEvent()
if a=="rednet_message" then
if c=="ping" then pong() else print(b," ",c) end
end
if a=="key" and b~=1 then local id=tonumber(read()) local message="00"..id..read() route(message, os.computerID()) end
end
end