Daniel_Kerman

LOSStartup

Dec 13th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. -- STARTUP --
  2.  
  3. os.loadAPI("lokiOS/files/os/apis/lapi");
  4. lapi.clean(lapi.getCenter("x",9),lapi.getCenter("y"));
  5. textutils.slowWrite("Starting Loki OS..",40); sleep(0.5);
  6. local selected = 0;
  7. while true do
  8.     lapi.clean();
  9.     if selected == 0 then
  10.         term.setCursorPos(lapi.getCenter("x",6),lapi.getCenter("y",2));
  11.         write("> Sign Up <"); else
  12.         term.setCursorPos(lapi.getCenter("x",4),lapi.getCenter("y",2));
  13.         write("Sign Up");
  14.     end
  15.    
  16.     if selected == 1 then
  17.         term.setCursorPos(lapi.getCenter("x",6),lapi.getCenter("y",-2));
  18.         write("> Sign In <"); else
  19.         term.setCursorPos(lapi.getCenter("x",4),lapi.getCenter("y",-2));
  20.         write("Sign In");
  21.     end
  22.    
  23.     local event, key = os.pullEvent( "key" )
  24.    
  25.     if key == keys.up or key == keys.w or key == keys.left then
  26.         if selected == 0 then selected = 1 else selected = 0 end
  27.     elseif key == keys.down or key == keys.s or key == keys.right then
  28.         if selected == 1 then selected = 0 else selected = 1 end
  29.     elseif key == keys.t or key == keys.leftCtrl then
  30.         os.reboot();
  31.     elseif key == keys.tab then
  32.         break;
  33.     elseif key == keys.enter then
  34.    
  35.         if selected == 0 then
  36.        
  37.        
  38.             newUser = {};
  39.             lapi.clean(lapi.getCenter("x",9),lapi.getCenter("y"));
  40.             textutils.slowWrite("Enter a Username:",150);
  41.             term.setCursorPos(lapi.getCenter("x",9),lapi.getCenter("y",-1));
  42.             local newUsername = io.read();
  43.            
  44.             lapi.clean(lapi.getCenter("x",5),lapi.getCenter("y"));
  45.             textutils.slowWrite("Password:",150);
  46.             term.setCursorPos(lapi.getCenter("x",5),lapi.getCenter("y",-1));
  47.             local newPassword = read("*");
  48.            
  49.             lapi.clean(lapi.getCenter("x",9),lapi.getCenter("y"));
  50.             textutils.slowWrite("Confirm Password:",150);
  51.             term.setCursorPos(lapi.getCenter("x",9),lapi.getCenter("y",-1));
  52.             local confirmNewPassword = read("*");
  53.            
  54.             if newPassword == confirmNewPassword then
  55.                 newUser["username"] = newUsername;
  56.                 newUser["password"] = newPassword;
  57.                 lapi.save(newUser,"lokiOS/files/user/"..newUsername.."/"..newUsername.."Data");
  58.                 lapi.clean(lapi.getCenter("x",8),lapi.getCenter("y"),colors.white,lapi.clc(colors.green));
  59.                 textutils.slowWrite("User registered.",64);sleep(0.75);
  60.             else
  61.                 lapi.clean(lapi.getCenter("x",9),lapi.getCenter("y"),colors.white,lapi.clc(colors.red));
  62.                 textutils.slowWrite("Passwords not matching.",150);sleep(0.75);
  63.             end
  64.            
  65.            
  66.         elseif selected == 1 then
  67.        
  68.        
  69.             lapi.clean(lapi.getCenter("x",10),lapi.getCenter("y"));
  70.             textutils.slowWrite("Enter your Username:",150);
  71.             term.setCursorPos(lapi.getCenter("x",10),lapi.getCenter("y",-1));
  72.             local usernameIn = io.read();
  73.            
  74.             lapi.clean(lapi.getCenter("x",5),lapi.getCenter("y"));
  75.             textutils.slowWrite("Password:",150);
  76.             term.setCursorPos(lapi.getCenter("x",5),lapi.getCenter("y",-1));
  77.             local passwordIn = read("*");
  78.            
  79.             local user = lapi.load("lokiOS/files/user/"..usernameIn.."/"..usernameIn.."Data");
  80.             if user == 0 then
  81.                 lapi.clean(lapi.getCenter("x",10),lapi.getCenter("y"),colors.white,lapi.clc(colors.blue));
  82.                 textutils.slowWrite("User not registered.",150);sleep(0.75);
  83.             else
  84.                 if user["username"] == usernameIn and user["password"] == passwordIn then
  85.                     lapi.clean(lapi.getCenter("x",15),lapi.getCenter("y"),colors.white,lapi.clc(colors.green));
  86.                     textutils.slowWrite("Correct login. Starting os...",60);sleep(0.75);break;
  87.                 else
  88.                     lapi.clean(lapi.getCenter("x",10),lapi.getCenter("y"),colors.white,lapi.clc(colors.red));
  89.                     textutils.slowWrite("Password incorrect.",150);sleep(0.75);
  90.                 end
  91.             end
  92.         end
  93.        
  94.     end
  95.        
  96. end
  97. lapi.clean(1,1,colors.black,colors.white);
  98.  
  99. shell.run("lokiOS/files/os/main");
Advertisement
Add Comment
Please, Sign In to add comment