Advertisement
FoxWorn3365

Hack OS - Login e Desktop

Dec 4th, 2021 (edited)
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw
  2. term.setCursorPos(1, 1)
  3. term.setBackgroundColor(colors.white)
  4. term.clear()
  5.  
  6. -- Hack OS - v0.19
  7. -- By FoxWorn3365
  8.  
  9.  
  10. -- APPUNTI
  11. -- Configurazioni sistema: .localConf
  12. -- Configurazioni pubbliche: .publicConf
  13. -- Immagini: /Hack/images/
  14. -- APP: /Hack/programmi/
  15. -- App di esempio:
  16. --   Directory: /Hack/programmi/fileManager/
  17. --   Icona: /Hack/programmi/fileManager/app.ico
  18. --   File da eseguire: /Hack/programmi/fileManager/exec.luaDir
  19. --   Configurazioni (facoltativo) (OBBLIGO AUTOGENERAZIONE): /Hack/programmi/fileManager/conf.public
  20. --   Nome dell'APP (massimo 4 caratteri): /Hack/programmi/fileManager/app.name
  21. --   API: https://fcosma.it/hackos/api
  22.  
  23. maxw, maxh = term.getSize()
  24. local function drawPixelInternal(xPos, yPos)
  25.     term.setCursorPos(xPos, yPos)
  26.     term.write(" ")
  27. end
  28.  
  29. local tColourLookup = {}
  30. for n = 1, 16 do
  31.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  32. end
  33.  
  34. function drawFilledBox(startX, startY, endX, endY, nColour)
  35.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  36.         "number" or type(endY) ~= "number" or
  37.         (nColour ~= nil and type(nColour) ~= "number") then
  38.         error("Expected startX, startY, endX, endY, colour", 2)
  39.     end
  40.  
  41.     startX = math.floor(startX)
  42.     startY = math.floor(startY)
  43.     endX = math.floor(endX)
  44.     endY = math.floor(endY)
  45.  
  46.     if nColour then term.setBackgroundColor(nColour) end
  47.     if startX == endX and startY == endY then
  48.         drawPixelInternal(startX, startY)
  49.         return
  50.     end
  51.  
  52.     local minX = math.min(startX, endX)
  53.     if minX == startX then
  54.         minY = startY
  55.         maxX = endX
  56.         maxY = endY
  57.     else
  58.         minY = endY
  59.         maxX = startX
  60.         maxY = startY
  61.     end
  62.  
  63.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  64. end
  65.  
  66. function  giremu(inputstr, sep)
  67.         local t={}
  68.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  69.                 table.insert(t, str)
  70.         end
  71.         return t
  72. end
  73.  
  74. function clear()
  75.     sfondo(colors.black)
  76.     term.clear()
  77.     term.setCursorPos(1, 1)
  78. end
  79.  
  80. function clearRed()
  81.     sfondo(colors.red)
  82.     term.clear()
  83.     term.setCursorPos(1, 1)
  84. end
  85.  
  86. function titolo(testo)
  87.     drawFilledBox(1, 1, maxw, 1, colors.orange)
  88.     term.setCursorPos((maxw - #testo) / 2, 1)
  89.     term.setTextColor(colors.white)
  90.     term.write(testo)
  91. end
  92.  
  93. function alarm(testo, colore, y)
  94.     drawFilledBox(1, y, maxw, y, colors[colore])
  95.     term.setCursorPos((maxw - #testo) / 2, y)
  96.     term.setTextColor(colors.white)
  97.     term.write(testo)
  98.     no()
  99. end
  100.  
  101.  
  102. function bottone(color, text, x, y)
  103.    term.setBackgroundColor(colors[color])
  104.    term.setTextColor(colors.white)
  105.    term.setCursorPos(x, y)
  106.    print(text)
  107. end
  108.  
  109. function drawA()
  110.    term.setBackgroundColor(colors.white)
  111.    term.setTextColor(colors.black)
  112. end
  113.  
  114. function programExec(programDir, type)
  115.     if type == "default_program_app" then
  116.        -- Apro il programma in modo default, eseguendolo
  117.        -- Consigliato solo con le app ufficiali
  118.        don = "execProgram"
  119.        program = programDir
  120.      elseif type == "external_program_app" then
  121.        shell.run(programDir.."/exec.luaDir")
  122.      end
  123. end
  124.  
  125. function loadDesktopBackground()
  126.     if fs.exists("/.bkgConf") == true then
  127.         local h = fs.open("/.bkgConf", "r")
  128.         local backImage = h.readAll()
  129.         h.close()
  130.         drawA()
  131.         term.clear()
  132.         local image = paintutils.loadImage("/Hack/files/"..backImage)
  133.         paintutils.drawImage(image, 1, 2)
  134.     elseif fs.exists("/.bkgColor") == true then
  135.         local h = fs.open("/.bkgColor", "r")
  136.         local backColor = h.readAll()
  137.         h.close()
  138.         term.setBackgroundColor(colors[backColor])
  139.         term.setTextColor(colors.black)
  140.         term.clear()
  141.     else
  142.         term.setBackgroundColor(colors.white)
  143.         term.setTextColor(colors.black)
  144.         term.clear()    
  145.     end
  146. end
  147.  
  148. if fs.exists(".localConf") == false then
  149.   titolo("Hack OS - Installazione")
  150.   term.setBackgroundColor(colors.white)
  151.   term.setTextColor(colors.black)
  152.   print("\n\nInserisci il tuo nome:")
  153.   name = read()
  154.   dir = "hackPC_VERIFIED"
  155.   print("\nInserisci la password (vuoto per non usarla)")
  156.   pass = read()
  157.   term.setTextColor(colors.green)
  158.   local h = fs.open(".localConf", "w")
  159.   if pass == nil or pass == '' then
  160.     h.writeLine(name.."$"..dir)
  161.     shell.run("label set hack_osPC-"..name)
  162.   elseif pass ~= nil and pass ~= '' and name ~= nil and name ~= '' then
  163.     h.writeLine(name.."$"..dir.."$"..pass)
  164.    shell.run("label set hack_osPC-"..name)
  165.   elseif pass == nil or pass == '' and name == nil or name == '' then
  166.     h.writeLine("HackPC$"..dir.."$"..pass)
  167.     shell.run("label set hack_osPC-defaultName")
  168.   end
  169.   h.flush()
  170.   h.close()
  171.   print("\nFatto! Premi un tasto qualsiasi")
  172.   os.pullEvent("key")
  173.   shell.run("reboot")
  174. else
  175.   local h = fs.open(".localConf", "r")
  176.   confInit = h.readAll()
  177.   h.close()
  178.   conf = giremu(confInit, "$")
  179. end
  180.  
  181. don = 0
  182.  
  183. while true do
  184. if don == 0 then
  185. -- Login
  186.  if conf[3] == nil then
  187.   shell.run("desktop")
  188.  else
  189.   drawA()
  190.   term.clear()
  191.   local image = paintutils.loadImage('Hack/sfondo.png')
  192.   paintutils.drawImage(image, 1, 2)
  193.   titolo("Accedi al computer di "..conf[1].."!")
  194.   drawA()
  195.   print("\n\nInserisci la password:")
  196.   local pass = read()
  197.   if pass ~= conf[3] then
  198.     term.setTextColor(colors.red)
  199.     print("\nPassword errata! Potrai riprovare tra 3 secondi..")
  200.     sleep(3)
  201.     drawA()
  202.     term.clear()
  203.     term.setTextColor(colors.black)
  204.     local image = paintutils.loadImage('Hack/sfondo.png')
  205.     paintutils.drawImage(image, 1, 2)
  206.     titolo("Accedi al computer di "..conf[1])
  207.     drawA()
  208.     print("\n\nInserisci la password:")
  209.     local pass = read()
  210.     if pass ~= conf[3] then
  211.        term.setTextColor(colors.red)
  212.        print("Password errata!\nProcedo con il riavvio.\nHo salvato nel LOG l'errore di accesso!")
  213.        sleep(4)
  214.        shell.run("reboot")
  215.     else
  216.        don = 1
  217.     end
  218.   else
  219.     don = 1
  220.   end
  221.  end
  222. elseif don == 1 then
  223.   loadDesktopBackground()
  224.   appList = {}
  225.   app = 1
  226.   titolo("Computer di "..conf[1].."  -  /Hack/Desktop")
  227.   term.setCursorPos(1, 3)
  228.   oldX = 0
  229.   oldY = 0
  230.   y = 3
  231.   for i, k in pairs(fs.list("/Hack/programmi/")) do
  232.     if fs.isDir("/Hack/programmi/"..k) == true then
  233.         x = 2 + oldX
  234.       term.setCursorPos(x, y)
  235.       ico = paintutils.loadImage("/Hack/programmi/"..k.."/app.ico")
  236.       local h = fs.open("/Hack/programmi/"..k.."/app.name", "r")
  237.       aName = h.readAll()
  238.       h.close()
  239.       paintutils.drawImage(ico, x, y)
  240.       oldX, oldY = term.getCursorPos()
  241.       term.setCursorPos(oldX-4, y+3)
  242.       drawA()
  243.       term.write(aName)
  244.       term.setCursorPos(oldX, oldY)
  245.       for i=x, x+3 do
  246.         for b=y, y+3 do
  247.           appList[tostring(i).." "..tostring(b)] = k
  248.         end
  249.       end
  250.       x = x + 4
  251.       if x >= 47 then
  252.          x = 0
  253.          oldX = 0
  254.          y = y+5
  255.       end
  256.     end
  257.   end
  258.   local event, key, x, y = os.pullEvent("mouse_click")
  259.   if appList[tostring(x).." "..tostring(y)] ~= nil and appList[tostring(x).." "..tostring(y)] ~= '' then
  260.      shell.run("/Hack/programmi/"..appList[tostring(x).." "..tostring(y)].."/exec.luaDir")
  261.   end
  262. end
  263. sleep(1)
  264. end
  265.  
  266.    
  267.  
  268.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement