Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args={...}
- local sep="|"
- local serv_id=167
- rednet.open("top")
- reader = peripheral.wrap("back")
- rfid=peripheral.wrap("left")
- writer=peripheral.wrap("right")
- function on() rs.setOutput("bottom",true) end
- function off() rs.setOutput("bottom",false) end
- if args[1]=="writemag" then -- name,daat
- local s=table.concat({unpack(args,3)}," "):sub(1,79)
- reader.beginWrite(args[2]:sub(1,20)..sep..s,args[2].."'s ID card")
- rednet.send(serv_id,"CARD|ADD|"..args[2]:sub(1,20)..sep..s.."|")
- print("Swipe a blank card!")
- os.pullEvent("mag_write_done")
- elseif args[1]=="writerfid" then
- local s=table.concat({unpack(args,3)}," "):sub(1,79)
- writer.encode(args[2]:sub(1,20)..sep..s,args[2].."'s ID card")
- print("Writing..")
- rednet.send(serv_id,"CARD|ADD|"..args[2]:sub(1,20)..sep..s..sep)
- os.pullEvent("rfid_written")
- else
- while true do
- reader.setInsertCardLight(true)
- local e,data=os.pullEvent()
- if e=="char" or e=="key" then
- on()
- os.sleep(3)
- off()
- elseif e=="mag_swipe" then
- reader.setInsertCardLight(false)
- data=data..sep
- rednet.send(serv_id,"CARD|CHECK|"..data)
- local id=0
- while id~=serv_id do
- local i,resp=rednet.receive()
- id=i
- data=resp
- end
- if data:sub(1,7)=="CARD|OK" then
- print("Authentication sucessful.")
- on()
- os.sleep(1.5)
- off()
- else
- off()
- end
- elseif e=="rfid_detected" then
- data=data..sep
- rednet.send(serv_id,"CARD|CHECK|"..data)
- local id=0
- while id~=serv_id do
- local i,resp=rednet.receive()
- id=i
- data=resp
- end
- if data:sub(1,7)=="CARD|OK" then
- on()
- valid=true
- else
- if not valid then
- off()
- end
- end
- elseif e=="rfid_scan_done" then if not valid then off() end valid=false
- else print(e,data) end
- rfid.scan(3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment