AnotherTekkituser

cc password disk door

Oct 20th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. local oside=""
  2. local pass=""
  3. local config="config"
  4. local sides={"front","back","left","right","top","bottom"}
  5. local info={}
  6. local default_state=nil
  7. local delay=0
  8. local event={}
  9. local event2={}
  10. local state=nil
  11. term.clear()
  12. term.setCursorPos(1,1)
  13.  
  14. local function lockout()
  15.     os.pullEvent=os.pullEventRaw
  16.     print("hacking attempt detected!")
  17.     print("deadlocked for 30 seconds")
  18.     for i=30,0,-1 do
  19.         sleep(1)
  20.         print(tostring(i).."...")
  21.     end
  22.     print("unlocking..")
  23.     sleep(3)
  24.     for i,side in ipairs(sides) do
  25.         disk.eject(side)
  26.     end
  27. end
  28.  
  29. local function setstr(file,input) --writes to file from a var
  30.     local f=fs.open(file,"a")
  31.     f.writeLine(input)
  32.     f.close()
  33. end
  34.  
  35. local function mkfile(file) --creates a new file, deletes original first
  36.     shell.run("delete "..file)
  37.     local f=fs.open(file,"w")
  38.     f.close()
  39. end
  40.  
  41. local function sidevalid(str) --checks a string to ensure that a correct side name was used
  42.         for i2 = 1, 6 do
  43.             if str:lower() == sides[i2] then return true end
  44.         end
  45.  
  46.         return false
  47. end
  48.  
  49. local function sideerror() --self explanatory
  50.     print([[side entered incorrect, sides can only be:
  51.     top,bottom,left,right,front or back
  52.     please enter the correct side]])
  53. end
  54.  
  55. local function conf()
  56.     mkfile(config)
  57.     print("please enter a name for this lock")
  58.     local name=read()
  59.     shell.run("label set "..name)
  60.     print("enter redstone output side for this lock")
  61.     local rside=read()
  62.     if not sidevalid(rside) then
  63.         repeat
  64.             sideerror()
  65.             rside = read()
  66.         until sidevalid(rside)
  67.         setstr(config,rside)
  68.     elseif sidevalid(rside) then
  69.         setstr(config,rside)
  70.     end
  71.     print("by default, 1:true or 2:false? press desired number")
  72.     local event
  73.     repeat event = {os.pullEvent()} until event[1] == "key" and event[2] > 1 and event[2] < 4
  74.     setstr(config, event[2] == 2)
  75.     sleep(1)
  76.     print("press space to enter password")
  77.     print("or simply insert preconfigured passkey into disc slot")
  78.     event2= {os.pullEvent()}
  79.     if event2[1]=="key" and event2[2]==57 then
  80.         print("password entry: please enter your password")
  81.         local pass=read("*")
  82.     elseif event2[1]=="disk" then
  83.         if disk.hasData(event2[2]) then
  84.             sFile = "disk/pass"
  85.             hRead = assert(fs.open(sFile,"r"))
  86.             sPass = hRead.readLine()
  87.             hRead.close()
  88.             setstr(config,sPass)       
  89.             disk.eject(event2[2])
  90.             os.reboot()
  91.         end
  92.     end
  93. end
  94.        
  95. local function getvars(file) --// Localize the function too, define it before we use it in 'startup' function
  96.     local f = fs.open(file,"r")
  97.     for i = 1,10 do
  98.         info[i] = f.readLine()
  99.     end
  100.     f.close()
  101. end
  102.  
  103. local function startup()
  104.     getvars(config)
  105.     pass=info[3]
  106.     rside=info[1]
  107.     default_state=info[2]
  108. end
  109.  
  110. local function state_invert()
  111.     if default_state then return false
  112.         else return true
  113.     end
  114. end
  115.  
  116. local function state_check()
  117.     if default_state=="true" then
  118.         default_state=true
  119.         return true
  120.     else
  121.         default_state=false
  122.         return false
  123.     end
  124. end
  125.  
  126. if not fs.exists(config) then
  127.     conf()
  128. else
  129.     startup()
  130. end
  131.  
  132. rs.setOutput(rside,state_check())
  133.  
  134. while true do
  135.     event = {os.pullEvent()}
  136.     if event[1]=="disk" then
  137.         if disk.hasData(event[2]) then
  138.             sFile = "disk/pass"
  139.             hRead = assert(fs.open(sFile,"r"))
  140.             sPass = hRead.readLine()
  141.             hRead.close()
  142.             if sPass == pass then
  143.                 rs.setOutput(rside,state_invert())
  144.                 disk.eject(event[2])
  145.                 sleep(3)
  146.                 os.reboot()
  147.             else
  148.                 disk.eject(event[2])
  149.                 os.reboot()
  150.             end
  151.         else
  152.             disk.eject(event[2])
  153.             os.reboot()
  154.         end
  155.     end
  156.     if event[1]=="key" then
  157.         if event[2]==29 or event[2]==157 then
  158.             lockout()
  159.             os.reboot()
  160.         elseif event[2]==22 then
  161.             print("lock Killer initiated, press 1 to confirm or 2 to reboot")
  162.             event={os.pullEvent("key")}
  163.             if event[2]==2 then
  164.                 print("Killing Lock..")
  165.                 sleep(1)
  166.                 shell.run("label set Broken Lock")
  167.                 shell.run("delete startup")
  168.                 shell.run("delete config")
  169.                 os.reboot()
  170.             elseif event[2]==3 then
  171.                 os.reboot()
  172.             elseif event[2]==29 or event[2]==157 then
  173.                 lockout()
  174.                 os.reboot()
  175.             end
  176.         end
  177.     end
  178. end
Advertisement
Add Comment
Please, Sign In to add comment