Advertisement
Guest User

nice

a guest
Mar 17th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.57 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1,1)
  3. print('^')
  4. _1 = 'drive_1'
  5. _2 = 'drive_2'
  6. _3 = 'drive_3'
  7. _4 = 'drive_4'
  8. _5 = 'drive_5'
  9. _6 = 'drive_6'
  10. _7 = 'drive_7'
  11. _8 = 'drive_8'
  12. _9 = 'drive_9'
  13. _10 = 'drive_10'
  14. _11 = 'drive_11'
  15. _12 = 'drive_12'
  16. door_0 = peripheral.wrap('drive_0')
  17. door_1 = peripheral.wrap('drive_13')
  18. door_2 = peripheral.wrap('drive_15')
  19. m = peripheral.wrap('back')
  20.  
  21. _func = {}
  22. wrap = {}
  23. disks = {
  24.   cdunn = {authentication = 'password',authorization = {'*'}},
  25.   user = {authentication = 'password', authorization = {_1,_2} --[[authorization = {cage #}]]}
  26. }
  27.  
  28.  
  29.  
  30. for i=1,12 do
  31.   wrap['drive_'..i] = peripheral.wrap('drive_'..i)
  32. end
  33.  
  34.  
  35.  
  36. function _func.drive_0()
  37.     commands.exec('setblock 0 4 -6 redstone_block 1 destroy')
  38.     sleep(2)
  39.     commands.exec('setblock 0 4 -6 stone 0 destroy')
  40. end
  41.  
  42. function _func.drive_1()
  43.     commands.exec('setblock 2 3 -27 redstone_block 1 destroy')
  44.     sleep(2)
  45.     commands.exec('setblock 2 3 -27 stained_glass 15 destroy')
  46. end
  47.  
  48. function _func.drive_2()
  49.     commands.exec('setblock -2 3 -27 redstone_block 1 destroy')
  50.     sleep(2)
  51.     commands.exec('setblock -2 3 -27 stained_glass 15 destroy')
  52. end
  53.  
  54. function _func.drive_3()
  55.     commands.exec('setblock 2 3 -37 redstone_block 1 destroy')
  56.     sleep(2)
  57.     commands.exec('setblock 2 3 -37 stained_glass 15 destroy')
  58. end
  59.  
  60. function _func.drive_4()
  61.     commands.exec('setblock -2 3 -37 redstone_block 1 destroy')
  62.     sleep(2)
  63.     commands.exec('setblock -2 3 -37 stained_glass 15 destroy')
  64. end
  65.  
  66. function _func.drive_5()
  67.     commands.exec('setblock 2 3 -47 redstone_block 1 destroy')
  68.     sleep(2)
  69.     commands.exec('setblock 2 3 -47 stained_glass 15 destroy')
  70. end
  71.  
  72. function _func.drive_6()
  73.     commands.exec('setblock -2 3 -47 redstone_block 1 destroy')
  74.     sleep(2)
  75.     commands.exec('setblock -2 3 -47 stained_glass 15 destroy')
  76. end
  77.  
  78. function _func.drive_7()
  79.     commands.exec('setblock 2 3 -54 redstone_block 1 destroy')
  80.     sleep(2)
  81.     commands.exec('setblock 2 3 -54 stained_glass 15 destroy')
  82. end
  83.  
  84. function _func.drive_8()
  85.     commands.exec('setblock -2 3 -54 redstone_block 1 destroy')
  86.     sleep(2)
  87.     commands.exec('setblock -2 3 -54 stained_glass 15 destroy')
  88. end
  89.  
  90. function _func.drive_9()
  91.     commands.exec('setblock 2 3 -64 redstone_block 1 destroy')
  92.     sleep(2)
  93.     commands.exec('setblock 2 3 -64 stained_glass 15 destroy')
  94. end
  95.  
  96. function _func.drive_10()
  97.     commands.exec('setblock -2 3 -64 redstone_block 1 destroy')
  98.     sleep(2)
  99.     commands.exec('setblock -2 3 -64 stained_glass 15 destroy')
  100. end
  101.  
  102. function _func.drive_11()
  103.     commands.exec('setblock 2 3 -72 redstone_block 1 destroy')
  104.     sleep(2)
  105.     commands.exec('setblock 2 3 -72 stained_glass 15 destroy')
  106. end
  107.  
  108. function _func.drive_12()
  109.     commands.exec('setblock -2 3 -72 redstone_block 1 destroy')
  110.     sleep(2)
  111.     commands.exec('setblock -2 3 -72 stained_glass 15 destroy')
  112. end
  113.  
  114. function _func.drive_13()
  115.     commands.exec('setblock 0 4 -14 redstone_block 1 destroy')
  116.     sleep(2)
  117.     commands.exec('setblock 0 4 -14 stone 0 destroy')
  118.     sleep(2)
  119.     commands.exec('setblock 0 4 -18 redstone_block 1 destroy')
  120.     sleep(2)
  121.     commands.exec('setblock 0 4 -18 stone 0 destroy')
  122. end
  123.  
  124. function _func.drive_15()
  125.     commands.exec('setblock 0 4 -18 redstone_block 1 destroy')
  126.     sleep(2)
  127.     commands.exec('setblock 0 4 -18 stone 0 destroy')
  128.     sleep(2)
  129.     commands.exec('setblock 0 4 -14 redstone_block 1 destroy')
  130.     sleep(2)
  131.     commands.exec('setblock 0 4 -14 stone 0 destroy')
  132. end
  133.  
  134. function getLabel(side)
  135.     local user = disk.getLabel(side)
  136.     if user == 'cmdpwnd' then user = 'jacky500' end
  137.     return user
  138. end
  139.  
  140. function run()
  141.     while true do
  142.         local event, side = os.pullEvent()
  143.         if event == 'disk' then
  144.             --Read Access-Disk
  145.             local mount = disk.getMountPath(side)
  146.             print(mount)
  147.             local ok, err = pcall(fs.open(mount..'/dc','r'))
  148.             print(ok)
  149.             if ok then
  150.                 commands.exec('tellraw'..getLabel(side)..'True')
  151.                 local f1 = fs.open(mount..'/dc','r')
  152.                 local contents = textutils.unserialize(f1.readAll())
  153.                 f1.close()
  154.                 --Authenticate
  155.                 if contents.authentication == disks[getLabel(side)].authentication then
  156.                     if disks[getLabel(side)].authorization[1] == '*' then --Global Authorization
  157.                         local f2 = fs.open('log','a')
  158.                         f2.write(getLabel(side)..' @ '..side..' : true\n')
  159.                         print(getLabel(side)..' @ '..side..' : true')
  160.                         f2.close()
  161.                         disk.eject(side) --Return Access-Disk
  162.                         _func[side]() --Execute function to open door
  163.                         run()
  164.                     else --Non-Global Authorization
  165.                         for i=1,#disks[getLabel(side)].authorization do
  166.                             if disks[getLabel(side)].authorization[i] == side then
  167.                                 local f3 = fs.open('log','a')
  168.                                 f3.write(getLabel(side)..' @ '..side..' : true\n')
  169.                                 print(getLabel(side)..' @ '..side..' : true')
  170.                                 f3.close()
  171.                                 disk.eject(side)
  172.                                 _func[side]() --Execute function to open door
  173.                             else
  174.                                 if i == #disks[getLabel(side)].authorization then
  175.                                     local f3 = fs.open('log','a')
  176.                                     f3.write(getLabel(side)..' @ '..side..' : false\n')
  177.                                     print(getLabel(side)..' @ '..side..' : true\n')
  178.                                     f3.close()
  179.                                     disk.eject(side)
  180.                                 end
  181.                             end
  182.                         end
  183.                     end
  184.                 else
  185.                     local f3 = fs.open('log','a')
  186.                     f3.write(getLabel(side)..' @ '..side..' : false\n')
  187.                     print(getLabel(side)..' @ '..side..' : true')
  188.                     f3.close()
  189.                     disk.eject(side)
  190.                     local com = 'tellraw '..getLabel(side)..' "Access Denied: Invalid Key"'
  191.                     print(com)
  192.                     commands.exec(com)
  193.                 end
  194.             else
  195.                 print(err)
  196.                 disk.eject(side)
  197.                 local com = 'tellraw '..getLabel(side)..' "Access Denied: Null Key"'
  198.                 print(com)
  199.                 commands.exec(com)
  200.                
  201.             end
  202.         end
  203.     end
  204. end
  205.  
  206. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement