Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Программа похожа на публичные чаты на локальной сетке, бывшие популярными когда-то давно.
- -- [ БИБЛИОТЕКИ И КОМПОНЕНТЫ ] --
- local com = require('component')
- local term = require('term')
- local event = require('event')
- local net = com.modem
- local gpu = com.gpu
- local w, h = gpu.getResolution()
- local n = 2
- local buffer = {'sample'}
- -- [ /////////////////////// ] --
- function scroll(text) -- Тут у нас буфер для более-менее человеческого сдвига сообщений вверх
- table.remove(buffer, 1)
- table.insert(buffer, text)
- for i in 1, #t do
- term.setCursor(2, i+1)
- term.write(nick..' : '..buffer[i])
- end
- end
- for i = 1, h-4 do -- Генерируем пустой буфер с количеством ячеек == высоте основного окна
- buffer[i] = ' '
- end
- net.open(33)
- print("Добро пожаловать в The 00's Chat!")
- print('Введите ваш никнейм: ')--, term.read) -- На входе логиним пользователя
- nick = term.read()
- term.clear()
- -- [ ИНТЕРФЕЙС ] --
- gpu.fill(1, 1, w, h, '@')
- gpu.fill(2, 2, w-2, h-2, ' ') -- Получаем рамку
- gpu.fill(1, h-2, w, 1, '@') -- Отделяем окно ввода от основного окна
- term.setCursor(2, h-1) -- Ставим курсор в начало окна ввода
- term.setCursorBlink()
- -- [ ///////// ] --
- net.broadcast(33, 'Admin: '..nick..' присоединился к беседе.') -- Объявляем другим пользователям
- while true do
- local name, _, _, _, message_in = event.pull(0.5, 'modem_message') -- Приём сообщений
- if name == 'modem_message' then
- scroll(message_in)
- end
- local name, _, char = event.pull(0.5, 'key_down')
- if name == 'key_down' and char == 'i' then -- Отправка
- term.setCursor(2, h-1)
- message_out = term.read()
- net.broadcast(33, nick..' : '..message_out)
- scroll(message_out)
- end
- if name == 'key_down' and char == 'q' then -- Выход
- net.broadcast(33, 'Admin: '..nick..' покинул беседу.')
- break
- end
- end
- net.close()
- term.clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement