Advertisement
rithrin

check

Oct 3rd, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. -- Config
  2. local iLevel = 5 -- Securitylevel of this station
  3. local iLevelLength = 6 -- length of a security level key
  4. local sRsOutput = "bottom" -- Redstone output for the door
  5. local iOpenTime = 3 -- amount of seconds the door should be open when opened from within
  6. -- End of config
  7.  
  8. term.clear()
  9. term.setCursorPos(1,1)
  10. local hMKey = fs.open("masterkey", "r")
  11. local sMKey = hMKey.readAll()
  12. local sLevelMasterKey = string.sub(sMKey, iLevel*iLevelLength, (iLevel*iLevelLength) + iLevelLength)
  13. local iCurrentOpenTime = 0
  14.  
  15. local bDebug = true
  16. local tTID = os.startTimer(1)
  17.  
  18. hMKey.close()
  19.  
  20. function clear()
  21. term.clear()
  22. term.setCursorPos(1,1)
  23. print("Press enter to open the door")
  24. print(sLevelMasterKey)
  25. end
  26.  
  27. clear()
  28. while (true) do
  29. local eEvent, cParam1, cParam2 = os.pullEvent ()
  30. clear()
  31.  
  32. if (bDebug) then
  33. print("---")
  34. print(tTID)
  35. print("---")
  36. print("event=" .. eEvent)
  37. if (cParam1 ~= nil) then
  38. print("par1=" .. cParam1)
  39. end
  40. print("---")
  41. print("openTime=" .. iCurrentOpenTime)
  42. print("---")
  43. end
  44.  
  45. if eEvent == "key" then
  46. rs.setOutput(sRsOutput, true)
  47. sleep(iOpenTime)
  48. rs.setOutput(sRsOutput, false)
  49. tTID = os.startTimer(1)
  50. else
  51. tTID = os.startTimer(1)
  52. end
  53. if (fs.exists("disk/key")) then
  54. hFile = fs.open("disk/key", "r")
  55. sKey = hFile.readAll()
  56. if (bDebug) then
  57. print("ExpectedKey="..sLevelMasterKey)
  58. print("GivenKey="..sKey)
  59. end
  60. hFile.close()
  61. if (string.len(sKey) >= string.len(sLevelMasterKey)) then
  62. sLevelKey = string.sub(sKey, iLevel*iLevelLength, (iLevel*iLevelLength) + iLevelLength)
  63. if (sLevelKey == sLevelMasterKey) then
  64. iCurrentOpenTime = 1
  65. end
  66. end
  67. end
  68.  
  69. if (iCurrentOpenTime > 0) then
  70. print("Door opened")
  71. rs.setOutput(sRsOutput, true)
  72. else
  73. rs.setOutput(sRsOutput, false)
  74. end
  75. iCurrentOpenTime = iCurrentOpenTime - 1
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement