Posted 19 August 2015 - 01:18 AM
Hey im new to the forums, a mate gave me some code to do with a door locking program and i have been trying to integrate it into my computer security program.
However because the PC reboots it resets the counter i have been trying to implement.
I am completely new to Computer craft and have like 3 days experience, im looking to improve my knowledge and skills, im not overly bad as i have a backgroud in java.
But if i could get some help that would be great here is the code, what i want is everytime you use the door with a passworded disk it opens resets and then you have to login to the pc again to repeat, after the first login i wish it to keep looping through the door opening code.
P,s im also having issues with a disk without the passcode breaks the program, any help would be great.
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
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 = 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()
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(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()
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
However because the PC reboots it resets the counter i have been trying to implement.
I am completely new to Computer craft and have like 3 days experience, im looking to improve my knowledge and skills, im not overly bad as i have a backgroud in java.
But if i could get some help that would be great here is the code, what i want is everytime you use the door with a passworded disk it opens resets and then you have to login to the pc again to repeat, after the first login i wish it to keep looping through the door opening code.
P,s im also having issues with a disk without the passcode breaks the program, any help would be great.
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
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 = 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()
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(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()
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