Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- My Security program i wish to embedd into the door locking program w/counter
- local counter = 0
- if counter == 0 then
- os.pullEvent = os.pullEventRaw
- term.clear()
- term.setCursorPos(1,1)
- print("Crab Computer Security 1.1")
- print("Username: Master Crab")
- write("Password: ")
- function pass()
- t= io.read()
- if t == "Monopoly" then
- print ("Access Granted.")
- sleep(2)
- term.clear()
- term.setCursorPos(1,1)
- else
- print("Incorrect Login Details.")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("Crab Computer Security 1.1")
- print("Username: Master Crab")
- write("Password: ")
- pass()
- end
- end
- pass()
- end --end if
- -- Second door program not written by myself was given to me from a mate who has since left the lua world.
- 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. On:true or Off:false, type true or false")
- state=read()
- if state== "true" then
- state=true
- setstr(config,state)
- elseif state =="false" then
- state=false
- setstr(config,state)
- else repeat
- print("invalid response, please only type true or false!")
- state=read()
- until (state=="true" or "false")
- setstr(config,state)
- end
- 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()
- counter = counter + 1
- 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]
- oside=info[1]
- default_state=info[2]
- end
- local function state_invert()
- return not default_state
- 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(oside,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(oside,state_invert())
- disk.eject(event[2])
- sleep(3)
- os.reboot()
- counter = counter + 1
- else
- disk.eject(event[2])
- os.reboot()
- counter = counter + 1
- end
- else
- disk.eject(event[2])
- os.reboot()
- counter = counter + 1
- end
- end
- if event[1]=="key" then
- if event[2]==29 or event[2]==157 then
- lockout()
- os.reboot()
- counter = counter + 1
- 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()
- counter = counter + 1
- elseif event[2]==3 then
- os.reboot()
- counter = counter + 1
- elseif event[2]==29 or event[2]==157 then
- lockout()
- os.reboot()
- counter = counter + 1
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment