lego11

Badge porta

Jul 5th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- (c) LEGO11
  2.  
  3. --CONFIGURAZIONE
  4.  
  5. --Inserire qui il titolo che appare sopra Inserire la carta
  6. print("Sistema badge")
  7.  
  8. --Inserire qui i nomi che possono aprire la porta
  9. nome1 = "lego11"
  10. -- nome2 = ""
  11. -- nome3 = ""
  12. -- nome4 = ""
  13.  
  14. --Inserire qui il lato dove la redstone viene attivata per aprire la porta
  15. latoRS = "back"
  16.  
  17. --Inserire qui il lato del lettore magnetico
  18.  
  19. latoLettore = "bottom"
  20.  
  21. --Inserire qui il tempo per cui la porta rimane aperta dopo aver inserito la carta
  22.  
  23. tempoApertura = 5
  24.  
  25. --FINE CONFIGURAZIONE
  26.  
  27.  
  28. local tabr = {}
  29. local contanti = 0
  30. local conteggio = 0
  31.  
  32. function clear()
  33. term.clear()
  34. term.setCursorPos(1,1)
  35. end
  36.  
  37. function pinErrato()
  38. clear()
  39. print("Errore di verifica del PIN")
  40. print("")
  41. print("Premere un tasto per uscire")
  42. os.pullEvent("key")
  43. os.reboot()
  44. end
  45.  
  46.  
  47. function cartaNonValida()
  48. clear()
  49. print("Carta non valida o corrotta.")
  50. print("")
  51. print("Premere un tasto per uscire")
  52. os.pullEvent("key")
  53. os.reboot()
  54. end
  55.  
  56. function cartaVuota()
  57. clear()
  58. print("Carta smagnetizzata.")
  59. print("")
  60. print("Premere un tasto per uscire")
  61. os.pullEvent("key")
  62. os.reboot()
  63. end
  64.  
  65. function nomeNonAutorizzato()
  66. clear()
  67. print("Utente non autorizzato.")
  68. print("")
  69. print("Premere un tasto per uscire")
  70. os.pullEvent("key")
  71. os.reboot()
  72. end
  73.  
  74. m = peripheral.wrap(latoLettore)
  75.  
  76. clear()
  77. print(titolo)
  78. print("")
  79. print("Inserire la carta")
  80. m.setInsertCardLight(true)
  81. za,rawcarta = os.pullEvent("mag_swipe")
  82. m.setInsertCardLight(false)
  83.  
  84. if rawcarta == nil then
  85. cartaVuota()
  86. end
  87.  
  88. tab = textutils.unserialize(rawcarta)
  89.  
  90. if type(tab) ~= "table" then
  91. cartaNonValida()
  92. end
  93.  
  94. if tab.t ~= "BA" then
  95. cartaNonValida()
  96. end
  97.  
  98. if tab.e ~= "NA" then
  99. cartaNonValida()
  100. end
  101.  
  102. if tab.n ~= nome1 or tab.n ~= nome2 or tab.n ~= nome3 then
  103. nomeNonAutorizzato()
  104. end
  105.  
  106. if tab.p ~= "0000" then
  107. print("")
  108. print("Inserire il PIN e premere ENTER")
  109. print("")
  110. local pinUtente = read("#")
  111. if pinUtente ~= tab.p then
  112. pinErrato()
  113. end
  114. end
  115. rs.setOutput(latoRS, true)
  116. sleep(tempoApertura)
  117. rs.setOutput(latoRS, false)
  118. sleep(1)
  119. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment