Advertisement
Ewgeniy

Untitled

Oct 28th, 2021
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.92 KB | None | 0 0
  1. local rst,req=pcall(require,'reqlib')
  2. if not rst then print('Please install reqlib to run this application!') os.exit(1) end
  3. local argv={...}
  4. print('RFID/Magnetic Card Checker (RMCC) v1.0 (C) NekoWarius, 2017')
  5. local event=require('event')
  6. local rfid_scan=req(function() return require('component').os_rfidreader end)
  7. local cardwriter=req(function() return require('component').os_cardwriter end)
  8. local magread=req(function() return require('component').os_magreader end)
  9. local setout=req(function() return require('component').redstone.setOutput end)
  10. if magread then magread.setEventName('mag') else print('No Magnetic Card Readers found.') end
  11. if not setout then setout=(function() end) print('No Redstone outputs found, RMCC is in dummy mode.') end
  12.  
  13.  
  14. local cardpass=nil
  15. function dublicate()
  16.     print('Please insert a RFID/Magnetic card to cardwriter.')
  17.     event.pull('cardInsert')
  18.     cardwriter.write(cardpass)
  19.     print('Please remove a RFID/Magnetic card from cardwriter.')
  20.     event.pull('cardRemove')
  21. end
  22. function newkey()
  23.     print('Please insert a RFID/Magnetic card to cardwriter.')
  24.     local passkey=''
  25.     for _=1,64 do passkey=passkey..string.char(math.random(65,90)) end
  26.     event.pull('cardInsert')
  27.     cardwriter.write(passkey)
  28.     print('Your passkey: '..passkey)
  29.     f=io.open('/rfid.txt','w')
  30.     f:write(passkey)
  31.     f:close()
  32.     f=io.open('/rfid.txt','r')
  33.     print('Please remove a RFID/Magnetic card from cardwriter.')
  34.     event.pull('cardRemove')
  35.     cardpass=f:read()
  36. end
  37. if not cardwriter then print('No Card Writers found.') dublicate=(function()  end) newkey=(function()  end) end
  38. function checkfile()
  39.     local f=io.open('/rfid.txt','r')
  40.     if not f and cardwriter~=nil then newkey() end
  41.     if f then cardpass=f:read() end
  42. end
  43. checkfile()
  44.  
  45.  
  46. function redtrigg() for n=1,4 do setout(n,15) end os.sleep(2) for n=1,4 do setout(n,0) end end
  47. function rfidcheck() for i,v in pairs(rfid_scan.scan(5)) do if v.data==cardpass then redtrigg() end end end
  48. function magcheck(a,x,f,data,n,m) if data==cardpass then redtrigg() end end
  49. if magread then event.listen('mag',magcheck) else magcheck=(function() end) end
  50. if not rfid_scan then rfidcheck=(function() end) end
  51.  
  52. local state=false
  53. function chst(addr,ch,chcode,player)
  54.     event.ignore('key_down',chst)
  55.     state=true
  56. end
  57. print()
  58. print('Commands:')
  59. if cardwriter then
  60.     print(' dublicate - programming a new card')
  61.     print(' newkey - generate new key')
  62. end
  63. print(' showkey - show generated key')
  64. print(' quit - quit from RMCC')
  65. print()
  66. event.listen('key_down',chst)
  67. while true do
  68.     if state then
  69.         io.write('> ')
  70.         local inp=io.read()
  71.         if inp=='dublicate' then dublicate()
  72.         elseif inp=='newkey' then newkey()
  73.         elseif inp=='showkey' then print('Key: '..cardpass)
  74.         elseif inp=='quit' then
  75.             event.ignore('mag',magcheck)
  76.             event.ignore('key_down',chst)
  77.             break
  78.         else
  79.             print('Unknown command.')
  80.         end
  81.         event.listen('key_down',chst)
  82.         state=false
  83.     else
  84.         rfidcheck()
  85.         os.sleep(0.5)
  86.     end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement