Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oside=""
- local pass=""
- local config="config"
- local sides={"front","back","left","right","top","bottom"}
- local info={}
- local default_state=nil
- local delay=0
- local event={}
- local event2={}
- local state=nil
- term.clear()
- term.setCursorPos(1,1)
- local function lockout()
- os.pullEvent=os.pullEventRaw
- print("hacking attempt detected!")
- print("deadlocked for 30 seconds")
- for i=30,0,-1 do
- sleep(1)
- print(tostring(i).."...")
- end
- print("unlocking..")
- sleep(3)
- for i,side in ipairs(sides) do
- disk.eject(side)
- end
- end
- local function setstr(file,input) --writes to file from a var
- local f=fs.open(file,"a")
- f.writeLine(input)
- f.close()
- end
- local function mkfile(file) --creates a new file, deletes original first
- shell.run("delete "..file)
- local f=fs.open(file,"w")
- f.close()
- end
- local function sidevalid(str) --checks a string to ensure that a correct side name was used
- for i2 = 1, 6 do
- if str:lower() == sides[i2] then return true end
- end
- return false
- end
- local function sideerror() --self explanatory
- print([[side entered incorrect, sides can only be:
- top,bottom,left,right,front or back
- please enter the correct side]])
- end
- local function conf()
- mkfile(config)
- print("please enter a name for this lock")
- local name=read()
- shell.run("label set "..name)
- print("enter redstone output side for this lock")
- local rside=read()
- if not sidevalid(rside) then
- repeat
- sideerror()
- rside = read()
- until sidevalid(rside)
- setstr(config,rside)
- elseif sidevalid(rside) then
- setstr(config,rside)
- end
- print("by default, 1:true or 2:false? press desired number")
- local event
- repeat event = {os.pullEvent()} until event[1] == "key" and event[2] > 1 and event[2] < 4
- setstr(config, event[2] == 2)
- sleep(1)
- print("press space to enter password")
- print("or simply insert preconfigured passkey into disc slot")
- event2= {os.pullEvent()}
- if event2[1]=="key" and event2[2]==57 then
- print("password entry: please enter your password")
- local pass=read("*")
- elseif event2[1]=="disk" then
- if disk.hasData(event2[2]) then
- sFile = "disk/pass"
- hRead = assert(fs.open(sFile,"r"))
- sPass = hRead.readLine()
- hRead.close()
- setstr(config,sPass)
- disk.eject(event2[2])
- os.reboot()
- end
- end
- end
- local function getvars(file) --// Localize the function too, define it before we use it in 'startup' function
- local f = fs.open(file,"r")
- for i = 1,10 do
- info[i] = f.readLine()
- end
- f.close()
- end
- local function startup()
- getvars(config)
- pass=info[3]
- rside=info[1]
- default_state=info[2]
- end
- local function state_invert()
- if default_state then return false
- else return true
- end
- end
- local function state_check()
- if default_state=="true" then
- default_state=true
- return true
- else
- default_state=false
- return false
- end
- end
- if not fs.exists(config) then
- conf()
- else
- startup()
- end
- rs.setOutput(rside,state_check())
- while true do
- event = {os.pullEvent()}
- if event[1]=="disk" then
- if disk.hasData(event[2]) then
- sFile = "disk/pass"
- hRead = assert(fs.open(sFile,"r"))
- sPass = hRead.readLine()
- hRead.close()
- if sPass == pass then
- rs.setOutput(rside,state_invert())
- disk.eject(event[2])
- sleep(3)
- os.reboot()
- else
- disk.eject(event[2])
- os.reboot()
- end
- else
- disk.eject(event[2])
- os.reboot()
- end
- end
- if event[1]=="key" then
- if event[2]==29 or event[2]==157 then
- lockout()
- os.reboot()
- elseif event[2]==22 then
- print("lock Killer initiated, press 1 to confirm or 2 to reboot")
- event={os.pullEvent("key")}
- if event[2]==2 then
- print("Killing Lock..")
- sleep(1)
- shell.run("label set Broken Lock")
- shell.run("delete startup")
- shell.run("delete config")
- os.reboot()
- elseif event[2]==3 then
- os.reboot()
- elseif event[2]==29 or event[2]==157 then
- lockout()
- os.reboot()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment