Advertisement
Guest User

User

a guest
May 18th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.57 KB | None | 0 0
  1. shell.run("/SublarmsOS/conf/Config")
  2.  
  3. os.loadAPI(cfg_rootDir.."/utils/FileHandler")
  4. os.loadAPI(cfg_rootDir.."/utils/TextUtils")
  5.  
  6. config = FileHandler.readVariableFile(cfg_runtimeFile)
  7.  
  8. local function readLen(len, fill)
  9.   local input = ""
  10.   local x,y = term.getCursorPos()
  11.  
  12.   term.setCursorBlink(true)
  13.  
  14.   repeat
  15.     term.setCursorPos(x,y)
  16.     term.write(string.rep(' ',len))
  17.     term.setCursorPos(x,y)
  18.     if fill == nil then
  19.       term.write(input)
  20.     else
  21.       term.write(string.rep(fill, #input))
  22.     end
  23.  
  24.     local event, key = os.pullEvent()
  25.  
  26.     if event == 'char' then
  27.       if #input < len and key ~= ':' then
  28.         input = input .. key
  29.       end
  30.     elseif event == 'key' then
  31.       if key == 14 then
  32.         input = input:sub(1, #input - 1)
  33.       end
  34.     end
  35.   until event == 'key' and key == 28
  36.   term.setCursorBlink(false)
  37.   return input
  38. end
  39.  
  40.  
  41. if config.userAuth == 0 and config.rednet then
  42.   term.clear()
  43.   term.setCursorPos(1,1)
  44.   print(" --------------- SublarmsOS Login ---------------")
  45.   term.setCursorPos(14,6)
  46.   print("[  CONTINUE AS GUEST  ]")
  47.   term.setCursorPos(14,9)
  48.   print("   LOGIN TO SUBLARMS   ")
  49.   term.setCursorPos(1,17)
  50.   print("     Use The Arrow Keys and Enter To Navigate    ")
  51.   term.setCursorPos(1,18)
  52.   i = 0
  53.   write(" ")
  54.   while i < 48 do
  55.     i = i + 1
  56.     write("-")
  57.   end
  58.   beGuest = true
  59.   loginLoop = true
  60.   while loginLoop do
  61.     event, key = os.pullEvent("key")
  62.     if key == 208 then
  63.       beGuest = false
  64.       term.setCursorPos(14,6)
  65.       print("   CONTINUE AS GUEST   ")
  66.       term.setCursorPos(14,9)
  67.       print("[  LOGIN TO SUBLARMS  ]")
  68.     elseif key == 200 then
  69.       beGuest = true
  70.       term.setCursorPos(14,6)
  71.       print("[  CONTINUE AS GUEST  ]")
  72.       term.setCursorPos(14,9)
  73.       print("   LOGIN TO SUBLARMS   ")
  74.     elseif key == 28 then
  75.       loginLoop = false
  76.     else
  77.       -- Random key
  78.     end
  79.   end  
  80.   if not beGuest then
  81.     newAcc = true
  82.     term.setCursorPos(14,6)
  83.     print("[  CREATE AN ACCOUNT  ]")
  84.     term.setCursorPos(14,9)
  85.     print("   I HAVE AN ACCOUNT   ")
  86.     newAccLoop = true
  87.     while newAccLoop do
  88.       event, key = os.pullEvent("key")
  89.       if key == 208 then
  90.         term.setCursorPos(14,6)
  91.         print("   CREATE AN ACCOUNT   ")
  92.         term.setCursorPos(14,9)
  93.         print("[  I HAVE AN ACCOUNT  ]")
  94.         newAcc = false
  95.       elseif key == 200 then
  96.         term.setCursorPos(14,6)
  97.         print("[  CREATE AN ACCOUNT  ]")
  98.         term.setCursorPos(14,9)
  99.         print("   I HAVE AN ACCOUNT   ")
  100.         newAcc = true
  101.       elseif key == 28 then
  102.         newAccLoop = false
  103.       else
  104.         -- Random key
  105.       end
  106.     end
  107.     if newAcc then
  108.      accountVerified = false
  109.      term.setCursorPos(1,17)
  110.      print("                                                 ")
  111.      repeat
  112.       term.setCursorPos(11,5)
  113.       -- Username 12 chars
  114.       print("[  Username:               ]")
  115.       -- Password 12 chars
  116.       term.setCursorPos(11,6)
  117.       print("[  Password:               ]")
  118.       term.setCursorPos(11,7)
  119.       print("[   Confirm:               ]")
  120.       -- Require password on new login
  121.       term.setCursorPos(11,9)
  122.       print("[    Remember Password?    ]")
  123.       term.setCursorPos(11,10)
  124.       print("   YES                 NO   ")
  125.       term.setCursorPos(24,5)
  126.       user = readLen(12)
  127.       pass = ""
  128.       pass2 = ""
  129.       passMatch = false
  130.       repeat
  131.         term.setCursorPos(24,6)
  132.         pass = readLen(12,"*")
  133.         term.setCursorPos(24,7)
  134.         pass2 = readLen(12,"*")
  135.         if pass ~= pass2 or pass == "" then
  136.           term.setCursorPos(1,17)
  137.           print("              Passwords do not match!            ")
  138.           term.setCursorPos(24,6)
  139.           sleep(0.5)
  140.           print("            ")
  141.           term.setCursorPos(24,7)
  142.           print("            ")
  143.         else
  144.           passMatch = true
  145.         end
  146.       until passMatch
  147.       term.setCursorPos(11,10)
  148.       remember = true
  149.       print("[  YES  ]              NO   ")
  150.       term.setCursorPos(1,17)
  151.       print("        Press Enter to create your account       ")
  152.       rememberLoop = true
  153.       while rememberLoop do
  154.         event, key = os.pullEvent("key")
  155.         if key == 205 then
  156.           term.setCursorPos(11,10)
  157.           remember = false
  158.           print("   YES              [  NO  ]")
  159.         elseif key == 203 then
  160.           term.setCursorPos(11,10)
  161.           remember = true
  162.           print("[  YES  ]              NO   ")
  163.         elseif key == 28 then
  164.           rememberLoop = false
  165.         else
  166.           -- Ignore
  167.         end
  168.       end
  169.       remStr = "1"
  170.       if remember then
  171.         remStr = "1"
  172.       else
  173.         remStr = "0"
  174.       end
  175.       term.setCursorPos(1,17)
  176.       print("         Waiting for server response...          ")
  177.       rednet.send(cfg_userServer, "CREATE:"..user..":"..pass..":"..remStr)
  178.       s = 0
  179.       msg = ""
  180.       while s ~= cfg_userServer do
  181.         s, msg = rednet.receive()
  182.       end
  183.       mParts = TextUtils.split(msg, ":")
  184.       if mParts[1] == "PASS" then
  185.         accountVerified = true
  186.         config.user = user
  187.         config.userAuth = mParts[2]
  188.       else
  189.         term.setCursorPos(1,17)
  190.         print("  Failed to create account! Is that name in use? ")
  191.       end
  192.      until accountVerified
  193.     else
  194.       term.setCursorPos(1,17)
  195.       print("                                                 ")
  196.       loggedIn = false
  197.       repeat
  198.         term.setCursorPos(11,5)
  199.         print("[  Username:               ]")
  200.         term.setCursorPos(11,6)
  201.         print("[  Password:               ]")
  202.         term.setCursorPos(7,9)
  203.         print("     Forgot Password? Tell Carg   ")
  204.         term.setCursorPos(24,5)
  205.         user = readLen(12)
  206.         term.setCursorPos(24,6)
  207.         pass = readLen(12,"*")
  208.         term.setCursorPos(1,17)
  209.         print("         Waiting for server response.            ")
  210.         rednet.send(cfg_userServer, "LOGIN:"..user..":"..pass)
  211.         s = 0
  212.         message = ""
  213.         while s ~= cfg_userServer do
  214.           s, message = rednet.receive()
  215.         end
  216.         messageParts = TextUtils.split(message,":")
  217.         if messageParts[1] == "PASS" then
  218.           loggedIn = true
  219.           config.user = user
  220.           config.userAuth = messageParts[2]
  221.         else
  222.           term.setCursorPos(1,17)
  223.           print("                 Failed to login!                ")
  224.         end
  225.       until loggedIn  
  226.     end
  227.   end
  228. end
  229. print(config.username.." "..config.userAuth)
  230. FileHandler.writeVariableFile(cfg_runtimeFile, config)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement