Advertisement
TheGameBros

Passtor-left

Apr 29th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- by TheGameBros
  2.  
  3.  
  4.  
  5. ----------------------------------
  6. ----- DONT CHANGE UNDER THIS -----
  7. ----------------------------------
  8. os.loadAPI("/debipasstor/api/config")
  9. os.loadAPI("/debipasstor/api/monster010")
  10. os.loadAPI("/debipasstor/api/btn")
  11.  
  12.  
  13.  
  14. local software = "DebiPassTor"
  15. local monitor
  16. local cfg = {}
  17. local button = {}
  18. local input = ""
  19. local myTimer
  20. local xyzTimer
  21. local zyxTimer
  22.  
  23.  
  24.  
  25. function addButtons()
  26.     for name, data in pairs(button) do
  27.         btn.add(name, data["name"], keyType, name, data["x"], data["y"], data["w"], data["h"], data["color"])
  28.     end
  29.  
  30.     btn.screen()
  31. end
  32.  
  33. function load()
  34.     if fs.exists("/debipasstor/save") then
  35.         button = monster010.loadFile("/debipasstor/save", true)
  36.     end
  37.  
  38.     addButtons()
  39. end
  40.  
  41.  
  42.  
  43.  
  44. function StrToNum(str)
  45.     if(str == "one") then
  46.         return 1
  47.     elseif(str == "two") then
  48.         return 2
  49.     elseif(str == "dree") then
  50.         return 3
  51.     elseif(str == "four") then
  52.         return 4
  53.     elseif(str == "five") then
  54.         return 5
  55.     elseif(str == "six") then
  56.         return 6
  57.     elseif(str == "seven") then
  58.         return 7
  59.     elseif(str == "eight") then
  60.         return 8
  61.     elseif(str == "nine") then
  62.         return 9
  63.     elseif(str == "null") then
  64.         return 0
  65.     end
  66. end
  67.  
  68. function keyType(key)
  69.     btn.flash(key)
  70.    
  71.     if(key == "enter") then
  72.         os.cancelTimer(myTimer)
  73.         checkPW()
  74.     else
  75.         input = input..StrToNum(key)
  76.     end
  77.  
  78.     myTimer = os.startTimer(5)
  79. end
  80.  
  81. function checkPW()
  82.     if(input == cfg["password"]) then
  83.          rs.setOutput("left",true)
  84.          pwResult(true)
  85.          input = ""
  86.     else
  87.         pwResult(false)
  88.         input = ""
  89.     end
  90. end
  91.  
  92. function pwResult(success)
  93.     monster010.clearMonitor()
  94.  
  95.     local bgcolor
  96.     local color = colors.white
  97.  
  98.     local data = {
  99.         label = "",
  100.         xmin = 2,
  101.         ymin = 2,
  102.         xmax = 17,
  103.         ymax = 11,
  104.     }
  105.  
  106.     if success == true then
  107.         bgcolor = colors.lime
  108.         data["label"] = "Tor freigegeben"
  109.     else
  110.         bgcolor = colors.red
  111.         data["label"] = "Passwort falsch"
  112.     end
  113.  
  114.     btn.fill(data["label"], bgcolor, color, data)
  115.  
  116.     if success == true then
  117.         xyzTimer = os.startTimer(1)
  118.     else
  119.         rs.setBundledOutput(cfg["redSide"], colors.black)
  120.         zyxTimer = os.startTimer(3)
  121.     end
  122. end
  123.  
  124. function closeTor()
  125.     local bgcolor = colors.lime
  126.     local color = colors.white
  127.  
  128.     local data = {
  129.         label = "",
  130.         xmin = 2,
  131.         ymin = 2,
  132.         xmax = 17,
  133.         ymax = 11,
  134.     }  
  135.  
  136.     btn.fill(data["label"], bgcolor, color, data)
  137.     rs.setOutput("left",false)
  138.  
  139.     zyxTimer = os.startTimer(1)
  140.  
  141.     os.cancelTimer(xyzTimer)
  142. end
  143.  
  144. function launchTimers()
  145.     while true do
  146.         local event, args = os.pullEvent()
  147.  
  148.         if event == "key" and args == 19 then
  149.             os.reboot()
  150.         elseif event == "timer" then
  151.             if args == zyxTimer then
  152.                 rs.setBundledOutput(cfg["redSide"], colors.black)
  153.                 monster010.clearMonitor()
  154.                 addButtons()
  155.  
  156.                 os.cancelTimer(zyxTimer)
  157.             elseif args == xyzTimer then          
  158.                 closeTor()
  159.             elseif args == myTimer then
  160.                 input = ""
  161.                 os.cancelTimer(myTimer)
  162.             end
  163.         end
  164.     end
  165. end
  166.  
  167. config.load("/debipasstor/cfg")
  168. cfg = config.getConfig()
  169.  
  170. monster010.construct(cfg["monSide"], software)
  171. monster010.startUp()
  172. monitor = monster010.getMonitor()
  173. btn.construct(monitor)
  174.  
  175. load()
  176. addButtons()
  177.  
  178. monster010.startUpDone()
  179.  
  180. while true do
  181.     parallel.waitForAny(btn.getClick, launchTimers)
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement