Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------
- -- Программа --
- -- для управления вратами из мода SG --
- -- в игре Minecraft с модом OpenComputers --
- -- проект http://computercraft.ru --
- -- 2017, © Asior --
- ----------------------------------------------------
- -- Version 0.01
- local com = require("computer")
- local gpu = require("component").gpu
- local event = require("event")
- local term = require("term")
- local unicode = require("unicode")
- local stargate = require("component").stargate
- local serialization = require("serialization")
- local fl = require("filesystem")
- local function PrintLine(x1, y1, x2, y2, sms, vertical, colorBr, colorLet) -- быстрая отрисовка рамок
- local vr = ''
- if not vertical then vertical = false end
- if not x2 then x2 = x1 end
- if not y2 then y2 = y1 end
- if not colorBr then gpu.setBackground(0x000000) else gpu.setBackground(colorBr) end
- if not colorLet then gpu.setForeground(0xffffff) else gpu.setForeground(colorLet) end
- if not vertical then -- если нарисовать горизонтальную строку
- vr = (sms):rep(x2 - x1 + 1)
- else -- если нарисовать вертикальную строку
- vr = (sms):rep(y2 - y1 + 1)
- end
- gpu.set(x1, y1, vr, vertical)
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- end
- local function frame() -- рамка, а что ж еще
- local h, w = 19, 54
- PrintLine(1, 1, nil, nil, '╔')
- PrintLine(w, 1, nil, nil, '╗')
- PrintLine(1, 19, nil, nil, '╚')
- PrintLine(w, 19, nil, nil, '╝')
- PrintLine(2, 1, w - 1, nil, '═')
- PrintLine(1, 2, nil, 18, '║', true)
- PrintLine(w, 2, nil, 18, '║', true)
- PrintLine(2, 19, w - 1, nil, '═')
- PrintLine(30, 4, nil, 18, '║', true)
- PrintLine(30, 19, nil, nil, '╩', false)
- PrintLine(1, 3, nil, nil, '╠')
- PrintLine(2, 3, w - 1, nil, '═')
- PrintLine(30, 3, nil, nil, '╦', false)
- PrintLine(w, 3, nil, nil, '╣')
- end
- local function ScreenBuffer(x1, y1, x2, y2, save) -- Буфер экрана. Вырезает кусок экрана, потом возвращает
- if save then
- Buffer = {}
- for i = y1, y2 do
- for i1 = x1, x2 do
- local s, b, f = gpu.get(i1, i)
- Buffer[i..i1] = {['s'] = s, ['b'] = b, ['f'] = f}
- end
- end
- else
- for i = y1, y2 do
- for i1 = x1, x2 do
- gpu.setBackground(Buffer[i..i1].f)
- gpu.setForeground(Buffer[i..i1].b)
- gpu.set(i1, i, Buffer[i..i1].s)
- end
- end
- Buffer = {}
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- end
- end
- local function errors(x, y, sms, color, time, scr, name) -- окно ошибок -- координаты по х, у;сообщение;цвет;время показа; не запоминать?
- local h, w = #sms + 3, 32
- if not scr then ScreenBuffer(x, y, x + w, y + h, true) end
- PrintLine(x, y, nil, nil, '╔')
- PrintLine(x + w, y, nil, nil, '╗')
- PrintLine(x, y + h, nil, nil, '╚')
- PrintLine(x + w, y + h, nil, nil, '╝')
- PrintLine(x + 1, y, x + w - 1, nil, '═')
- PrintLine(x, y + 1, nil, y + h - 1, '║', true)
- PrintLine(x + w, y + 1, nil, y + h - 1, '║', true)
- PrintLine(x + 1, y + h, x + w - 1, nil, '═')
- gpu.setBackground(color)
- gpu.fill(x + 1, y + 1, w - 1, h - 1, ' ')
- gpu.set(math.floor(x + w/2 - unicode.len(sms[1])/2), y + 1, sms[1])
- for i = 2, #sms do
- gpu.set(x + 2, y + i + 1, sms[i])
- end
- gpu.setBackground(0x000000)
- os.sleep(0.5)
- local t, _, _, _, k = event.pull(time)
- if t == 'touch' and k == 1 and name == Temp[2].name1 then
- t = true
- else
- t = false
- end
- if not scr then ScreenBuffer(x, y, x + w, y + h, false) end
- return t
- end
- local function bazaAdress(repetition, append, score, random) -- случайная база данных (рандом)
- -- удаление; дозапись; подсчет базы адресов; случайный адрес
- local files = "../Stargate/System/Baza_Adress.csv"
- if repetition then
- fl.remove(files)
- end
- file = io.open(files, 'r')
- if file ~= nil then
- if append then
- file:close()
- file = io.open(files, 'a')
- if #AllBaza>0 then
- for i = 1, #AllBaza do
- file:write(tostring(AllBaza[i])..';\n')
- end
- else
- errors(13, 7, {'Нечем заполнять'}, 0x00aa00, 1, false)
- end
- file:close()
- elseif score then
- local i, a = 0, ''
- repeat
- i = i + 1
- a = file:read()
- -- print(i..'|'..tostring(a))
- until a == nil
- file:close()
- AllBaza.num = i - 1
- return
- elseif random then
- local a = math.random(AllBaza.num) + 1
- local i, vr = 0, ''
- repeat
- i = i + 1
- vr = file:read()
- until i == a
- file:close()
- return vr
- end
- else
- file = io.open(files, 'w')
- if #AllBaza>0 then
- for i = 1, #AllBaza do
- file:write(tostring(AllBaza[i])..';\n')
- end
- else
- errors(13, 7, {'Нечем заполнять'}, 0x00aa00, 1, false)
- end
- file:close()
- end
- end
- local function usersQuantity(save) -- статистика пользователей (костыль, хз как считать кол - во файлов)
- if save then
- file = io.open("../Stargate/Users/Stat.csv", 'w')
- file:write(usersNum + 1)
- else
- file = io.open("../Stargate/Users/Stat.csv", 'r')
- if file == nil then
- usersNum = 0
- usersQuantity(true)
- return
- else
- usersNum = tonumber(file:read())
- end
- end
- file:close()
- end
- local function appendFile(files) -- перезапись файла пользователя
- local vr, a = {}, nil
- file = io.open(files, 'w')
- for i = 1, #UserBaza do
- file:write(tostring(UserBaza[i].name)..';'..tostring(UserBaza[i].adress)..';\n')
- end
- file:write(tostring(UserBaza[1].ends)..';Последний;\n')
- file:close()
- end
- local function toboolean(string) -- конвертор из строки в булевый
- return string == "true"
- end
- local function openFile(files, numBaza, repetition, append) -- имя файла(ник); номер базы (1 - 3); удаление; дозапись; подсчет базы адресов; случайный адрес -- загрузка или перезапись настроек в файл
- local file = nil
- -- задаем адрес файла
- if numBaza == 2 then -- имя;адрес;
- files = "../Stargate/Users/"..files.."__Baza.csv"
- elseif numBaza == 3 then -- имя;адрес;доступ;
- files = "../Stargate/System/Baza.csv"
- end
- -- проверка на удаление
- if repetition then
- fl.remove(files)
- end
- if append then
- appendFile(files)
- return
- end
- file = io.open(files, "r")
- if file == nil then -- если новый пользователь
- file = io.open(files, "w")
- if numBaza == 2 then
- errors(13, 7, {'Привет новичкам!', "Пожалуйста, подождите, идет", "создание вашего идентификатора"}, 0x00aa00, 4)
- usersQuantity(true)
- UserBaza, list = {}, {}
- for i = 1, 4 do -- порядок адресов стандартных спавн, ад, край, мир - шахта
- file:write(Baza[i].name..';'..Baza[i].adress..';\n')
- UserBaza[#UserBaza + 1] = {['name'] = Baza[i].name, ['adress'] = Baza[i].adress}
- list[#list + 1] = Baza[i].name
- end
- UserBaza[#UserBaza + 1] = {['name'] = Baza[1].adress, ['adress'] = 'Последняя'}
- list[#list + 1] = Baza[1].name
- file:write(UserBaza[#UserBaza].name..';'..UserBaza[#UserBaza].adress..';\n')
- elseif numBaza == 3 then
- if #Baza>0 then
- for i = 1, #Baza do
- file:write(tostring(Baza[i].name)..';'..tostring(Baza[i].adress)..';'..tostring(Baza[i].access)..';\n')
- end
- else
- errors(13, 7, {'Нет файла', string.sub(files, 1, 30)}, 0x00aa00, 1, false)
- file:write('')
- end
- end
- else -- если файл найден
- local line = file:read()
- -- print('читаю файл')
- while line do
- local arg = {}
- -- print(arg)os.sleep(0.3)
- for i = 1, numBaza do
- arg[i] = string.sub(line, 1, string.find(line, ';') - 1)
- line = string.sub(line, string.find(line, ';') + 1)
- end
- if numBaza == 2 then
- UserBaza[#UserBaza + 1] = {['name'] = arg[1], ['adress'] = arg[2]}
- list[#list + 1] = arg[1]
- elseif numBaza == 3 then
- Baza[#Baza + 1] = {['name'] = arg[1], ['adress'] = arg[2], ['access'] = toboolean(arg[3])}
- end
- line = file:read()
- end
- end
- if numBaza == 2 then
- UserBaza[1].ends = UserBaza[#UserBaza].name
- UserBaza[#UserBaza] = nil
- list[#list] = nil
- end
- file:close()
- end
- local function bottom(x, y, text, color) -- большие кнопки
- r = unicode.len(text) + 2
- if color == 0 then color = 0x00ff00 -- зеленый
- elseif color == 1 then color = 0x8b0000 -- красный
- elseif color == 2 then color = 0xBDB76B -- белый?
- elseif color == 3 then color = 0x191970
- elseif color == 4 then color = 0x006400 -- темно - зеленый
- elseif color > 10 then color = color
- else color = 0x008080 -- синеватый
- end
- gpu.setBackground(color)
- gpu.set(x, y, '┏'..("┉"):rep(r)..'┓')
- gpu.set(x, y + 1, '┋ '..text..' ┋')
- gpu.set(x, y + 2, '┗'..("┉"):rep(r)..'┛')
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- return y, y + 2, x, x + unicode.len(text) + 3
- end
- local function bottom2(y, text, press) -- маленькие кнопки
- if press then
- F = 0x00ff00
- else
- F = 0x808080
- end
- x = math.floor(22/2 - unicode.len(text)/2) + 30
- gpu.setForeground(F)
- gpu.set(x, y, '◀')
- gpu.set(x + unicode.len(text) + 3, y, '▶')
- gpu.setBackground(F)
- gpu.setForeground(0xffffff)
- gpu.set(x + 1, y, ' '..text..' ')
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- return y, y, x, x + unicode.len(text) + 3
- end
- local function bottom3(x, y, text, color) -- вертикальные кнопки
- r = unicode.len(text)
- if color == 0 then color = 0x00ff00 -- зеленый
- elseif color == 1 then color = 0x006400 -- темно - зеленый
- elseif color > 5 then color = color
- else color = 0x008080 -- синеватый
- end
- gpu.setBackground(color)
- gpu.set(x, y, '┏┉┉┉┓')
- for i = 1, r do
- gpu.set(x, y + i, '┋ '..unicode.sub(text, i, i)..' ┋')
- end
- gpu.set(x, y + r + 1, '┗┉┉┉┛')
- gpu.setBackground(0x000000)
- gpu.setForeground(0xffffff)
- return y, y + r + 1, x, x + 4
- end
- local function bottomPress(y, y1, x, x1) -- нажатие на кнопку
- text = ''
- _, _, c = gpu.get(x, y)
- if y1 - y>3 then
- for i = y + 1, y1 - 1 do
- text = text..gpu.get(x + 2, i)
- end
- bottom3(x, y, text, 0)
- os.sleep(0.5)
- bottom3(x, y, text, c)
- -- print(text)
- return
- end
- if y ~= y1 then
- for i = x + 2, x1 - 2 do
- text = text..gpu.get(i, y + 1)
- end
- bottom(x, y, text, 0)
- os.sleep(0.5)
- bottom(x, y, text, c)
- else
- for i = x + 2, x1 - 2 do
- text = text..gpu.get(i, y)
- end
- bottom2(y, text, true)
- os.sleep(0.5)
- bottom2(y, text)
- end
- end
- local function onOff(tr) -- преобразование true - >вкл false = >выкл
- if tr then
- tr = 'вкл '
- else
- tr = 'выкл'
- end
- return tr
- end
- local function oval(display) -- заставка врат
- if display then
- gpu.set(9, 2, 'Звездные врата')
- local items = {"Сон через ", " Статистика:", "Ад:", "Край:", "Мир - шахта: ", "Доступно: ", "Игроков: ", "Последним был:", " - "}
- for i = 1, 9 do
- gpu.set(9, i + 6, items[i])
- end
- else
- local items = {
- tostring(Temp[2].time)..' ',
- '',
- onOff(Baza[2].access),
- onOff(Baza[3].access),
- onOff(Baza[4].access),
- AllBaza.num,
- usersNum,
- '', Temp[2].name}
- for i = 1, 8 do
- gpu.set(20, i + 6, tostring(items[i]))
- end
- gpu.set(11, 15, tostring(items[9]))
- end
- end
- local function advertising(num, ls) -- Телепорты(и реклама)
- bottomMass2 = {}
- local qua = 0
- gpu.fill(31, 4, 22, 15, ' ')
- gpu.set(30, 2, (" "):rep(23))
- if not ls then
- qua = 7
- gpu.set(33, 2, 'Точки телепортов')
- else
- qua = 6
- gpu.set(32, 2, 'Ваши точки врат')
- local y0, y1, x0, x1 = bottom2(18, 'Назад')
- bottomMass2[3] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- end
- i1 = 0
- num = num - 1
- PrintLine(31, 18, 31, 18, '<=')
- bottomMass2[1] = {['y0'] = 18, ['y1'] = 18, ['x0'] = 31, ['x1'] = 32}
- PrintLine(52, 18, 52, 18, '=>')
- bottomMass2[2] = {['y0'] = 18, ['y1'] = 18, ['x0'] = 52, ['x1'] = 53}
- for i = qua*num + 1, qua*num + qua do
- i1 = i1 + 2
- if list[i] ~= nil then
- local y0, y1, x0, x1 = bottom2(i1 + 3, list[i])
- bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- end
- end
- end
- local function bottomSave() -- прорисовка кнопок и запоминания их функционала
- local y0, y0, x0, x1 = 0, 0, 0, 0
- y0, y1, x0, x1 = bottom(4, 4, 'ВХОД', 3) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom3(3, 7, ' СПАВН ', 1) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(7, 16, 'В АД', 1) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(17, 16, 'В КРАЙ', 3) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(14, 4, 'Мир - шахта', 3) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom3(24, 7, 'RANDOM ', 2) bottomMass[#bottomMass + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- end
- local function bottomMenu(name) -- прорисовка кнопок и запоминания их функционала
- local y0, y0, x0, x1 = 0, 0, 0, 0
- gpu.set(30, 2, (" "):rep(22))
- gpu.set(32, 2, name..', hi')
- gpu.fill(31, 4, 23, 15, ' ')
- y0, y1, x0, x1 = bottom(32, 4, 'В последнюю точку', 1) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(32, 8, 'Сохраненные точки', 6) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(35, 12, 'Новая точка', 6) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(38, 16, 'Выход', 1) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- end
- local function bottomMenuNew() -- прорисовка кнопок и запоминания их функционала
- local y0, y0, x0, x1 = 0, 0, 0, 0
- gpu.set(30, 2, (" "):rep(22))
- gpu.set(33, 2, 'Новая точка врат')
- gpu.fill(31, 4, 23, 15, ' ')
- gpu.set(32, 4, "Имя точки 15 символов")
- gpu.set(32, 6, "_______________")
- bottomMass2[#bottomMass2 + 1] = {['y0'] = 6, ['y1'] = 6, ['x0'] = 32, ['x1'] = 32 + 15}
- gpu.set(32, 8, "Адрес врат")
- gpu.set(32, 10, "_______________")
- bottomMass2[#bottomMass2 + 1] = {['y0'] = 10, ['y1'] = 10, ['x0'] = 32, ['x1'] = 32 + 15}
- y0, y1, x0, x1 = bottom(36, 12, 'Сохранить', 6) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- y0, y1, x0, x1 = bottom(38, 16, 'Назад', 1) bottomMass2[#bottomMass2 + 1] = {['y0'] = y0, ['y1'] = y1, ['x0'] = x0, ['x1'] = x1}
- end
- local function stargateStart() -- проверка на айрис
- stargate.sendMessage('PING')
- status = true
- local _, _, sms = event.pull(5, 'sgMessageReceived')
- if sms == "PONG" then
- stargate.sendMessage('STATUS')
- _, _, sms = event.pull(5, 'sgMessageReceived')
- end
- if sms == 'Offline' or sms == 'Open' then
- sms = 'Айрис открыт'
- elseif sms == nil then
- status = nil
- sms = 'Нет ответа'
- else
- sms = 'ТРЕВОГА! АЙРИС ЗАКРЫТ!'
- status = false
- end
- return sms, status
- end
- local function stargateSend() -- ответ по айрис
- local _, _, sms = event.pull(5, 'sgMessageReceived')
- if sms == "PING" then
- stargate.sendMessage('PONG')
- return true
- elseif sms == "STATUS" then
- stargate.sendMessage(stargate.irisState())
- return true
- else
- return false
- end
- end
- local function printStat(reception) -- окно открытия врат
- local a, i, vr = {}, 0, '##'
- ScreenBuffer(13, 7, 13 + 32, 15, true)
- errors(13, 7, {'Открытие врат', '[----------------------]', '', '', ''}, 0x0000ff, 0, true)
- if reception then
- i = 2
- gpu.set(16, 10, vr)
- end
- gpu.setBackground(0x0000ff)
- repeat
- a = {event.pull(4)}
- if a[1] == 'sgChevronEngaged' then
- i = i + 2
- gpu.set(14 + i, 10, vr)
- elseif a[1] == 'sgStargateStateChange' then
- i = 22
- vr = ('#'):rep(i)
- gpu.set(16, 10, vr)
- end
- gpu.set(40, 10, math.ceil(i*100/22)..'%')
- if not reception and i == 22 then
- gpu.set(15, 11, 'Ожидаю отчет по айрис ...')
- vr, stat = stargateStart()
- if stat == nil then
- gpu.set(15, 12, vr)
- gpu.set(15, 13, 'Возможно, айрис закрыт')
- elseif stat == false then
- gpu.set(15, 12, vr)
- gpu.set(15, 13, 'Переход запрещен!')
- stargate.disconnect()
- break;
- else
- gpu.set(15, 12, vr)
- gpu.set(15, 13, 'Переход разрешаю, удачи!')
- end
- elseif reception and i == 22 then
- gpu.set(15, 11, 'Ожидаю проверки моста ...')
- if stargateSend() then
- gpu.set(15, 12, 'Успешно')
- else
- gpu.set(15, 12, 'Нет запроса')
- end
- gpu.set(15, 13, 'Ожидаю проверки айрис ...')
- if stargateSend() then
- gpu.set(15, 14, 'Успешно')
- else
- gpu.set(15, 14, 'Нет запроса')
- end
- end
- until a[1] == nil
- ScreenBuffer(13, 7, 13 + 32, 15, false)
- if a[1] == nil and i == 22 then
- errors(13, 7, {'Врата настроены', 'Переход разрешен, но помните', 'нам неизвестно, что ждет вас', 'на той стороне врат.'}, 0x00aa00, 10, false)
- else
- errors(13, 7, {'ОШИБКА!', 'Произошла ошибка при ', 'построении моста. Переход ', 'запрещен из - за закрытия айрис', 'или по неизвестной причине'}, 0xaa0000, 10, false)
- end
- end
- local function errorBaza() -- стартовый мастер. работает только 1 раз для заполнения основной бызы
- errors(13, 7, {"ERROR", "База не заполнена. Пожалуйста, ", "заполните базу данных вручную ", "в следующем порядке (ВАЖНО!) ", "Cпавн = "..tostring(Baza[1]), "Ад = "..tostring(Baza[2]), "Край = "..tostring(Baza[3]), "Мир - шахта = "..tostring(Baza[4])}, 0xaa0000, nil)
- gpu.setResolution(80, 24)
- print('Мастер быстрой настройки активен')
- print('Желаете настроить базу данных в полуавтоматическом режиме? (y/n)')
- local vr = io.read()
- if vr == 'y' then
- local a = {}
- print('Адрес считывается автоматически, вам надо заполнить только остальную информацию')
- print('Адрес текущих врат '..stargate.localAddress()..'\nЕсли адрес другой, введите его, если совпадает, нажмите Enter')
- vr = io.read()
- os.sleep(0.1)
- local i = #Baza + 1
- if vr == '' then
- a[#a + 1] = stargate.localAddress()
- else
- a[#a + 1] = vr
- end
- print('Где мы находимся? (введите название этих врат)')
- vr = io.read()
- os.sleep(0.1)
- if vr == '' then
- print('ERROR! Имя не может быть пустым!')
- os.exit()
- else
- a[#a + 1] = vr
- end
- print('Разрешить доступ к этим вратам? (введите true/false)')
- vr = io.read()
- os.sleep(0.1)
- if vr == '' then
- print('ERROR! Доступ не может быть пустым!')
- os.exit()
- else
- a[#a + 1] = vr
- end
- print('Сохраняю ...')
- Baza[#Baza + 1] = {['name'] = a[2], ['adress'] = a[1], ['access'] = a[3]}
- print('В память базы записано')
- AllBaza[#AllBaza + 1] = a[1]
- print('В память общих точек записано')
- openFile(nil, 3, true)
- print('База сохранена')
- bazaAdress(false, true)
- print('Случайная база сохранена')
- print('Все сохранено. Переместитесь к следующим вратам и сохраните их. Диск можете с собой утащить. Напомню порядок: Cпавн, Ад, Край, Мир - шахта\nВсе остальные точки врат можно будет настроить через нормальное меню')
- else
- print('Для ручной настройки заполните файл ../Stargate/System/Baza.csv по образцу \n[Имя];[Адрес];[Доступность];\n Пример:\nСпавн;UYBM - 6ZK - SA;true;')
- end
- os.exit()
- end
- local function errorDial(vr) -- ответ на разнообразные ошибки
- if string.find(vr, 'busy') ~= nil then
- errors(13, 7, {'ОШИБКА!', 'Данные врата уже подключены к', 'другому мосту. ', 'Подождите 30 секунд и', 'повторите попытку'}, 0xaa0000, 10, false)
- elseif vr == 'Stargate cannot connect to itself' then
- errors(13, 7, {'ОШИБКА!', 'Вы пытаетесь подключиться к ', 'этим же вратам.', 'Будьте внимательны при наборе'}, 0xaa0000, 10, false)
- elseif vr == 'Malformed stargate address' then
- errors(13, 7, {'ОШИБКА!', 'Некорректный ввод адреса.', 'Будьте внимательны при наборе'}, 0xaa0000, 10, false)
- elseif string.find(vr, 'chevrons') ~= nil then
- errors(13, 7, {'ОШИБКА!', 'Не хватает шевронов для', 'перехода в указанную вами', 'точку. Добавьте еще 1 шеврон', 'и повторите попытку'}, 0xaa0000, 10, false)
- elseif vr == nil then
- return
- else
- errors(13, 7, {'ОШИБКА!', 'Данных врат не существует.', 'Будьте внимательны при наборе'}, 0xaa0000, 10, false)
- end
- end
- local function editPoint(num, name) -- удаление пользовательских точек
- if errors(13, 7, {'Информация по точке', 'Имя: '..UserBaza[num].name, 'Адрес: '..UserBaza[num].adress, 'ПКМ - удалить', 'ЛКМ - обратно'}, 0x0000ff, 10, false, name) then
- -- print('удаляю')
- table.remove(UserBaza, num)
- openFile(name, 2, false, true)
- UserBaza = {}
- list = {}
- openFile(name, 2)
- bottomMass2 = {}
- advertising(1, true)
- Temp[1].list = 1
- end
- end
- local function touchOn(x, y, name, key) -- обработчик нажатий
- if x >= 2 and x <= 29 and menu <= 1 then -- главное меню
- for i = 1, #bottomMass do
- -- print(tostring(bottomMass[i].y0 >= a[4])..'|'..tostring(bottomMass[i].y1 <= a[4])..'|'..tostring(bottomMass[i].x0 <= a[3])..'|'..tostring(bottomMass[i].x1 >= a[3]))
- if bottomMass[i].y0 <= a[4] and bottomMass[i].y1 >= a[4] and bottomMass[i].x0 <= a[3] and bottomMass[i].x1 >= a[3] then
- if bottomMass[i].y1 - bottomMass[i].y0>3 then
- bottomPress(bottomMass[i].y0, bottomMass[i].y1, bottomMass[i].x0, bottomMass[i].x1, true)
- else
- bottomPress(bottomMass[i].y0, bottomMass[i].y1, bottomMass[i].x0, bottomMass[i].x1)
- end
- if i == 1 then
- bottomMass2 = {}
- bottomMenu(name)
- menu = 2
- Temp[2].name1 = name
- -- openFile(name, 2, true) -- убрать, это для теста
- UserBaza = {}
- list = {}
- openFile(name, 2)
- elseif i == 6 then
- -- print('RANDOM')
- bazaAdress(false, false, false, true)
- stargate.disconnect()
- os.sleep(2)
- local _, vr = stargate.dial(Baza[i - 1].adress)
- if vr ~= nil then
- errorDial(vr)
- end
- else
- stargate.disconnect()
- -- print(Baza[i - 1].adress..'|'..Baza[i - 1].name..'|'..i - 1)
- if Baza[i - 1].access then
- os.sleep(2)
- local _, vr = stargate.dial(Baza[i - 1].adress)
- if vr ~= nil then
- errorDial(vr)
- end
- else
- errors(13, 7, {'ОШИБКА!', 'Переход в текущую точку', 'запрещен администратором'}, 0xaa0000, 10)
- end
- end
- return
- end
- end
- elseif x >= 31 and x <= 53 and menu == 2 then -- меню входа
- if name == Temp[2].name1 then
- for i = 1, #bottomMass2 do
- if bottomMass2[i].y0 <= a[4] and bottomMass2[i].y1 >= a[4] and bottomMass2[i].x0 <= a[3] and bottomMass2[i].x1 >= a[3] then
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- if i == 1 then
- stargate.disconnect()
- os.sleep(2)
- local _, vr = stargate.dial(UserBaza[1].ends)
- if vr ~= nil then
- errorDial(vr)
- end
- elseif i == 2 then
- menu = 4
- bottomMass2 = {}
- advertising(1, true)
- Temp[1].list = 1
- elseif i == 3 then
- bottomMass2 = {}
- bottomMenuNew()
- menu = 3
- Temp[1] = {['name'] = '', ['adress'] = ''}
- -- print(#UserBaza..' menu '..menu)
- elseif i == 4 then
- bottomMass2 = {}
- list = {}
- for i = 5, #Baza do
- list[#list + 1] = Baza[i].name
- end
- advertising(1)
- Temp[2].name1 = ''
- Temp[1].list = 1
- menu = 1
- end
- return
- end
- end
- end
- elseif x >= 31 and x <= 53 and menu == 3 then -- меню новая точка
- for i = 1, #bottomMass2 do
- if bottomMass2[i].y0 <= a[4] and bottomMass2[i].y1 >= a[4] and bottomMass2[i].x0 <= a[3] and bottomMass2[i].x1 >= a[3] then
- if i == 1 then
- term.setCursor(32, 6)
- Temp[1].name = unicode.sub(io.read(), 1, 15)
- elseif i == 2 then
- term.setCursor(32, 10)
- Temp[1].adress = unicode.sub(io.read(), 1, 15)
- elseif i == 3 then
- if name == Temp[2].name1 then
- if Temp[1].name ~= '' and Temp[1].adress ~= '' then
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- UserBaza[#UserBaza + 1] = {['name'] = Temp[1].name, ['adress'] = Temp[1].adress}
- openFile(name, 2, false, true)
- errors(13, 7, {'Сохранено!', 'Точка врат добавлена.', 'Рекомендую проверить её работу'}, 0x00aa00, 3)
- bazaAdress(false, Temp[1].adress)
- bazaAdress(false, false, true)
- bottomMass2 = {}
- bottomMenu(name)
- menu = 2
- UserBaza = {}
- list = {}
- openFile(name, 2)
- else
- errors(13, 7, {'ОШИБКА!', 'Некорректный ввод названия ', 'точки телепорта или адреса ', 'врат. Проверьте еще раз прави - ', 'льность ввода. В случае ', 'повторения ошибки, запишите её', 'на видео и предоставьте админу'}, 0xaa0000, 10)
- bottomMenuNew()
- end
- end
- elseif i == 4 then
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- bottomMass2 = {}
- bottomMenu(name)
- menu = 2
- UserBaza = {}
- list = {}
- openFile(name, 2)
- end
- return
- end
- end
- elseif x >= 31 and x <= 53 and menu == 4 then -- меню телепортов пользователя
- if name == Temp[2].name1 then
- for i = 1, #bottomMass2 do
- if bottomMass2[i].y0 <= a[4] and bottomMass2[i].y1 >= a[4] and bottomMass2[i].x0 <= a[3] and bottomMass2[i].x1 >= a[3] then
- if i == 1 then
- print(tonumber(Temp[1].list))
- if Temp[1].list - 1 > 0 then
- Temp[1].list = Temp[1].list - 1
- advertising(Temp[1].list, true)
- end
- elseif i == 2 then
- if Temp[1].list + 1 <= math.ceil(#list/6) then
- Temp[1].list = Temp[1].list + 1
- advertising(Temp[1].list, true)
- end
- elseif i == 3 then
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- menu = 2
- bottomMass2 = {}
- bottomMenu(name)
- else
- if key == 1 then
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- editPoint((i - 3) + (Temp[1].list - 1)*6, name)
- else
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- stargate.disconnect()
- -- print(list[(i - 3) + (Temp[1].list - 1)*6]..'|'..UserBaza[(i - 3) + (Temp[1].list - 1)*6].name..'|'..i)
- UserBaza[1].ends = UserBaza[(i - 3) + (Temp[1].list - 1)*6].adress
- openFile(name, 2, false, true)
- os.sleep(2)
- local _, vr = stargate.dial(UserBaza[1].ends)
- if vr ~= nil then
- errorDial(vr)
- end
- end
- end
- return
- end
- end
- end
- elseif x >= 31 and x <= 53 and menu <= 1 then -- меню телепортов официальных
- for i = 1, #bottomMass2 do
- if bottomMass2[i].y0 <= a[4] and bottomMass2[i].y1 >= a[4] and bottomMass2[i].x0 <= a[3] and bottomMass2[i].x1 >= a[3] then
- if i == 1 then
- if Temp[1].list - 1 > 0 then
- Temp[1].list = Temp[1].list - 1
- advertising(Temp[1].list)
- end
- elseif i == 2 then
- if Temp[1].list + 1 <= math.ceil(#list/7) then
- Temp[1].list = Temp[1].list + 1
- advertising(Temp[1].list)
- end
- else
- bottomPress(bottomMass2[i].y0, bottomMass2[i].y1, bottomMass2[i].x0, bottomMass2[i].x1)
- stargate.disconnect()
- -- print(list[(i - 2) + (Temp[1].list - 1)*7]..'|'..Baza[(i + 2) + (Temp[1].list - 1)*7].name)
- if Baza[(i + 2) + (Temp[1].list - 1)*7].access then
- os.sleep(2)
- local _, vr = stargate.dial(Baza[(i + 2) + (Temp[1].list - 1)*7].adress)
- if vr ~= nil then
- errorDial(vr)
- end
- else
- errors(13, 7, {'ОШИБКА!', 'Переход в текущую точку', 'запрещен администратором'}, 0xaa0000, 10)
- end
- end
- return
- end
- end
- end
- end
- ----------- ПЕРЕМЕННЫЕ ----------------------
- Buffer = {} -- буфер для графики (Оторожно, выжирает почти всю память)
- gpu.setResolution(54, 19)
- term.clear()
- bottomMass = {} -- кнопки большие
- bottomMass2 = {} -- кнопки маленькие
- Baza = {} -- главные точки врат
- UserBaza = {} -- пользовательские точки врат
- AllBaza = {} -- хранит все адреса
- list = {} -- список адресов для маленьких кнопок
- if not fl.exists("../Stargate") then
- print('нету ../Stargate')
- fl.makeDirectory("../Stargate/Users/")
- fl.makeDirectory("../Stargate/System/")
- openFile(nil, 3, true)
- bazaAdress(true)
- end
- openFile(nil, 3)
- if #Baza < 4 then
- errorBaza()
- end
- event.shouldInterrupt = function () return false end --защита от ctrl+alt+c
- Temp = {} -- временные данные
- Temp[1] = {['name'] = '', ['adress'] = '', ['list'] = 1}
- Temp[2] = {['time'] = 1, ['name'] = 'ХЗ', ['name1'] = ''}
- bazaAdress(false, false, true)
- usersQuantity(false)
- print('LOADING ...')
- local name = ''
- ---------------- ОСНОВНОЙ ЦИКЛ ------------------------
- repeat
- a = {event.pull(1)}
- if a[1] == 'sgStargateStateChange' or a[1] == 'sgDialIn' and a[3] ~= 'Closing' then
- a = {event.pull(1)}
- if a[1] == 'sgDialOut' then
- -- print('передатчик')
- printStat(false)
- else
- -- print('приемник')
- printStat(true)
- end
- elseif a[1] == 'touch' then
- touchOn(a[3], a[4], a[6], a[5])
- name = a[6]
- Temp[2].time = 30
- -- gpu.set(33, 4, 'x = '..a[3]..' y = '..a[4]..' ')
- elseif a[1] == nil then
- Temp[2].time = Temp[2].time - 1
- oval()
- if Temp[2].time <= 0 then
- Temp[2].time = 30
- Temp[2].name = name
- Temp[2].name1 = ''
- name = ''
- menu = 1
- stargate.disconnect()
- errors(13, 7, {'Информация', 'Система переведена в режим ', 'ожидания, для активации ', 'нажмите куда - нибудь'}, 0x00aa00, nil, false)
- term.clear()
- frame()
- oval(true)
- bottomSave()
- Baza = {}
- openFile(nil, 3)
- list = {}
- for i = 5, #Baza do
- list[#list + 1] = Baza[i].name
- end
- advertising(1)
- oval()
- end
- end
- until a[1] == 'key_up' and a[4] == 59
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement