Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args={...}
- local hopSlice = tonumber(args[1]) or 1
- local modems = {}
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v)=="modem" then
- modems[#modems+1] = peripheral.wrap(v)
- end
- end
- local modemColors = {}
- local count = 1
- for k,v in pairs(colors) do
- if type(v) == "number" then
- modemColors[count] = v
- count = count + 1
- if count > #modems then break end
- end
- end
- print("Found " .. #modems .. " modem"..(#modems>1 and "s " or " ")..", estimated total hop time is " .. (65535 / (#modems * 128)) * hopSlice .. " seconds.")
- local i=0
- local num = 0
- local logFile = fs.open("log","a")
- function log(s)
- logFile.writeLine(s)
- end
- local space = 65536 / #modems
- term.clear()
- term.setBackgroundColor(colors.white)
- while true do
- for i=0,space,128 do -- get the block size
- local open={}
- print("Hopping block " .. i)
- for i=i,i+127 do
- for j=1,#modems do
- local c = math.floor(i + ((j-1) * space)) % 65535
- modems[j].open(c)
- open[c]=j
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,1)
- local xSize,ySize = term.getSize()
- for j = 1,512 do
- if open[j * 128] then
- term.setBackgroundColor(modemColors[open[j * 128]])
- end
- io.write(open[j*128] or " ")
- term.setBackgroundColor(colors.white)
- end
- os.startTimer(hopSlice)
- while true do
- local e,side,recvChan,replyChan,msg,dist = os.pullEvent()
- if e == "timer" then
- break
- elseif e == "modem_message" then
- log(recvChan .. ":" .. replyChan .. ":"..msg)
- print("Message on " .. recvChan .. ":" .. replyChan .. ", '"..msg.."'")
- num = num + 1
- end
- end
- for j=1,#modems do
- modems[j].closeAll()
- end
- end
- print("Round finished, logged " .. num .. " messages, press any key to continue, enter to finish.")
- if io.read()=="" then break end
- num = 0
- end
- for j=1,#modems do
- modems[j].closeAll()
- end
- logFile.close()
Advertisement
Add Comment
Please, Sign In to add comment