Nekrose483

Door lock with floppy disk keycard (clearner)

May 19th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.98 KB | None | 0 0
  1. password = "secretdoorpassword!"
  2. debug_char = "0"
  3.  
  4. term.clear()
  5.  
  6. function mainLoop()
  7.     while(true) do
  8.         event, driveSide = os.pullEventRaw()
  9.         if(event=="disk" and driveSide) then
  10.             path = disk.getMountPath(driveSide)
  11.             if(path) then
  12.                 path = path.."/secretdoor"
  13.                 file = fs.exists(path) and io.open(path, "r") or nil
  14.             end
  15.             disk.eject(driveSide)
  16.             if(file and file:read()==password) then
  17.                 rs.setOutput("left", true)
  18.                 sleep(3)
  19.                 rs.setOutput("left", false)         end
  20.             if(file) then file:close() file = nil end
  21.             elseif(debug_char and event=="char" and driveSide==debug_char) then return("break") end
  22.         end
  23.     end
  24.  
  25.     rs.setOutput("top", true)
  26.         rs.setOutput("back", true)
  27.     sfile = io.open("/startup", "w")
  28.     sfile:write('shell.run("password­")')
  29.     sfile:close()
  30.  
  31.     repeat
  32.         ok, err, val = pcall(mainLoop)
  33.         if(not ok and err) then
  34.             if(err=="Terminated") then print ("Access denied.")
  35.             else
  36.                 print(err)
  37.             end
  38.         end
  39.     until(ok and err=="break")
Add Comment
Please, Sign In to add comment