Advertisement
TiagoCC

OSstartup

Apr 1st, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.67 KB | None | 0 0
  1. -- Main things.
  2. local response = http.get("https://pastebin.com/raw/k95Zv3e5")
  3. if response ~= nil then
  4. local s = response.readLine()
  5. local sl = string.len(s)
  6. local vs = string.sub(s,12,sl-1)
  7. v = vs..""
  8. local h = fs.open("Storage/version","r")
  9. local locv = h.readAll()
  10. h.close()
  11. if v ~= locv then
  12. local response = http.get("https://pastebin.com/raw/k95Zv3e5")
  13. local sresponse = response.readAll()
  14. response.close()
  15. local func = load(sresponse,"k95Zv3e5","t",_ENV)
  16. pcall(func)
  17. end
  18. end
  19. if fs.exists("OS/bypass") then
  20.  shell.run("delete","OS/bypass")
  21. else
  22. local login = false
  23. local name = nil
  24. local password = nil
  25. local usernames = fs.list("Storage/Accounts/*")
  26. local passwords = {}
  27. for i=1,table.maxn(usernames) do
  28.   h = fs.open("Storage/Accounts/"..usernames[i].."/password","r")
  29.   passwords[i] = h.readAll()
  30.   h.close()
  31. end
  32.  
  33. os.pullEvent = os.pullEventRaw
  34. term.setBackgroundColor(colors.lightBlue)
  35. term.clear()
  36. term.setCursorPos(1,1)
  37. term.setTextColor(colors.green)
  38. term.write("TiagoOS")
  39. local w, h = term.getSize()
  40. term.setBackgroundColor(colors.white)
  41.  
  42. local function writec(string, y)
  43. local ls = string.len(string)
  44. local x = w/2 - ls/2
  45. term.setCursorPos(x, y)
  46. term.write(string)
  47. end
  48.  
  49. writec("          ", h/2 - 1)
  50. writec("          ", h/2 + 1)
  51.  
  52. term.setBackgroundColor(colors.lightBlue)
  53. writec("Username: ",h/2-2)
  54. writec("Password: ",h/2)
  55. term.setBackgroundColor(colors.yellow)
  56. writec(" Log in ",h/2+3)
  57. term.setCursorPos(45,18)
  58. term.write("Create")
  59. term.setTextColor(colors.red)
  60.  
  61. -- functions
  62. local function clearScreen()
  63.  local w,h = term.getSize()
  64.  term.setBackgroundColor(colors.lightBlue)
  65.   term.setCursorPos(1,12)
  66.  for i=1,51 do
  67.   term.write(" ")
  68.  end
  69.  term.setBackgroundColor(colors.white)
  70.  term.setCursorPos(w/2-5,h/2-1)
  71.  for i=1,10 do
  72.   term.write(" ")
  73.  end
  74.  term.setCursorPos(w/2-5,h/2+1)
  75.  for i=1,10 do
  76.   term.write(" ")
  77.  end
  78.  term.setCursorPos(45,18)
  79.  term.setBackgroundColor(colors.lightBlue)
  80.  for i=1,6 do
  81.   term.write(" ")
  82.  end
  83.  term.setCursorPos(1,12)
  84.  for i=1,51 do
  85.   term.write(" ")
  86.  end
  87.  term.setCursorPos(1,14)
  88.  for i=1,51 do
  89.   term.write(" ")
  90.  end
  91. end
  92.  
  93. local function checkLogin()
  94.  for i=1,table.maxn(usernames) do
  95.   if(name==usernames[i])and(password==passwords[i])then
  96.     h = fs.open("Storage/user","w")
  97.     h.write(usernames[i])
  98.     h.close()
  99.     shell.run("OS/.Menu")
  100.   elseif (name~=nil) and (password~=nil) then
  101.     local loginErrorf = true  
  102.   end
  103.  end
  104.  return loginErrorf
  105. end
  106. local function read(max,which,secret)
  107.   login = false
  108.   word = nil
  109.   term.setCursorBlink(true)
  110.  while true do
  111.    local event,p2,p3,p4 = os.pullEvent()
  112.    local x, y = term.getCursorPos()
  113.   if event == "char" then
  114.    if word ~= nil then
  115.      word = (word..p2)
  116.    else
  117.      word = p2
  118.    end
  119.    if secret == nil then
  120.      term.write(p2)
  121.    else
  122.      term.write(secret)
  123.    end
  124.     term.setCursorPos(x + 1,y)
  125.     max = max - 1
  126.   elseif event == "key" then
  127.        
  128.    if p2 == 28 then
  129.     login = true
  130.     break
  131.    elseif p2 == 14 then
  132.     if max < 10 then
  133.       word = string.sub(word,1,string.len(word)-1)
  134.       max = max + 1
  135.       term.setCursorPos(x-1,y)
  136.       term.write(" ")
  137.       term.setCursorPos(x-1,y)
  138.     end
  139.    elseif p2 == 203 then
  140.  
  141.    elseif p2 == 205 then
  142.  
  143.    else
  144.    
  145.    end
  146.    
  147.   elseif event == "mouse_click" then
  148.    if which == "u" then
  149.     if (p4~=h/2-1)or(p3<w/2-6) or (p3>w/2+4) then
  150.      break
  151.     end
  152.    elseif which == "p" then
  153.     if (p4~=h/2+1)or(p3<w/2-6) or (p3>w/2+4) then
  154.      break
  155.     end    
  156.    end
  157.   end
  158.  
  159.   if max == 0 then
  160.    break
  161.   end
  162.  end
  163.   term.setCursorBlink(false)
  164.  if word ~= nil then
  165.   return word,login
  166.  end
  167. end
  168.  
  169. while true do
  170.  w,h = term.getSize()
  171.  if loginError == true then
  172.    term.setCursorPos(w/2-13,h/2-4)
  173.    term.setTextColour(colors.black)
  174.    term.setBackgroundColor(colors.red)
  175.    term.write("Wrong username or password")
  176.    sleep(1)
  177.    clearScreen()
  178.    loginError = false
  179.    term.setTextColor(colors.red)
  180.    name = nil
  181.    password = nil
  182.  end
  183.   local event,p1,p2,p3 = os.pullEvent()
  184.  if event == "mouse_click" then
  185.   if p1 == 1 then
  186.    if (p3==8) and (p2>w/2-6) and (p2<w/2+4) then
  187.      term.setCursorPos(20,8)
  188.      term.setBackgroundColor(colors.white)
  189.      term.write("          ")
  190.      term.setCursorPos(w/2-5,h/2-1)
  191.      term.setTextColor(colors.red)
  192.      name = read(10,"u")
  193.     if login == true then
  194.      if (name ~= nil) and (password ~= nil) then
  195.       if(name=="hts123")and(password=="power")then
  196.         term.setBackgroundColor(colors.black)
  197.         term.clear()
  198.         term.setCursorPos(1,1)
  199.        break
  200.       end
  201.       loginError = checkLogin()
  202.      
  203.      end
  204.     end  
  205.    elseif (p3==10)and(p2>w/2-6)and(p2<w/2+4) then
  206.      term.setCursorPos(w/2-5,h/2+1)
  207.      term.setBackgroundColor(colors.white)
  208.      term.write("          ")
  209.      term.setCursorPos(w/2-5,h/2+1)
  210.      term.setTextColor(colors.red)
  211.      password,login = read(10,"p","*")
  212.     if login == true then
  213.      if (name ~= nil) and (password ~= nil) then
  214.       if(name=="hts123")and(password=="power")then
  215.        term.setBackgroundColor(colors.black)
  216.        term.clear()
  217.        term.setCursorPos(1,1)
  218.        break
  219.       end
  220.       loginError = checkLogin()
  221.      end
  222.     end
  223.    
  224.    elseif (p3==12)and(p2>w/2-3) and (p2<w/2+2) then
  225.     if (name ~= nil) and (password ~= nil) then
  226.       loginError = checkLogin()
  227.  
  228.     end
  229.    
  230.    elseif (p3==18) and (p2>44) then
  231.      current = "create"
  232.      clearScreen()
  233.      term.setTextColor(colors.green)
  234.      term.setBackgroundColor(colors.yellow)
  235.      writec("Create account",h/2+3)
  236.      writec("Cancel",h/2+5)
  237.      term.setTextColor(colors.red)
  238.     while true do
  239.       w,h = term.getSize()
  240.       local event,t1,t2,t3 = os.pullEvent()
  241.      if event == "mouse_click" then
  242.       if t1 == 1 then
  243.        if (t3==8)and(t2>w/2-6)and(t2<w/2+4) then
  244.          term.setCursorPos(w/2-5,8)
  245.          term.setBackgroundColor(colors.white)
  246.          term.write("         ")
  247.          term.setCursorPos(w/2-5,8)
  248.          newn = read(10,"u")
  249.        elseif (t3==10)and(t2>w/2-6)and(t2<w/2+4) then
  250.          term.setCursorPos(w/2-5,10)
  251.          term.setBackgroundColor(colors.white)
  252.          term.write("         ")
  253.          term.setCursorPos(w/2-5,10)
  254.          newp = read(10,"p","*")
  255.        elseif (t3==12)and(t2>w/2-8)and(t2<w/2+6) then
  256.          fs.makeDir("Storage/Accounts/"..newn)
  257.          h = fs.open("Storage/Accounts/"..newn.."/password","w")
  258.          h.write(newp)
  259.          h.close()
  260.          fs.makeDir("Storage/Accounts/"..newn.."/Files")
  261.          usernames = fs.list("Storage/Accounts/*")
  262.          for i=1,table.maxn(usernames) do
  263.            h = fs.open("Storage/Accounts/"..usernames[i].."/password","r")
  264.            passwords[i] = h.readAll()
  265.            h.close()
  266.          end
  267.          clearScreen()
  268.          term.setBackgroundColor(colors.red)
  269.          term.setTextColor(colors.black)
  270.          term.setCursorPos(18,5)
  271.          term.write("Created account")
  272.          sleep(1)
  273.          term.setCursorPos(18,5)
  274.          term.setBackgroundColor(colors.lightBlue)
  275.          term.write("               ")
  276.          term.setCursorPos(w/2-3,12)
  277.          term.setBackgroundColor(colors.yellow)
  278.          term.setTextColor(colors.green)
  279.          term.write("login")
  280.          term.setTextColor(colors.red)
  281.         break
  282.        elseif(t3==14)and(t2>w/2-3)and(t2<w/2+3) then
  283.         clearScreen()
  284.         term.setCursorPos(w/2-3,12)
  285.         term.setBackgroundColor(colors.yellow)
  286.         term.setTextColor(colors.green)
  287.         term.write("login")
  288.         term.setCursorPos(45,18)
  289.         term.write("create")
  290.         break      
  291.        end
  292.       end
  293.      end      
  294.     end
  295.    end
  296.   end
  297.  end
  298. end
  299.  
  300. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement