Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local FILE_USERNAME = "username"
- local FILE_PASSWORD = "password"
- local USERNAME = nil
- local PASSWORD = nil
- local AUTHENTICATED = false
- local RUNNING = false
- local MODEM = "right"
- local LINES = {}
- --
- function install()
- term.clear()
- term.setCursorPos(1, 1)
- while USERNAME == nil or USERNAME == "" do
- USERNAME = inputUsername()
- end
- local file = io.open(FILE_USERNAME, "w")
- file:write(USERNAME)
- file:close()
- term.setCursorPos(1, 2)
- while PASSWORD == nil or PASSWORD == "" do
- PASSWORD = inputPassword()
- end
- file = io.open(FILE_PASSWORD, "w")
- file:write(PASSWORD)
- file:close()
- term.setCursorPos(1, 2)
- print("Installation successfull. Starting application.")
- sleep(1)
- end
- function inputUsername()
- term.write("Choose a username: ")
- return read()
- end
- function inputPassword()
- term.write("Choose a password: ")
- return read()
- end
- function inputAuthenticate()
- term.clearLine()
- term.write("Password: ")
- return read("*")
- end
- function updateOnlineList()
- while RUNNING do
- term.setCursorPos(1, 1)
- term.write("Online: ")
- term.setCursorPos(8, 3)
- sleep(1)
- end
- return false
- end
- function writeLineBuffer()
- term.setCursorPos(1, 5)
- term.clearLine()
- term.write(LINES[0])
- term.setCursorPos(1, 6)
- term.clearLine()
- term.write(LINES[1])
- term.setCursorPos(1, 7)
- term.clearLine()
- term.write(LINES[2])
- term.setCursorPos(1, 8)
- term.clearLine()
- term.write(LINES[3])
- term.setCursorPos(1, 9)
- term.clearLine()
- term.write(LINES[4])
- term.setCursorPos(1, 10)
- term.clearLine()
- term.write(LINES[5])
- term.setCursorPos(1, 11)
- term.clearLine()
- term.write(LINES[6])
- term.setCursorPos(1, 12)
- term.clearLine()
- term.write(LINES[7])
- term.setCursorPos(1, 13)
- term.clearLine()
- term.write(LINES[8])
- term.setCursorPos(1, 14)
- term.clearLine()
- term.write(LINES[9])
- term.setCursorPos(1, 15)
- term.clearLine()
- term.write(LINES[10])
- term.setCursorPos(1, 16)
- term.clearLine()
- term.write(LINES[11])
- term.setCursorPos(1, 17)
- term.clearLine()
- term.write(LINES[12])
- term.setCursorPos(1, 18)
- term.clearLine()
- term.write(LINES[13])
- term.setCursorPos(8, 3)
- end
- function updateBuffer()
- local senderId, message, distance
- while RUNNING do
- senderId, message, distance = rednet.receive(1)
- if message ~= "" and message ~= nil then
- addMessage(message)
- end
- end
- return false
- end
- function handleInput()
- local message
- while RUNNING do
- term.setCursorPos(1, 3)
- term.clearLine()
- term.write("Send > ")
- message = USERNAME .. ": " .. read()
- addMessage(message)
- rednet.broadcast(message)
- end
- return false
- end
- function addMessage(message)
- LINES[0] = LINES[1]
- LINES[1] = LINES[2]
- LINES[2] = LINES[3]
- LINES[3] = LINES[4]
- LINES[4] = LINES[5]
- LINES[5] = LINES[6]
- LINES[6] = LINES[7]
- LINES[7] = LINES[8]
- LINES[8] = LINES[9]
- LINES[9] = LINES[10]
- LINES[10] = LINES[11]
- LINES[11] = LINES[12]
- LINES[12] = LINES[13]
- LINES[13] = message
- writeLineBuffer()
- end
- if fs.exists(FILE_USERNAME) and fs.exists(FILE_PASSWORD) then
- local file = fs.open(FILE_USERNAME, "r")
- USERNAME = file:readLine()
- file:close()
- if USERNAME == nil or username == "" then
- install()
- end
- file = fs.open(FILE_PASSWORD, "r")
- PASSWORD = file:readLine()
- file:close()
- if PASSWORD == nil or PASSWORD == "" then
- install()
- end
- else
- install()
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome " .. USERNAME)
- while AUTHENTICATED == false do
- term.setCursorPos(1, 3)
- local password = inputAuthenticate()
- if password == PASSWORD then
- AUTHENTICATED = true
- RUNNING = true
- end
- end
- term.clear()
- term.setCursorPos(1, 2)
- term.write("-------------------------")
- term.setCursorPos(1, 4)
- term.write("-------------------------")
- rednet.open("right")
- parallel.waitForAny(handleInput, updateBuffer, updateOnlineList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement