qwertytrains

Axzen OS

Oct 19th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.13 KB | None | 0 0
  1. --Stops the people terminating the program
  2. local pullEvent = os.pullEvent
  3. os.pullEvent = os.pullEventRaw
  4. --Create variables for later
  5. local osver = "OS version"
  6. local osname = "openBananaOS"
  7. local programs = "[Programs]  [Time]  [Logout]"
  8. local times = ""
  9. local name = ""
  10. local username = ""
  11. local password = ""
  12. local i = 0
  13. local confirmpassword = ""
  14. local input2 = ""
  15. local input1 = ""
  16. local usertable = {}
  17. local login = 0
  18. local j = 0
  19. local n = 0
  20. local user = ""
  21. local pass = ""
  22. local permission = ""
  23. local found = "false"
  24.  
  25.  
  26.  
  27. --Clear function
  28. function clear()
  29.     term.clear()
  30.     term.setCursorPos(1,1)
  31. end
  32. function time()
  33.     times = os.date("!%H:%M:%S")
  34.     clear()
  35.     slowPrint(times)
  36. end
  37.  
  38.  
  39. --Shorten textutils.slowPrint
  40. function slowPrint(msg)
  41.     textutils.slowPrint(msg)
  42. end
  43.  
  44.  
  45.  
  46. --Shorten textutils.slowWrite
  47. function slowWrite(msg)
  48.     textutils.slowWrite(msg)
  49. end
  50.  
  51.  
  52.  
  53.  
  54. --Center Text
  55. function centerText(text)
  56.     local x,y = term.getSize()
  57.     local x2,y2 = term.getCursorPos()
  58.     term.setCursorPos(math.ceil((x/2) - (text:len() / 2)), y2)
  59.     write(text)
  60. end
  61. function string:split(sSeparator, nMax, bRegexp)
  62.     assert(sSeparator ~= '')
  63.     assert(nMax == nil or nMax >= 1)
  64.  
  65.     local aRecord = {}
  66.  
  67.     if self:len() > 0 then
  68.         local bPlain = not bRegexp
  69.         nMax = nMax or -1
  70.  
  71.         local nField=1 nStart=1
  72.         local nFirst,nLast = self:find(sSeparator, nStart, bPlain)
  73.         while nFirst and nMax ~= 0 do
  74.             aRecord[nField] = self:sub(nStart, nFirst-1)
  75.             nField = nField+1
  76.             nStart = nLast+1
  77.             nFirst,nLast = self:find(sSeparator, nStart, bPlain)
  78.             nMax = nMax-1
  79.         end
  80.         aRecord[nField] = self:sub(nStart)
  81.     end
  82.  
  83.     return aRecord
  84. end
  85.  
  86.  
  87.  
  88.  
  89.  
  90. --System Setup on first boot
  91. if fs.exists("users.dat") == false then
  92.     slowPrint(osname.." has not been setup yet!")
  93.     slowPrint(osname..".setup initializing...")
  94.     sleep(1)
  95.     clear()
  96.     slowWrite("[SetuPro] What is your name? ")
  97.     name = read()
  98.     clear()
  99.     slowWrite("[SetuPro] Please enter your desired username: ")
  100.     username = read()
  101.     i = 0
  102.     while i == 0 do
  103.         slowWrite("[SetuPro] Please enter your desired password: ")
  104.         password = read("*")
  105.         slowWrite("[SetuPro] Please confirm your password: ")
  106.         confirmpassword = read("*")
  107.         if password == confirmpassword then
  108.             i = 1
  109.             clear()
  110.             slowPrint("[SetuPro] Passwords match")
  111.         else
  112.             clear()
  113.             slowPrint("[SetuPro] Passwords do not match, please try again")
  114.         end
  115.     end
  116.     input = name..":"..username..":"..password..":owner"
  117.     usertable = {}
  118.     table.insert(usertable, 1, input2)
  119.     input2 = textutils.serialize(usertable)
  120.     local writefile = fs.open("users.dat","w")
  121.     writefile.write(input2)
  122.     writefile.close()
  123. end
  124.    
  125. local tmp = fs.open("users.dat","r")
  126. local users = tmp.readAll()
  127. tmp.close()
  128. local userlist = textutils.unserialize(users)
  129.  
  130.  
  131. while true do
  132.  
  133. --Booting Screen
  134.     clear()
  135.     term.setCursorPos(1,4)
  136.     centerText("[ "..osname.." ]")
  137.     term.setCursorPos(1,6)
  138.     centerText("  "..osver.."  ")
  139.     sleep(2)
  140.     i = 0
  141.     login = 0
  142.     while i == 0 do
  143.         clear()
  144.         print(osname..osver.."(TM)")
  145.         slowWrite("Please enter your username: ")
  146.         user = read()
  147.         slowWrite("Please enter your password: ")
  148.         pass = read("*")
  149.         j = 0
  150.         n = 1
  151.         found = false
  152.         while j == 0 do
  153.             test = userlist[n]
  154.             test = string.split(test,":")
  155.             if test == nil then
  156.                 j = 1
  157.             else
  158.                 name = test[1]
  159.                 username = test[2]
  160.                 password = test[3]
  161.                 permission = test[4]
  162.                 if username == user and password == pass then
  163.                     found = true
  164.                     j = 1
  165.                 else
  166.                     n = n+1
  167.                 end
  168.             end
  169.         end
  170.         if found == false then
  171.             slowPrint("Username/Password incorrect, please try again")
  172.             sleep(2)
  173.             clear()
  174.         else
  175.             i = 1
  176.             slowPrint("Username and password correct!")
  177.             sleep(1)
  178.             clear()
  179.         end
  180.     end
  181.     clear()
  182.     while login == 1 do
  183.         clear()
  184.         print(osname..osver.."(TM)")
  185.         print("Welcome to" ..osname.." "..name)
  186.         sleep(1)
  187.         slowPrint("Type 'programs' to view the programs avaliable")
  188.         slowWrite("Please enter a program: ")
  189.         input1 = read()
  190.         input2 = string.lower(input1)
  191.         if input2 == "programs" then
  192.             clear()
  193.             slowPrint("Avaliable programs: ")
  194.             slowPrint(programs)
  195.             print("")
  196.             slowPrint("Press enter to continue...")
  197.             read()
  198.         elseif input2 == "logout" then
  199.             clear()
  200.             login = 0
  201.             slowPrint("Logged out!")
  202.         elseif input2 == "time" then
  203.             clear()
  204.             slowPrint("The time in UTC is: ")
  205.             time()
  206.         else
  207.             slowPrint(input2.." is not a recognised program")
  208.         end
  209.     end
  210. end
Advertisement
Add Comment
Please, Sign In to add comment