Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local activeError = nil
- local w, h = term.getSize()
- local spamData = {}
- local ready = false
- local function drawHeader()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.white)
- term.clearLine()
- term.setCursorPos(1, 2)
- term.clearLine()
- term.setTextColor(colors.cyan)
- center("Rednet Spam Monitor by 1lann")
- term.setCursorPos(1, 3)
- term.clearLine()
- end
- local function drawBottomBar(err)
- term.setBackgroundColor(colors.gray)
- if err then
- activeError = err
- term.setCursorPos(1, h)
- term.setTextColor(colors.red)
- term.clearLine()
- center(err)
- else
- activeError = nil
- term.setCursorPos(1, h)
- term.clearLine()
- term.setTextColor(colors.green)
- center("Connected to the server!")
- end
- end
- local function drawData(data)
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- drawHeader()
- drawBottomBar(activeError)
- term.setBackgroundColor(colors.lightGray)
- if #data > 0 then
- for k,v in pairs(data) do
- term.setBackgroundColor(colors.white)
- local baseY = (4 * (k - 1) + 1) + 4
- term.setCursorPos(2, baseY)
- term.write(string.rep(" ", w - 4))
- term.setCursorPos(3, baseY)
- term.setTextColor(colors.red)
- local time = "Ongoing..."
- if v.time > 7 then
- time = math.floor(v.time) .. " secs ago"
- end
- term.write("Computer ID: " .. v.id .. " | Time: " .. time)
- term.setCursorPos(2, baseY + 1)
- term.write(string.rep(" ", w - 4))
- term.setCursorPos(3, baseY + 1)
- term.setTextColor(colors.lightBlue)
- if v.locationA and v.locationB then
- term.write(v.locationA)
- term.setCursorPos(2, baseY + 2)
- term.write(string.rep(" ", w - 4))
- term.setCursorPos(3, baseY + 2)
- term.write(v.locationB)
- else
- term.write(v.locationA)
- end
- end
- else
- term.setCursorPos(1, 9)
- term.setTextColor(colors.lightBlue)
- center("The skies are all clear!")
- term.setCursorPos(1, 10)
- center("No spam to be seen")
- end
- end
- local serverLoop = function()
- while true do
- local rawData = firewolf.query("get")
- if rawData then
- local data = textutils.unserialize(rawData)
- if type(data) == "table" then
- spamData = data
- ready = true
- drawData(data)
- else
- drawBottomBar("Server error!")
- end
- else
- drawBottomBar("Could not connect to server! Retrying...")
- end
- sleep(5)
- end
- end
- local updateLoop = function()
- while true do
- for k,v in pairs(spamData) do
- spamData[k].time = spamData[k].time + 1
- end
- if ready then
- drawData(spamData)
- else
- term.setCursorPos(1, 9)
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.lightBlue)
- center("Connecting...")
- end
- sleep(1)
- end
- end
- drawHeader()
- parallel.waitForAny(serverLoop, updateLoop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement