Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local speaker = peripheral.find("speaker")
- if fs.exists("govry/") == false then
- fs.makeDir("govry")
- end
- if speaker then
- sound = speaker.playNote
- end
- local _defAccounts = {
- { user = 'admin', pass = 'admin', admin = true },
- { user = 'guest', pass = 'guest', admin = false },
- }
- if fs.exists("govry/users/") == false then
- fs.makeDir("govry/users")
- end
- if fs.exists("govry/accounts.cfg") == false then
- local file = fs.open("govry/accounts.cfg","w")
- file.write(textutils.serialise(_defAccounts))
- file.close()
- file = nil
- end
- file = fs.open("govry/accounts.cfg","r")
- if not file then
- error('Unable to open file')
- end
- local accounts = {}
- local temp = 0
- local accounts = textutils.unserialise(file.readAll())
- if not accounts then
- accounts = _defAccounts
- fs.delete("govry/accounts.cfg")
- printError("Improperly formated account file!")
- printError()""
- end
- --local length = fs.getSize("govry/accounts.cfg")
- --length is size in bytes / not # lines
- --while true do
- -- temp = temp + 1
- -- line = file.readLine()
- -- if not line then break end
- -- unline = textutils.unserialise(line)
- -- table.insert(accounts, unline)
- --end
- term.setPaletteColor(1,0xC9C9FF)
- term.setPaletteColor(256,0xB9B9FF)
- term.setPaletteColor(32768,0x222299)
- term.setPaletteColor(128,0x6666FF)
- term.setPaletteColor(32,0x6699AA)
- term.setPaletteColor(16384,0x9966AA)
- term.setPaletteColor(2,0x000099)
- file.close()
- term.setBackgroundColor(colors.white)
- term.clear()
- local width, height = term.getSize()
- term.setCursorPos(3,13)
- term.setTextColor(colors.gray)
- if os.getComputerLabel() ~= nil then
- write("Computer Label: ")
- write(os.getComputerLabel())
- else
- term.setTextColor(colors.red)
- write("No Label!")
- term.setTextColor(colors.gray)
- end
- term.setCursorPos(3,10)
- write("Computer ID: ")
- write(os.getComputerID())
- paintutils.drawFilledBox(1,1,width,3,colors.gray)
- paintutils.drawFilledBox(1,height - 3,width,height,colors.gray)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(width - 30, 6)
- write("Username")
- term.setCursorPos(width - 30, 8)
- write("Password")
- entry = false
- local admin = false
- term.setTextColor(colors.gray)
- local length = #accounts
- function main()
- repeat
- paintutils.drawLine(width - 20, 8, width - 1, 8, colors.lightGray)
- paintutils.drawLine(width - 20, 6, width - 1, 6, colors.lightGray)
- term.setCursorPos(width - 20, 6)
- username = read()
- term.setCursorPos(width - 20, 8)
- password = read()
- for id = 1, length do
- if accounts[id].user == username then
- if accounts[id].pass == password then
- entry = true
- admin = accounts[id].admin
- name = accounts[id].user
- end
- end
- end
- if entry == false then
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(width - 20, 10)
- write("Login failed!")
- sleep(1)
- term.setCursorPos(width - 20, 10)
- write(" ")
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.lightGray)
- end
- until entry == true
- term.setBackgroundColor(colors.white)
- term.setCursorPos(width - 20, 10)
- write("Login successful!")
- term.setCursorPos(width - 20, 11)
- if admin == true then
- term.setTextColor(colors.lime)
- write("Admin")
- else
- term.setTextColor(colors.orange)
- write("Normal")
- end
- write(" account")
- sleep(2)
- term.setBackgroundColor(colors.white)
- term.clear()
- if speaker then
- sound("harp",1,5)
- sleep(0.2)
- sound("harp",1,9)
- sleep(0.2)
- sound("harp",1,8)
- sleep(0.2)
- sound("harp",1,6)
- end
- sleep(0.2)
- paintutils.drawFilledBox(1, height - 1, width, height, colors.gray)
- local modem = peripheral.find("modem")
- term.setCursorPos(width - 4, height)
- if modem then
- term.setTextColor(colors.black)
- write("Ooo")
- end
- local dir = "/"
- if fs.exists("govry/users/"..name.."/") == false then
- fs.makeDir("govry/users/"..name)
- end
- if admin == false then
- dir = "govry/users/"..name.."/"
- end
- local files = fs.list("govry/users/"..name.."/")
- pos = 1
- while true do
- term.setTextColor(colors.white)
- for pc = 1, height - 2 do
- term.setCursorPos(2,pc)
- if files[pc] then
- write(files[pc])
- end
- end
- _, m, x, y = os.pullEvent("mouse_click")
- end
- end
- function stop()
- while true do
- local ok, msg = pcall(main)
- if not ok then
- term.setCursorBlink(false)
- term.setPaletteColor(32768,0x570000)
- term.setPaletteColor(16384,0xAA0000)
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(2,2)
- write("Uh oh! The system has crashed!")
- term.setCursorPos(2,4)
- write("The error was caused by:")
- term.setCursorPos(1,6)
- write("-"..msg)
- sleep(2)
- term.setCursorPos(2,10)
- write("Rebooting system...")
- sleep(1)
- os.reboot()
- end
- end
- end
- while true do
- local ok, msg = pcall(stop)
- if not ok then
- if admin == true then
- local color = term.setPaletteColor
- color(1,0xF0F0F0)
- color(2,0xF2B223)
- color(32,0x7FCC19)
- color(128,0x4C4C4C)
- color(256,0x999999)
- color(16384,0xCC4C4C)
- color(32768,0x191919)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error("Closed by admin")
- else
- os.reboot()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement