This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
cowboycomando54's profile picture

Card locked Security Doors

Started by cowboycomando54, 15 March 2014 - 05:56 PM
cowboycomando54 #1
Posted 15 March 2014 - 06:56 PM
I have a new idea for the use of floppy disks in computer craft. Use floppy disks as key cards for a set of doors linked to a computer and disk drive. I was wondering how this might be possible to do so?
CometWolf #2
Posted 15 March 2014 - 07:09 PM
This has been dozens of times, it's pretty simple.
Whenever a disk is inserted into a connected disk drive, an event is fired.
http://computercraft.info/wiki/Os.pullEvent
When your program catches this event, it can check the files on the disk using the fs api.
http://computercraft.info/wiki/Fs_%28API%29
Using some if statements you can check if a specific file exists, the read the file for some specific content, if the content is correct, open the door.
theoriginalbit #3
Posted 16 March 2014 - 03:30 AM
alternatively if you wish to use something a little more secure than files on a disk you can use the Disk's ID to be the identifier of whether the person is allowed or not.

Actually since its such a simple program here, have a read of this program I just whipped together :)/>

local outputSide = "left" --# the side the redstone will be on to open the door
local openFor = 5 --# time in seconds for the door to be open
local allowedIDs = { --# this is a list of disk IDs that are allowed to open the door
 [1] = true; --# disk id 1 is allowed
 [34] = true; --# disk id 34 is allowed
}

while true do
  local _, side = os.pullEvent("disk") --# wait until a disk is inserted
  if allowedIDs[ disk.getID(side) ] then --# if the ID is in the allowed IDs table
    os.pullEvent("disk_eject") --# wait until they've removed the disk
    rs.setOutput(outputSide, true) --# open the door
    os.startTimer(openFor) --# start our timer
    os.pullEvent("timer") --# wait until the timer has finished
    rs.setOutput(outputSide, false) --# close the door
  end
end

Note: i could have used sleep(openFor) instead of

os.startTimer(openFor)
os.pullEvent("timer")
but that allows people to terminate the program on your computer and then gain access to it, meaning they'd be able to open the door with the computer; well they could probably just use a pickaxe too.