Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --============================
- -- OpenRep.
- -- Автор SkyDrive_
- -- Идея Astro
- -- Проект McSkill, cервер ТМ
- -- 09.07.2017
- -- Version 1.01
- --============================
- local component = require(component)
- local term = require(term)
- local event = require(event)
- local unicode=require(unicode)
- local computer = require(computer)
- local fs = require(filesystem)
- local shell = require(shell)
- local serial = require(serialization)
- if not fs.exists(lib/sky.lua) then
- shell.execute(wget httpswww.dropbox.comsct5zsbm81zir7w2Sky%28lib%29.luadl=1 libSky.lua)
- end
- local Sky = require(lib/sky)
- local g = component.gpu
- local c = component.chat_box
- local u = computer.addUser
- local tab
- event.shouldInterrupt = function () return false end
- --------------------Настройки--------------------
- local WIGHT, HEIGHT = 80, 25 --Разрешение моника 146112 x 42
- local COLOR1 = 0x00ffff --Рамка
- local COLOR2 = 0x0000ff --Цвет кнопок
- local COLOR_W1 = §a --Лс текст
- local COLOR_W2 = §b --Лс выделение
- local LINES = 1 --Длина таблицы, которая отображает рейтинг топ игроков. Меняется, в зависимости от разрешения
- local HISTORY = 1 --Кол-во строк в истории
- -------------------------------------------------
- local mid = WIGHT 2 --
- print(nИнициализация...)
- os.sleep(2)
- print(Запуск программы...)
- os.sleep(2)
- file = io.open(shell.getWorkingDirectory() .. RepBD.lua, r)
- local reads = fileread(9999999)
- if reads ~= nil then
- tab = serial.unserialize({ .. reads .. })
- else
- tab = {}
- end
- fileclose()
- users={computer.users()}
- for i=1, #users do
- computer.removeUser(users[i])
- end
- if not (fs.isDirectory(shell.getWorkingDirectory() .. Rep)) then
- fs.makeDirectory(shell.getWorkingDirectory() .. Rep)
- end
- function RepCheck(name)
- file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
- local reads = fileread(9999999)
- local mass = serial.unserialize({ .. reads .. })
- local plus, minus = 0, 0
- for i = 1, #mass do
- if mass[i][2] == + then
- plus = plus + 1
- else
- minus = minus + 1
- end
- end
- fileclose()
- return plus, minus
- end
- function RepChange(nick, name, value)
- file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
- local reads = fileread(9999999)
- if reads ~= nil then
- local mass = serial.unserialize({ .. reads .. })
- for i = 1, #mass do
- if mass[i][1] == nick then
- return(Вы уже оценили этого игрока)
- end
- end
- end
- fileclose()
- file = io.open(shell.getWorkingDirectory() .. Rep .. name, a)
- filewrite({' .. nick .. ', ' .. value .. '},n)
- fileclose()
- return(Ваш голос учтён)
- end
- function TabSave()
- file = io.open(shell.getWorkingDirectory() .. RepBD.lua, w)
- local text =
- for i = 1, #tab do
- text = text .. {' .. tab[i][1] .. ', .. tab[i][2] .. , .. tab[i][3] .. , .. tab[i][4] .. },n
- end
- filewrite(text)
- fileclose()
- end
- function history(name)
- file = io.open(shell.getWorkingDirectory() .. Rep .. name, r)
- local reads = fileread(9999999)
- local mass = serial.unserialize({ .. reads .. })
- local hist
- if #mass HISTORY then
- hist = #mass - HISTORY + 1
- else
- hist = 1
- end
- local text =
- for i = hist, #mass do
- if mass[i][2] == + then
- COLOR_W3 = §2
- else
- COLOR_W3 = §4
- end
- text = text .. COLOR_W2 .. mass[i][1] .. COLOR_W1 .. поставил .. COLOR_W3 .. mass[i][2] .. string.char(10)
- end
- fileclose()
- return text
- end
- function tableCheck(name)
- for i = 1, #tab do
- if tab[i][1] == name then
- table.remove(tab, i)
- return
- end
- end
- end
- function tableAdd(name, reputation, plus, minus)
- for i = 1, #tab do
- if tab[i][2] = reputation then
- table.insert(tab, i, {name, reputation, plus, minus})
- if #tab LINES then
- table.remove(tab, #tab)
- end
- return
- end
- end
- table.insert(tab, {name, reputation, plus, minus})
- if #tab LINES then
- table.remove(tab, #tab)
- end
- end
- function Message(msg, nick)
- if msg == -rep then
- Sky.Com(w .. nick .. .. string.char(10) ..
- §8------------------------------------------------ .. string.char(10) ..
- COLOR_W2 .. -rep nick §8➢ .. COLOR_W1 .. Узнать репутацию игрока. .. string.char(10) ..
- COLOR_W2 .. -rep nick + §8➢ .. COLOR_W1 .. Повысить репутацию игрока. .. string.char(10) ..
- COLOR_W2 .. -rep nick - §8➢ .. COLOR_W1 .. Понизить репутацию игрока. .. string.char(10) ..
- COLOR_W2 .. -history nick §8➢ .. COLOR_W1 .. Показать последние изменения .. string.char(10) ..
- §8------------------------------------------------)
- elseif string.find(msg, -rep) ~= nil then
- if string.sub(msg, unicode.len(msg), unicode.len(msg)) ~= + and string.sub(msg, unicode.len(msg), unicode.len(msg)) ~= - then
- local name = string.sub(msg, 6, unicode.len(msg))
- if (fs.exists(shell.getWorkingDirectory() .. Rep .. name)) then
- local plus, minus = RepCheck(name)
- local reputation = plus - minus
- local COLOR_W3
- if reputation = 0 then
- COLOR_W3 = §2
- else
- COLOR_W3 = §4
- end
- Sky.Com(w .. nick .. .. string.char(10) ..
- §8------------------------------------------------ .. string.char(10) ..
- COLOR_W1 .. Репутация игрока .. COLOR_W2 .. name .. .. string.char(10) ..
- COLOR_W1 .. Рейтинг = .. COLOR_W3 .. reputation .. ❤ .. string.char(10) ..
- COLOR_W1 .. Положительных (+) = §2 .. plus .. string.char(10) ..
- COLOR_W1 .. Отрицательных (-) = §4 .. minus .. string.char(10) ..
- §8------------------------------------------------)
- else
- Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не имеет репутации)
- end
- else
- local name = string.sub(msg, 6, unicode.len(msg)-2)
- local value
- if string.sub(msg, unicode.len(msg), unicode.len(msg)) == + then
- value = +
- else
- value = -
- end
- if u(name) ~= nil then
- computer.removeUser(name)
- local text = RepChange(nick, name, value)
- local plus, minus = RepCheck(name)
- local reputation = plus - minus
- if #tab ~= 0 then
- tableCheck(name)
- tableAdd(name, reputation, plus, minus)
- else
- table.insert(tab, {name, reputation, plus, minus})
- end
- draw()
- TabSave()
- Sky.Com(w .. nick .. .. COLOR_W1 .. text)
- else
- Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не найден, либо оффлайн)
- end
- end
- elseif string.find(msg, -history) ~= nil then
- if msg == -history then
- Sky.Com(w .. nick .. .. COLOR_W1 .. Введите ник (-history nick))
- else
- local name = string.sub(msg, 10, unicode.len(msg))
- if (fs.exists(shell.getWorkingDirectory() .. Rep .. name)) then
- local hist = history(name)
- Sky.Com(w .. nick .. .. string.char(10) ..
- §8------------------------------------------------ .. string.char(10) ..
- COLOR_W1 .. История .. COLOR_W2 .. name .. COLOR_W1 .. .. string.char(10)
- .. hist ..
- §8------------------------------------------------)
- else
- Sky.Com(w .. nick .. .. COLOR_W1 .. Игрок не имеет репутации)
- end
- end
- end
- end
- function draw()
- WIGHT, HEIGHT = Sky.Resolution(WIGHT,HEIGHT)
- Sky.Ram(OpenRep, COLOR1,COLOR2,WIGHT, HEIGHT, false)
- g.setForeground(COLOR1)
- Sky.Mid(WIGHT, 3, Лучшие игроки сервера)
- Sky.Mid(WIGHT, HEIGHT-2, Чтобы пользоваться сис-мой рейтинга пропишите -rep)
- for i = 1, #tab do
- Sky.Mid(WIGHT, i+4, &b .. tab[i][1] .. - &2Рейтинг .. tab[i][2] .. &b - (&2+ .. tab[i][3] .. &b&4- .. tab[i][4] .. &b))
- end
- end
- draw()
- while true do
- local _, _, nick, msg = event.pull(chat_message)
- if msg ~= nil and nick ~= nil then
- Message(msg, nick)
- end
- end
Add Comment
Please, Sign In to add comment