FERROUSSAGE

check owners online

Aug 27th, 2021 (edited)
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local component = require("component")
  2. local computer = require("computer")
  3. local json = require("json")
  4. local gpu = component.gpu
  5. local terminal = require("term")
  6. local fs = require("filesystem")
  7. local shell = require("shell")
  8. local unicode = require("unicode")
  9.  
  10. gpu.setResolution(37, 17)
  11. local w, h = gpu.getResolution()
  12.  
  13. local color = {
  14.     green = 0x00ff00,
  15.     yellow = 0xffb600,
  16.     red = 0xff0000
  17. }
  18.  
  19. local url = "https://api.minetools.eu/query/s9.mcskill.net/25675"
  20.  
  21. local owners = {
  22.     "FERROUS",
  23.     "Hedboys",
  24.     "deadinsideclown",
  25.     "xixiii"
  26. }
  27.  
  28. local status = {
  29.     "online ",
  30.     "offline"
  31. }
  32.  
  33. function dump(table)
  34.     if type(table) == 'table' then
  35.        local s = '{ '
  36.        for k,v in pairs(table) do
  37.           if type(k) ~= 'number' then k = '"'..k..'"' end
  38.           s = s .. '['..k..'] = ' .. dump(v) .. ','
  39.        end
  40.        return s .. '} '
  41.     else
  42.        return tostring(table)
  43.     end
  44. end
  45.  
  46. function parseJson(string)
  47.     return json:decode(string)
  48. end
  49.  
  50. function readFile()
  51.     local dataFromFile
  52.     if fs.exists("/home/infoServer.json") then
  53.         local file = io.open("/home/infoServer.json", "r")
  54.         dataFromFile = file:read("*a")
  55.         file:close()
  56.     end
  57.     return dataFromFile
  58. end
  59.  
  60. function drawBorder()
  61.     gpu.setForeground(color.green)
  62.  
  63.     gpu.fill(1, 1, w, 1, "-")
  64.     gpu.fill(1, h, w, 1, "-")
  65.     gpu.fill(1, 0, 1, h + 1, "|")
  66.     gpu.copy(1, 0, 1, h + 1, w - 1, 0)
  67. end
  68.  
  69. function drawOwners(owner, yPos, indexStatus, colorStatus)
  70.     gpu.setForeground(color.yellow)
  71.     gpu.set(w / 5, (yPos * 2) + yPos, owner)
  72.     gpu.setForeground(colorStatus)
  73.     gpu.set(w - 10, (yPos * 2) + yPos, status[indexStatus])
  74. end
  75.  
  76. for i = 1, #owners do
  77.     computer.addUser(owners[i])
  78. end
  79.  
  80. while true do
  81.     terminal.clear()
  82.  
  83.     local center = (w / 2) / 2
  84.  
  85.     drawBorder()
  86.  
  87.     gpu.setForeground(color.green)
  88.     gpu.set(center, 1, "[")
  89.     gpu.setForeground(color.yellow)
  90.     gpu.set(center + 1, 1, "Владельцы /warp SKY")
  91.     gpu.setForeground(color.green)
  92.     gpu.set(center + unicode.len("Владельцы /warp SKY") + 1, 1, "]")
  93.     gpu.setForeground(color.green)
  94.     gpu.set(w / 5 - 2, h - 2, "По всем вопросам: /w nickname")
  95.  
  96.     local downloadFile = shell.execute("wget " .. url .. " " .. "/home/infoServer.json" .. " -fQ")
  97.     local response = readFile()
  98.  
  99.     if response then
  100.         local list = parseJson(response)["Playerlist"]
  101.         for i = 1, #owners do
  102.             drawOwners(owners[i], i, 2, color.red)
  103.             if list then
  104.                 for j = 1, #list do
  105.                     if owners[i] == list[j] then
  106.                         drawOwners(owners[i], i, 1, color.green)
  107.                     end
  108.                 end
  109.             end
  110.         end
  111.     end
  112.  
  113.     os.sleep(60)
  114. end
  115.  
  116.  
Add Comment
Please, Sign In to add comment