Advertisement
Guest User

makeDisk

a guest
Jan 28th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. local t = term
  2. local c = term.clear
  3. local s = term.setCursorPos
  4. local tc = term.setTextColor
  5. local bc = term.setBackgroundColor
  6. local w = term.write
  7.  
  8. local CID = nil
  9. local PSW = nil
  10. local USR = nil
  11. local CHU = 0
  12.  
  13. local Password = {}
  14.  
  15. local string = ""
  16.  
  17. function makePassword()
  18.     CHU = CHU + 1
  19.  
  20.     c()
  21.     s(1,1)
  22.     tc(colors.green)
  23.     w(CHU..". ")
  24.     tc(colors.blue)
  25.     s(1,2)
  26.     w(": "..string)
  27.     tc(colors.red)
  28.  
  29.     local input = read()
  30.  
  31.     if input == "done" or input == "Done" or input == "DONE" or input == "" or input == " " or input == "  " or input == "   " then
  32.         CHU = CHU - 1
  33.         return true
  34.     else
  35.         string = string..input
  36.         Password[CHU] = input
  37.         makePassword()
  38.     end
  39. end
  40.  
  41. function getInput(x, y, q)
  42.     tc(colors.green)
  43.     s(x,y)
  44.     w(q)
  45.  
  46.     tc(colors.red)
  47.     s(x,y+1)
  48.     w("> ")
  49.     local input = read()
  50.     tc(colors.white)
  51.     return input   
  52. end
  53.  
  54. function generated() -- Just proof :)
  55.     local point = 1
  56.  
  57.     c()
  58.    
  59.     s(1,point)
  60.     tc(colors.green)
  61.     w("Generated a floppy disk with:")
  62.  
  63.     tc(colors.yellow)
  64.     s(1,point+1)
  65.     w("ChunkID: ")
  66.     tc(colors.red)
  67.     w(CID)
  68.  
  69.     tc(colors.yellow)
  70.     s(1,point+2)
  71.     w("ChunkID: ")
  72.     tc(colors.red)
  73.     w(CID)
  74.  
  75.     s(1,point+3)
  76.     tc(colors.yellow)
  77.     w("Username: ")
  78.     tc(colors.red)
  79.     w(USR)
  80.  
  81.     s(1,point+4)
  82.     tc(colors.yellow)
  83.     w("Password: ")
  84.     tc(colors.red)
  85.     w(PSW)
  86.  
  87.     for i = 1, CHU do
  88.         s(1, point+5+i)
  89.         w(i..". "..Password[i])
  90.     end
  91.  
  92.     s(1,point+CHU+6)
  93.  
  94.     local newTable = fs.list("/disk/")
  95.  
  96.     if newTable[1] == nil then
  97.  
  98.         -- chunkID
  99.         newFile = fs.open("/disk/chunkID", "w")
  100.         newFile.writeLine(tostring(CID))
  101.         newFile.close()
  102.  
  103.         -- chunks
  104.         newFile = fs.open("/disk/chunks", "w")
  105.         newFile.writeLine(tostring(CHU))
  106.         newFile.close()
  107.  
  108.         -- username
  109.         newFile = fs.open("/disk/username", "w")
  110.         newFile.writeLine(tostring(USR))
  111.         newFile.close()
  112.  
  113.         -- password
  114.         for i = 1, CHU do
  115.             newFile = fs.open("/disk/"..CID.."_"..i, "w")
  116.             newFile.writeLine(tostring(Password[i]))
  117.             newFile.close()
  118.         end
  119.     else
  120.         c()
  121.         s(1,1)
  122.         w("Falied, there is already files on the Floppy Disk")
  123.     end
  124. end
  125.  
  126. function boot()
  127.  
  128.     c()
  129.     CID = getInput(1, 1, "What should the identifier look like?")
  130.     USR = getInput(1, 3, "What is your username?")
  131.     makePassword()
  132.     PSW = string
  133.     --PSW = getInput(1, 5, "Can you type you password ono for one?")
  134.  
  135.     generated()
  136. end
  137.  
  138. boot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement