Advertisement
Guest User

diskLogin

a guest
Jan 28th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. m = peripheral.wrap("right")
  2. diskSide = "back"
  3.  
  4.  
  5. local username = ""
  6. local chunks = 0
  7. local ID = ""
  8. local password = {}
  9.  
  10. local s = m.setCursorPos
  11. local b = m.setBackgroundColor
  12.  
  13. local login_text = "Take the Card"
  14.  
  15. local waittime = 0.1
  16.  
  17. local drawed = false
  18.  
  19.  
  20. function openDisk()
  21.  
  22.   local exists = fs.exists("/disk/username")
  23.   local exists2 = fs.exists("/disk/chunks")
  24.   local exists3 = fs.exists("/disk/chunkID")
  25.  
  26.   if exists and exists2 and exists3 then
  27.     local file = fs.open( "/disk/username", "r" )
  28.     username = file.readLine()
  29.     file.close()
  30.  
  31.     local file = fs.open( "/disk/chunks", "r" )
  32.     chunks = file.readLine()
  33.     chunks = tonumber(chunks)
  34.     file.close()
  35.  
  36.     local file = fs.open( "/disk/chunkID", "r" )
  37.     ID = file.readLine()
  38.     file.close()
  39.  
  40.     for i = 1, chunks do
  41.       local file = fs.open( "/disk/"..ID.."_"..tostring(i), "r")
  42.       password[i] = file.readLine()
  43.       file.close()
  44.     end
  45.  
  46.     --m.clear()
  47.     --m.setCursorPos(1,1)
  48.     --m.write(username)
  49.     --s(1,2)
  50.     --m.write(chunks)
  51.     --s(1,3)
  52.     --m.write(ID)
  53.     --s(1,1)
  54.    
  55.     local truePSW = ""
  56.     for i = 1, chunks do
  57.       truePSW = truePSW..password[i]
  58.     end
  59.     return truePSW
  60.   else
  61.     return false
  62.   end
  63.  
  64. end
  65.  
  66. function drawT()
  67.   m.setBackgroundColor(colors.white)
  68.   s(2,3)
  69.   local len = login_text:len()
  70.   for i = 1, len+2 do
  71.     s(1+i,2)
  72.     m.write(" ")
  73.     s(1+i, 3)
  74.     m.write(" ")
  75.     s(1+i, 4)
  76.     m.write(" ")
  77.   end
  78.  
  79.  
  80.   s(3, 3)
  81.   m.setTextColor(colors.black)
  82.   m.write( login_text )
  83. end
  84.  
  85. function menu(loaded)
  86.   plusY = 21
  87.  
  88.   m.setBackgroundColor(colors.black)
  89.  
  90.   m.clear()
  91.  
  92.   s(2+plusY,2)
  93.  
  94.   m.setTextColor(colors.lime)
  95.  
  96.   local file = fs.exists("/disk/username")
  97.   local second = fs.exists("/disk")
  98.  
  99.   loaded = loaded + 1
  100.   if loaded > 8 then
  101.     loaded = 8
  102.   end
  103.  
  104.   if file then
  105.     --drawDisk(plusY, loaded) -- Draw the disk
  106.     if loaded == 8 then
  107.    
  108.       local v = openDisk()
  109.       error(username.."  "..v)
  110.  
  111.      
  112.       -- Touch
  113.      
  114.       --local event, side, xP, yP = os.pullEvent("monitor_touch")
  115.  
  116.      
  117.      
  118.     else
  119.       s(3,3)
  120.       b(colors.black)
  121.       m.write("Loading Disk")
  122.       drawed = false
  123.     end
  124.   else
  125.     drawDisk(plusY, 0)
  126.     s(3,3)
  127.     b(colors.black)
  128.     if second then
  129.       m.write("Invalid Disk")
  130.     else
  131.       m.write("Insert Disk")
  132.     end
  133.     loaded = 0
  134.   end
  135.  
  136.   sleep(waittime)
  137.   menu(loaded)
  138. end
  139.  
  140. function drawDisk(plus, loaded)
  141.   for i = 1, 8 do
  142.     if i <= loaded then
  143.       b(colors.white)
  144.     else
  145.       b(colors.gray)
  146.     end
  147.     s(3+plus, 1+i)
  148.     if i == 1 then
  149.       m.write("          ")
  150.     else
  151.       m.write("           ")
  152.     end
  153.   end
  154. end
  155.  
  156. menu(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement