Changed some stuff, added the whole controller script
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
-- LUA SWITCH / CASE
|
||||
|
||||
function switch(t)
|
||||
t.case = function (self,x)
|
||||
local f=self[x] or self.default
|
||||
if f then
|
||||
if type(f)=="function" then
|
||||
f(x,self)
|
||||
else
|
||||
error("case "..tostring(x).." not a function")
|
||||
end
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
--actions = switch {
|
||||
-- ["18873940"] = function()
|
||||
-- print("Door has been opened : " .. user .. " MagReader : " .. address)
|
||||
-- doorCtrl()
|
||||
-- end,
|
||||
-- ["99447582"] = function()
|
||||
-- print("Exiting process : " .. user)
|
||||
-- os.exit()
|
||||
-- end,
|
||||
-- default = function()
|
||||
-- print("Code is not correct : " .. user)
|
||||
-- end,
|
||||
--}
|
||||
|
||||
--actions:case(code)
|
||||
@@ -0,0 +1,37 @@
|
||||
-- FileName --
|
||||
The filename of an instruction sheet must be made up of the magnetic card reader and the suffix ".lua"
|
||||
example : 3bbdd537-f117-4d4a-bc48-6adc766fb243.lua
|
||||
|___________________________________|___|
|
||||
Filename Suffix
|
||||
|
||||
|
||||
-- Content --
|
||||
The content of an instruction sheet is basically an array.
|
||||
This array contains the address of the door controller, and the magstripe card codes that are allowed to go in.
|
||||
|
||||
example :
|
||||
accessArray = {
|
||||
["doorController"] = "91b601d3-19eb-4762-9073-8f2a208accc2", -- This is the address of the controller that the MagCard reader is supposed to work with --
|
||||
["allowed"] = {
|
||||
"18873940", -- Here are the codes of the cards that can use the card reader --
|
||||
"11225543" -- This can be anything, numbers, characters, special characters, it doesnt matter --
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-- How to create a magstripe access card --
|
||||
You need the cardwriter.
|
||||
Then you go to lua input mode, and type in :
|
||||
component.os_cardwriter.write("18873940", "The name of the card you want")
|
||||
done, now you have a keycard that has the code "18873940" on it.
|
||||
|
||||
|
||||
-- Sample --
|
||||
This is a sample that you can use in notepad++ for example, and put your values in, and then copy paste it into your game when you are done.
|
||||
|
||||
accessArray = {
|
||||
["doorController"] = "",
|
||||
["allowed"] = {
|
||||
""
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
-- Mag Keycard Door Controller Program
|
||||
|
||||
event = require("event")
|
||||
|
||||
|
||||
function inTable(tbl, item)
|
||||
for key, value in pairs(tbl) do
|
||||
if value == item then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
||||
function doorCtrl(doorController)
|
||||
door = component.proxy(component.get(doorController))
|
||||
door.toggle()
|
||||
end
|
||||
|
||||
while true do
|
||||
_,address,user,code = event.pull("magData")
|
||||
if code == "99447582" then
|
||||
print("Exiting")
|
||||
door1 = require("component").os_doorcontroller
|
||||
door1.close()
|
||||
os.exit()
|
||||
end
|
||||
require("instructions/" .. address)
|
||||
if inTable(accessArray["allowed"], code) then
|
||||
print("The code is correct")
|
||||
doorCtrl(accessArray["doorController"])
|
||||
else
|
||||
print("The code is incorrect")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
-- Instruction on how to use --
|
||||
Step 0:
|
||||
Make sure that you have the OpenComputers and OpenSecurity mods installed
|
||||
|
||||
Step 1:
|
||||
You copy paste the main.lua script into your OC device
|
||||
|
||||
Step 2:
|
||||
If you havent done this yet, build your MagCard Reader and DoorControllers, and you need an "Analyzer" (5948/0)
|
||||
|
||||
Step 3:
|
||||
Follow the instructions in the "instructions" directory
|
||||
@@ -0,0 +1,31 @@
|
||||
I need to make the cardReader script better, by using multiple doorcontrollers, and magcardreaders
|
||||
|
||||
to do this, i ll need different folders, each with instructions in JSON form
|
||||
the id of the reader, and the id of the controller
|
||||
and a set of codes that work on said reader
|
||||
|
||||
|
||||
|
||||
ab7f5cd3-db83-4232-93f3-8187ede44853 Card Reader next to the computer
|
||||
|
||||
|
||||
|
||||
83d424fd-533a-498c-94b0-57f0d91f7189 Card Reader next to door 1
|
||||
4450c25a-347b-4400-a7ec-848811b8d6ca Door Controller 1
|
||||
entry codes:
|
||||
- 18873940
|
||||
- 11225543
|
||||
|
||||
ace408be-05d5-45c6-b3cf-5d8c9a2a3f24 Reader 2
|
||||
91b601d3-19eb-4762-9073-8f2a208accc2 Door Controller 2
|
||||
entry codes:
|
||||
- 18873940
|
||||
- 15422687
|
||||
- 11225543
|
||||
|
||||
3bbdd537-f117-4d4a-bc48-6adc766fb243 Reader 3
|
||||
bce90c10-c8ba-4151-97a1-056d479caed1 Controller 3
|
||||
entry codes:
|
||||
- 18873940
|
||||
- 15422687
|
||||
- 11225543
|
||||
@@ -1,48 +0,0 @@
|
||||
-- Mag Keycard Door Controller Program
|
||||
|
||||
magReader = require("component").os_magreader
|
||||
door = require("component").os_doorcontroller
|
||||
event = require("event")
|
||||
|
||||
function switch(t)
|
||||
t.case = function (self,x)
|
||||
local f=self[x] or self.default
|
||||
if f then
|
||||
if type(f)=="function" then
|
||||
f(x,self)
|
||||
else
|
||||
error("case "..tostring(x).." not a function")
|
||||
end
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
|
||||
actions = switch {
|
||||
["18873940"] = function()
|
||||
print("Door has been opened : " .. user)
|
||||
doorCtrl()
|
||||
end,
|
||||
["99447582"] = function()
|
||||
print("Exiting process : " .. user)
|
||||
os.exit()
|
||||
end,
|
||||
default = function()
|
||||
print("Code is not correct : " .. user)
|
||||
end,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function doorCtrl()
|
||||
door.open()
|
||||
os.sleep(2)
|
||||
door.close()
|
||||
end
|
||||
|
||||
while true do
|
||||
_,_,user,code = event.pull("magData")
|
||||
actions:case(code)
|
||||
end
|
||||
Reference in New Issue
Block a user