Posted 30 December 2012 - 09:15 AM
Just a quick post to share a little program I've used for a while. This is a rednet relayer that takes two computer IDs as arguments, and forwards all traffic from one to the other. It also displays all of the traffic on its screen. When you're done recording the traffic, hit Q and it will output the full log into the file "rednet_log" for you to analyze (good for busy connections where you might miss something that doesn't fit on the screen). It's on pastebin (of course) at id NHjxbGdT. It's also fairly small, so here's the whole code as well:
args = {...}
if #args < 2 or tonumber(args[1]) == nil or tonumber(args[2]) == nil then
print("Usage:")
print("redrelay <id> <id>")
return
else
local modemFound = false
for _,side in ipairs(rs.getSides()) do
if peripheral.getType(side) == "modem" then
rednet.open(side)
modemFound = true
break
end
end
if not modemFound then
print("No modem found!")
return
end
end
local logTable = {}
local id1, id2 = tonumber(args[1]), tonumber(args[2])
while true do
event = {os.pullEvent()}
if event[1] == "rednet_message" then
if event[2] == id1 or event[2] == id2 then
print(event[2]..": "..event[3])
table.insert(logTable, event[2]..": "..event[3])
rednet.send(event[2] == id1 and id2 or id1, event[3])
end
elseif event[1] == "char" and event[2] == "q" then
handle = io.open("/rednet_log", "w")
if handle then
for i=1, #logTable do
handle:write(logTable[i].."\n")
end
handle:close()
end
return
end
end