View difference between Paste ID: Lh36kQPs and uzz9eDLM
SHOW: | | - or go back to the newest paste.
1-
--|============================|
1+
--|============================|
2-
--|         OpenAdmins.        |
2+
--|         OpenAdmins.        |
3-
--|       Автор: SkyDrive_     |
3+
--|       Автор: SkyDrive_     |
4-
--| Проект McSkill, cервер HTC |
4+
--| Проект McSkill, cервер HTC |
5-
--|         14.05.2017         |
5+
--|         14.05.2017         |
6-
--|        Version: 1.02       |
6+
--|        Version: 1.02       |
7-
--|============================|
7+
--|============================|
8-
local component = require("component")
8+
local component = require("component")
9-
local computer=require("computer")
9+
local computer=require("computer")
10-
local event = require("event")
10+
local event = require("event")
11-
local term = require("term")
11+
local term = require("term")
12-
local shell = require("shell")
12+
local shell = require("shell")
13-
local fs = require("filesystem")
13+
local fs = require("filesystem")
14-
local unicode=require("unicode")
14+
local unicode=require("unicode")
15-
local serial = require("serialization")
15+
local serial = require("serialization")
16-
if not fs.exists("/lib/sky.lua") then
16+
if not fs.exists("/lib/sky.lua") then
17-
  shell.execute("wget https://www.dropbox.com/s/dhgifu198hjyzoy/sky.lua?dl=1 /lib/sky.lua")
17+
  shell.execute("wget https://www.dropbox.com/s/dhgifu198hjyzoy/sky.lua?dl=1 /lib/sky.lua")
18
end
19-
local sky = require("sky")
19+
local sky = require("sky")
20-
local g = component.gpu
20+
local g = component.gpu
21-
event.shouldInterrupt = function () return false end
21+
event.shouldInterrupt = function () return false end
22-
--------------------Настройки--------------------
22+
--------------------Настройки--------------------
23-
local WIDTH, HEIGHT = 146, 42 --Разрешение моника 146/112 x 42
23+
local WIDTH, HEIGHT = 146, 42 --Разрешение моника 146/112 x 42
24-
local COLOR1 = 0x00ffff --Рамка
24+
local COLOR1 = 0x00ffff --Рамка
25-
local COLOR2 = 0x333333 --Цвет кнопок
25+
local COLOR2 = 0x333333 --Цвет кнопок
26-
local UPDATE = 300 --Апдейт отображения информации в сек.
26+
local UPDATE = 300 --Апдейт отображения информации в сек.
27-
local SCOREBOARDS = {"Admin", "TAdmin", "Global", "GD", "GM", "STMod", "Dev", "Builder", "Modn",
27+
local SCOREBOARDS = {"Admin", "TAdmin", "Global", "GD", "GM", "STMod", "Dev", "Builder", "Modn",
28-
"Helper2", "Helper1"} --Названия Скорбордов (Создать такие же на серве, либо поменять тут)
28+
"Helper2", "Helper1"} --Названия Скорбордов (Создать такие же на серве, либо поменять тут)
29-
local MOD_CHAT_COLOR = {"&8", "&8", "&8",  "&9", "&9", "&3", "&5", "&5", "&6", "&2", "&a"} --Изменение цвета ника в Мод.Чате
29+
local MOD_CHAT_COLOR = {"&8", "&8", "&8",  "&9", "&9", "&3", "&5", "&5", "&6", "&2", "&a"} --Изменение цвета ника в Мод.Чате
30-
-------------------------------------------------
30+
-------------------------------------------------
31-
if not (fs.exists(shell.getWorkingDirectory() .. "/AdminsBD.lua")) then
31+
if not (fs.exists(shell.getWorkingDirectory() .. "/AdminsBD.lua")) then
32-
  shell.execute("wget https://www.dropbox.com/s/ev2fuxc43m9v97o/AdminsBD.lua?dl=1")
32+
  shell.execute("wget https://www.dropbox.com/s/ev2fuxc43m9v97o/AdminsBD.lua?dl=1")
33
end
34-
34+
35-
local mid = WIDTH / 2
35+
local mid = WIDTH / 2
36-
local sel = nil
36+
local sel = nil
37-
local admins
37+
local admins
38-
local timer = 0
38+
local timer = 0
39-
local stat = {"&0[&4Админ&0] - &0", "&0[&4Тех.Админ&0] - &0", "&0[&4Глобал Мод&0] - &0", "&0[&9Дизайнер&0] - &3","&0[&9Гл.Модератор&0] - &3",
39+
local stat = {"&0[&4Админ&0] - &0", "&0[&4Тех.Админ&0] - &0", "&0[&4Глобал Мод&0] - &0", "&0[&9Дизайнер&0] - &3","&0[&9Гл.Модератор&0] - &3",
40-
"&0[&3Ст.Модератор&0] - &3", "&0[&5Разработчик&0] - &d", "&0[&5Строитель&0] - &d", "&0[&4Модератор&0] - &6","&0[&2Помощник&0] - &2", "&0[&aСтажёр&0] - &2"}
40+
"&0[&3Ст.Модератор&0] - &3", "&0[&5Разработчик&0] - &d", "&0[&5Строитель&0] - &d", "&0[&4Модератор&0] - &6","&0[&2Помощник&0] - &2", "&0[&aСтажёр&0] - &2"}
41-
41+
42-
file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "r")
42+
file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "r")
43-
local reads = file:read(9999999)
43+
local reads = file:read(9999999)
44-
if reads ~= nil then
44+
if reads ~= nil then
45-
  admins = serial.unserialize("{" .. reads .. "}")
45+
  admins = serial.unserialize("{" .. reads .. "}")
46-
else
46+
else
47-
  admins = {}
47+
  admins = {}
48
end
49-
file:close()
49+
file:close()
50-
50+
51-
g.setResolution(WIDTH, HEIGHT)
51+
g.setResolution(WIDTH, HEIGHT)
52-
sky.logo("OpenAdmins", COLOR1, COLOR2, WIDTH, HEIGHT)
52+
sky.logo("OpenAdmins", COLOR1, COLOR2, WIDTH, HEIGHT)
53-
53+
54-
function isOnline(nick)
54+
function isOnline(nick)
55-
result,reason=computer.addUser(nick)
55+
result,reason=computer.addUser(nick)
56-
computer.removeUser(nick)
56+
computer.removeUser(nick)
57-
if result==true then
57+
if result==true then
58-
 return "&aонлайн"
58+
 return "&aонлайн"
59-
else
59+
else
60-
 return "&4оффлайн"
60+
 return "&4оффлайн"
61
end
62
end
63-
63+
64-
function Save()
64+
function Save()
65-
  file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "w")
65+
  file = io.open(shell.getWorkingDirectory() .. "/AdminsBD.lua", "w")
66-
  local text = ""
66+
  local text = ""
67-
  for i = 1, #admins do
67+
  for i = 1, #admins do
68-
    text = text .. "{'"..admins[i][1].."','"..admins[i][2].."','"..admins[i][3].."'},\n"    
68+
    text = text .. "{'"..admins[i][1].."','"..admins[i][2].."','"..admins[i][3].."'},\n"    
69-
  end
69+
  end
70-
  file:write(text)
70+
  file:write(text)
71-
  file:close()
71+
  file:close()
72
end
73-
73+
74-
function Seen(nick)
74+
function Seen(nick)
75-
  local  status=isOnline(nick)
75+
  local  status=isOnline(nick)
76-
  return status, 0, 0, 0, 0, 0
76+
  return status, 0, 0, 0, 0, 0
77
end
78-
78+
79-
function Update()
79+
function Update()
80-
  for i = 1, #admins do
80+
  for i = 1, #admins do
81-
    g.set(mid-45,i+13,"                                     ")
81+
    g.set(mid-45,i+13,"                                     ")
82-
    sky.text(mid-45, i+13, admins[i][1] .. admins[i][2])
82+
    sky.text(mid-45, i+13, admins[i][1] .. admins[i][2])
83-
    sky.text(mid-8, i+13, admins[i][3] .. "  ")
83+
    sky.text(mid-8, i+13, admins[i][3] .. "  ")
84-
    
84+
    
85-
    sky.text(mid+4, i+13, "&6" .. sky.playtime(admins[i][2]) .. "    ")
85+
    sky.text(mid+4, i+13, "&6" .. sky.playtime(admins[i][2]) .. "    ")
86-
    
86+
    
87-
    local status, year, month, day, hour, minute = Seen(admins[i][2]) 
87+
    local status, year, month, day, hour, minute = Seen(admins[i][2]) 
88-
    g.set(mid+20,i+13,"                       ")
88+
    g.set(mid+20,i+13,"                       ")
89-
    if status == "&4error" then
89+
    if status == "&4error" then
90-
      sky.text(mid+20,i+13, status)
90+
      sky.text(mid+20,i+13, status)
91-
    elseif year ~= 0 then
91+
    elseif year ~= 0 then
92-
      sky.text(mid+20,i+13, status)
92+
      sky.text(mid+20,i+13, status)
93-
    elseif month ~= 0 then
93+
    elseif month ~= 0 then
94-
      sky.text(mid+20,i+13, status)
94+
      sky.text(mid+20,i+13, status)
95-
    elseif day ~= 0 then
95+
    elseif day ~= 0 then
96-
      sky.text(mid+20,i+13, status)
96+
      sky.text(mid+20,i+13, status)
97-
    else
97+
    else
98-
      sky.text(mid+20,i+13, status)
98+
      sky.text(mid+20,i+13, status)
99-
    end
99+
    end
100-
  end
100+
  end
101
end
102-
102+
103-
function Sort()
103+
function Sort()
104-
  local buffer = {}
104+
  local buffer = {}
105-
  for i = 1, #stat do
105+
  for i = 1, #stat do
106-
    for j = 1, #admins do
106+
    for j = 1, #admins do
107-
      if stat[i] == admins[j][1] then
107+
      if stat[i] == admins[j][1] then
108-
        table.insert(buffer, admins[j])
108+
        table.insert(buffer, admins[j])
109-
      end
109+
      end
110-
    end
110+
    end
111-
  end
111+
  end
112-
  admins = buffer
112+
  admins = buffer
113
end
114-
114+
115-
function Sel()
115+
function Sel()
116-
  for i = 1, #admins do
116+
  for i = 1, #admins do
117-
    sky.text(mid-51,i+13, "   ")
117+
    sky.text(mid-51,i+13, "   ")
118-
    sky.text(mid+45,i+13, "   ")
118+
    sky.text(mid+45,i+13, "   ")
119-
    if sel~= nil then
119+
    if sel~= nil then
120-
      if sel == admins[i][2] then
120+
      if sel == admins[i][2] then
121-
        sky.text(mid-51,i+13, "&b>>>")
121+
        sky.text(mid-51,i+13, "&b>>>")
122-
        sky.text(mid+45,i+13, "&b<<<")
122+
        sky.text(mid+45,i+13, "&b<<<")
123-
      end
123+
      end
124-
    end
124+
    end
125-
  end
125+
  end
126
end
127-
127+
128-
function Draw()
128+
function Draw()
129-
  if sel ~= nil then
129+
  if sel ~= nil then
130-
    sky.button(mid-44,HEIGHT-4,20,3,COLOR1,COLOR2,"Повысить")
130+
    sky.button(mid-44,HEIGHT-4,20,3,COLOR1,COLOR2,"Повысить")
131-
    sky.button(mid-22,HEIGHT-4,20,3,COLOR1,COLOR2,"Понизить")
131+
    sky.button(mid-22,HEIGHT-4,20,3,COLOR1,COLOR2,"Понизить")
132-
    sky.button(mid+6,HEIGHT-4,20,3,COLOR1,COLOR2,"Male/Female")
132+
    sky.button(mid+6,HEIGHT-4,20,3,COLOR1,COLOR2,"Male/Female")
133-
    sky.button(mid+28,HEIGHT-4,20,3,COLOR1,COLOR2,"Удалить")
133+
    sky.button(mid+28,HEIGHT-4,20,3,COLOR1,COLOR2,"Удалить")
134-
  else
134+
  else
135-
    g.fill(3,HEIGHT-6, WIDTH-11, 5, " ")
135+
    g.fill(3,HEIGHT-6, WIDTH-11, 5, " ")
136-
  end
136+
  end
137
end
138-
138+
139-
function Index(array, value)
139+
function Index(array, value)
140-
  for i = 1, #array do
140+
  for i = 1, #array do
141-
    if value == array[i] then
141+
    if value == array[i] then
142-
      return i
142+
      return i
143-
    end
143+
    end
144-
  end
144+
  end
145
end
146-
146+
147-
function Click(w,h)
147+
function Click(w,h)
148-
  if sel~= nil then
148+
  if sel~= nil then
149-
    local sel_id
149+
    local sel_id
150-
    for i = 1, #admins do
150+
    for i = 1, #admins do
151-
      if sel == admins[i][2] then
151+
      if sel == admins[i][2] then
152-
        sel_id = i
152+
        sel_id = i
153-
        break
153+
        break
154-
      end
154+
      end
155-
    end
155+
    end
156-
    if w>=mid-44 and w<=mid-25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
156+
    if w>=mid-44 and w<=mid-25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
157-
      index = Index(stat,admins[sel_id][1]) - 1
157+
      index = Index(stat,admins[sel_id][1]) - 1
158-
      if index == 0 then index = 1 end
158+
      if index == 0 then index = 1 end
159-
      admins[sel_id][1] = stat[index]   
159+
      admins[sel_id][1] = stat[index]   
160-
      Sort()
160+
      Sort()
161-
    elseif w>=mid-22 and w<=mid-3 and h>=HEIGHT-4 and h<=HEIGHT-2 then
161+
    elseif w>=mid-22 and w<=mid-3 and h>=HEIGHT-4 and h<=HEIGHT-2 then
162-
      index = Index(stat,admins[sel_id][1]) + 1
162+
      index = Index(stat,admins[sel_id][1]) + 1
163-
      if index == #stat + 1 then index = #stat end
163+
      if index == #stat + 1 then index = #stat end
164-
      admins[sel_id][1] = stat[index] 
164+
      admins[sel_id][1] = stat[index] 
165-
      Sort()
165+
      Sort()
166-
    elseif w>=mid+6 and w<=mid+25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
166+
    elseif w>=mid+6 and w<=mid+25 and h>=HEIGHT-4 and h<=HEIGHT-2 then
167-
      if admins[sel_id][3] == "&bMale" then
167+
      if admins[sel_id][3] == "&bMale" then
168-
        admins[sel_id][3] = "&dFemale"
168+
        admins[sel_id][3] = "&dFemale"
169-
      else
169+
      else
170-
        admins[sel_id][3] = "&bMale"
170+
        admins[sel_id][3] = "&bMale"
171-
      end
171+
      end
172-
    elseif w>=mid+28 and w<=mid+47 and h>=HEIGHT-4 and h<=HEIGHT-2 then
172+
    elseif w>=mid+28 and w<=mid+47 and h>=HEIGHT-4 and h<=HEIGHT-2 then
173-
      table.remove(admins, sel_id)
173+
      table.remove(admins, sel_id)
174-
      g.fill(3,13,WIDTH-4,25, " ")
174+
      g.fill(3,13,WIDTH-4,25, " ")
175-
    end
175+
    end
176-
    Update()
176+
    Update()
177-
    Save()
177+
    Save()
178-
  end
178+
  end
179-
  
179+
  
180-
  if w>=WIDTH-8 and w<=WIDTH-4 and h>=HEIGHT-4 and h<=HEIGHT-2 then
180+
  if w>=WIDTH-8 and w<=WIDTH-4 and h>=HEIGHT-4 and h<=HEIGHT-2 then
181-
    sky.text(mid-44, HEIGHT-6,"&bВведите ник:")
181+
    sky.text(mid-44, HEIGHT-6,"&bВведите ник:")
182-
    term.setCursor(mid-30, HEIGHT-6)
182+
    term.setCursor(mid-30, HEIGHT-6)
183-
    local n = io.read()
183+
    local n = io.read()
184-
    table.insert(admins, {stat[#stat], n, "&bMale"})
184+
    table.insert(admins, {stat[#stat], n, "&bMale"})
185-
    g.set(mid-44, HEIGHT-6,"                                                                                        ")
185+
    g.set(mid-44, HEIGHT-6,"                                                                                        ")
186-
    Update()
186+
    Update()
187-
    Save()
187+
    Save()
188-
  end
188+
  end
189-
  
189+
  
190-
  if h-13 >= 1 and h-13 <= #admins then
190+
  if h-13 >= 1 and h-13 <= #admins then
191-
    sel = admins[h-13][2]
191+
    sel = admins[h-13][2]
192-
    Sel()
192+
    Sel()
193-
  else
193+
  else
194-
    sel = nil
194+
    sel = nil
195-
    Sel()
195+
    Sel()
196-
  end
196+
  end
197-
  
197+
  
198-
  Draw()
198+
  Draw()
199
end
200-
200+
201-
sky.button(WIDTH - 8,HEIGHT-4,5,3,COLOR1,COLOR2,"+")
201+
sky.button(WIDTH - 8,HEIGHT-4,5,3,COLOR1,COLOR2,"+")
202-
Update()
202+
Update()
203-
203+
204-
while true do
204+
while true do
205-
  local e,_,w,h,_,nick = event.pull(UPDATE, "touch")
205+
  local e,_,w,h,_,nick = event.pull(UPDATE, "touch")
206-
  if e == "touch" then
206+
  if e == "touch" then
207-
    Click(w,h)
207+
    Click(w,h)
208-
  end
208+
  end
209-
  if sel == nil then
209+
  if sel == nil then
210-
    Update()
210+
    Update()
211-
  end
211+
  end
212
end