Advertisement
serafim7

монитор онлайна [OpenComputers]

Jul 17th, 2022 (edited)
1,461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.07 KB | None | 0 0
  1. --монитор онлайна by serafim    pastebin.com/ZQrMhRLW    update 25.06.22
  2. --https://i.imgur.com/FMWujYt.png  
  3.  
  4. local admins = {
  5.   {"Тех.Админ","SkyDrive_","0xFF0000","0xFFFFFF","0","false"},
  6.   {"Куратор","NpVpanthera","0xFF0000","0xFFFFFF","0","false"},
  7.   {"Гл.Модератор","Firemet","0x006DFF","0x33B6BF","0","false"},
  8.   {"Ст.Модератор","Strategy","0x006DFF","0x33B6BF","0","false"},
  9.   {"Модератор","Morisonsa","0xFF55FF","0xFF9200","0","false"},
  10.   {"Модератор","Elecpat","0xFF55FF","0xFF9200","0","false"},
  11.   {"Помощник","LeBron12","0x00FF00","0x00FF00","0","false"},
  12.   {"Помощник","sima21","0x00FF00","0x00FF00","0","false"},
  13.   {"Стажёр","HaKKO","0x66FF80","0x00FF00","0","false"}
  14. }
  15.  
  16. local com = require("component")
  17. local computer = require("computer")
  18. local unicode = require("unicode")
  19. local fs = require('filesystem')
  20. local event = require("event")
  21. local gpu = com.gpu
  22. local run = true
  23.  
  24. local w, h = 80, 25
  25. local w2 = w / 2
  26.  
  27. local function get_time()
  28.   local time_correction = 3
  29.   io.open('/tmp/clock.dt', 'w'):write(''):close()
  30.   return tonumber(string.sub(fs.lastModified('/tmp/clock.dt'), 1, -4)) + time_correction * 3600
  31. end
  32.  
  33. local function disp_time(t)
  34.   local days = (t / 86400)
  35.   local hrs = (t % 86400) / 3600
  36.   local mins = ((t % 86400) % 3600) / 60
  37.   local sec = (t % 3600) % 60
  38.   if days >= 1 then
  39.     return string.format("%d дн. %02d ч.   ",days,hrs)
  40.   elseif hrs >= 1 then
  41.     return string.format("%02d ч. %02d мин.   ",hrs,mins)
  42.   else
  43.     return string.format("%02d мин. %02d сек.   ",mins,sec)
  44.   end
  45. end
  46.  
  47. local function save()
  48.   local f = io.open("/home/tbl", "w")  
  49.   f:write("List = {")
  50.   for ind = 1,#admins do
  51.     local w = tonumber(admins[ind][5])
  52.     if ind == #admins then
  53.       f:write(w)
  54.     else
  55.       f:write(w..',')
  56.     end
  57.   end
  58.   f:write("}")
  59.   f:close()
  60. end
  61.  
  62. if not fs.exists("/home/tbl") then
  63.   save()
  64. end  
  65. dofile("/home/tbl")
  66. local t = {}
  67. local t = List
  68. local start_time = get_time()
  69. for ind = 1,#t do
  70.   if t[ind] == 0 then
  71.     admins[ind][5] = start_time
  72.   else
  73.     admins[ind][5] = t[ind]
  74.   end
  75. end
  76. for ind = 1,#admins do
  77.   computer.removeUser(admins[ind][2])
  78. end
  79. os.execute("cls")
  80. print("Коснитесь экрана")
  81. computer.addUser(({event.pull("touch")})[6])
  82. os.execute("cls")
  83. gpu.setResolution(w, h)
  84. gpu.setBackground(0x000000)
  85. gpu.setForeground(0x333333)
  86. for i = 1,w do
  87.   gpu.set(i,1,"=")
  88.   gpu.set(i,h,"=")
  89. end
  90. for i = 1,h do
  91.   gpu.set(1, i, "||")
  92.   gpu.set(w-1, i, "||")
  93. end
  94. gpu.setForeground(0x66FF00)
  95. gpu.set(w2 - unicode.len("[ OpenAdmins ]")/2,1,"[ OpenAdmins ]")
  96. gpu.set(w2 - unicode.len("Список администрации")/2,3,"Список администрации")
  97. local line = 10
  98. for ind = 1,#admins do
  99.   gpu.setForeground(0x2D2D2D)
  100.   gpu.set(10,line,"[")
  101.   gpu.set(11+unicode.len(admins[ind][1]),line,"]")
  102.   gpu.setForeground(tonumber(admins[ind][3]))
  103.   gpu.set(11,line,admins[ind][1])
  104.   gpu.setForeground(tonumber(admins[ind][4]))
  105.   gpu.set(30,line,admins[ind][2])
  106.   line = line + 1
  107. end
  108.  
  109. while run do
  110.   local current_time = get_time()
  111.   local line = 10
  112.   for ind = 1,#admins do
  113.     if computer.addUser(admins[ind][2]) then
  114.       computer.removeUser(admins[ind][2])
  115.       gpu.setForeground(0x00FF00)
  116.       gpu.set(47,line,"online ")
  117.       if admins[ind][6] == "false" then
  118.         admins[ind][5] = current_time
  119.         admins[ind][6] = "true"
  120.       end
  121.     else
  122.       gpu.setForeground(0x2D2D2D)
  123.       gpu.set(47,line,"offline")
  124.       if admins[ind][6] == "true" then
  125.         admins[ind][5] = current_time
  126.         admins[ind][6] = "false"
  127.       end
  128.     end
  129.     gpu.set(57,line,disp_time(current_time-admins[ind][5]))
  130.     line = line + 1
  131.   end
  132.   local e = ({event.pull(5,"key_down")})[4]
  133.   if e == 29 or e == 157 then -- Ctrl Выход
  134.     save()
  135.     gpu.setResolution(w,h)
  136.     gpu.setBackground(0x000000)
  137.     gpu.setForeground(0xFFFFFF)
  138.     os.execute("cls")
  139.     run = false
  140.     os.exit()
  141.   end
  142. end
  143.  
  144. if run then
  145.   computer.shutdown(false)
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement