Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local users = {}
- local function displayStartupAnimation()
- local width, height = term.getSize()
- for i = 1, 30 do
- term.clear()
- term.setCursorPos((width - #("Daedalus OS")) / 2, height / 2)
- write("Daedalus OS")
- sleep(0.05)
- end
- term.clear()
- term.setCursorPos((width - #("Computer ID: " .. os.getComputerID())) / 2, height / 2 + 1)
- print("Computer ID: " .. os.getComputerID())
- sleep(2)
- end
- local function loadUsers()
- local file = fs.open("users.txt", "r")
- if file then
- local line = file.readLine()
- while line do
- local username, password = line:match("([^:]+):([^:]+)")
- if username and password then
- users[username] = password
- end
- line = file.readLine()
- end
- file.close()
- else
- error("Benutzerdatei nicht gefunden.")
- end
- end
- local function authenticate(username, password)
- return users[username] and users[username] == password
- end
- local function getModemSide()
- local file = fs.open("modemSide.txt", "r")
- if file then
- local side = file.readLine()
- file.close()
- return side
- else
- return nil
- end
- end
- local function setModemSide(side)
- local file = fs.open("modemSide.txt", "w")
- file.writeLine(side)
- file.close()
- end
- local function askForModemSide()
- print("Bitte wähle die Seite des Modems: ")
- local sides = {"left", "right", "top", "bottom", "front", "back"}
- for i, side in ipairs(sides) do
- print(i .. ". " .. side)
- end
- local choice = read()
- return sides[tonumber(choice)]
- end
- local function startAuthServer(modemSide)
- loadUsers()
- if not rednet.isOpen(modemSide) then
- rednet.open(modemSide)
- end
- print("Auth-Server läuft auf der Seite: " .. modemSide)
- while true do
- local senderId, message, protocol = rednet.receive()
- local username, password = string.match(message, "([^:]+):([^:]+)")
- if authenticate(username, password) then
- rednet.send(senderId, "SUCCESS", protocol)
- else
- rednet.send(senderId, "FAILURE", protocol)
- end
- end
- end
- displayStartupAnimation()
- local modemSide = getModemSide()
- if not modemSide then
- modemSide = askForModemSide()
- setModemSide(modemSide)
- end
- startAuthServer(modemSide)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement