Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local rst,req=pcall(require,'reqlib')
- if not rst then print('Please install reqlib to run this application!') os.exit(1) end
- local argv={...}
- print('RFID/Magnetic Card Checker (RMCC) v1.0 (C) NekoWarius, 2017')
- local event=require('event')
- local rfid_scan=req(function() return require('component').os_rfidreader end)
- local cardwriter=req(function() return require('component').os_cardwriter end)
- local magread=req(function() return require('component').os_magreader end)
- local setout=req(function() return require('component').redstone.setOutput end)
- if magread then magread.setEventName('mag') else print('No Magnetic Card Readers found.') end
- if not setout then setout=(function() end) print('No Redstone outputs found, RMCC is in dummy mode.') end
- local cardpass=nil
- function dublicate()
- print('Please insert a RFID/Magnetic card to cardwriter.')
- event.pull('cardInsert')
- cardwriter.write(cardpass)
- print('Please remove a RFID/Magnetic card from cardwriter.')
- event.pull('cardRemove')
- end
- function newkey()
- print('Please insert a RFID/Magnetic card to cardwriter.')
- local passkey=''
- for _=1,64 do passkey=passkey..string.char(math.random(65,90)) end
- event.pull('cardInsert')
- cardwriter.write(passkey)
- print('Your passkey: '..passkey)
- f=io.open('/rfid.txt','w')
- f:write(passkey)
- f:close()
- f=io.open('/rfid.txt','r')
- print('Please remove a RFID/Magnetic card from cardwriter.')
- event.pull('cardRemove')
- cardpass=f:read()
- end
- if not cardwriter then print('No Card Writers found.') dublicate=(function() end) newkey=(function() end) end
- function checkfile()
- local f=io.open('/rfid.txt','r')
- if not f and cardwriter~=nil then newkey() end
- if f then cardpass=f:read() end
- end
- checkfile()
- function redtrigg() for n=1,4 do setout(n,15) end os.sleep(2) for n=1,4 do setout(n,0) end end
- function rfidcheck() for i,v in pairs(rfid_scan.scan(5)) do if v.data==cardpass then redtrigg() end end end
- function magcheck(a,x,f,data,n,m) if data==cardpass then redtrigg() end end
- if magread then event.listen('mag',magcheck) else magcheck=(function() end) end
- if not rfid_scan then rfidcheck=(function() end) end
- local state=false
- function chst(addr,ch,chcode,player)
- event.ignore('key_down',chst)
- state=true
- end
- print()
- print('Commands:')
- if cardwriter then
- print(' dublicate - programming a new card')
- print(' newkey - generate new key')
- end
- print(' showkey - show generated key')
- print(' quit - quit from RMCC')
- print()
- event.listen('key_down',chst)
- while true do
- if state then
- io.write('> ')
- local inp=io.read()
- if inp=='dublicate' then dublicate()
- elseif inp=='newkey' then newkey()
- elseif inp=='showkey' then print('Key: '..cardpass)
- elseif inp=='quit' then
- event.ignore('mag',magcheck)
- event.ignore('key_down',chst)
- break
- else
- print('Unknown command.')
- end
- event.listen('key_down',chst)
- state=false
- else
- rfidcheck()
- os.sleep(0.5)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement