Advertisement
Muzze77

Auftrag[00255] - WritePassword

Sep 4th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. shell.run("clear")
  2. sides = {"top","bottom","left","right","front","back"}
  3. for getPeris = 1, table.maxn(sides), 1 do
  4.     if peripheral.getType(sides[getPeris]) ~= nil then
  5.         if peripheral.getType(sides[getPeris]) == "monitor" then
  6.         mon =  peripheral.wrap(sides[getPeris])
  7.         end
  8.         end
  9. end
  10. mon.setTextScale(1)
  11. mon.clear()
  12.  
  13.  
  14. if fs.exists("config") == false then
  15.     print("Password eingeben")
  16.     pw = io.read()
  17.     pw = string.lower(pw)
  18.     sFile = fs.open("config","w")
  19.     sFile.writeLine(pw)
  20.     sFile.close()
  21. else
  22.     rFile = fs.open("config","r")
  23.     pw = rFile.readLine(1)
  24.     rFile.close()
  25. end
  26.  
  27.  
  28.  
  29.  
  30. function writeLetters()
  31. click = {}
  32. lx = 2
  33. ly = 4
  34.  
  35.     for v = 97, 122,1 do
  36.     table.insert(click,{["Letter"] = string.char(v),["X"] = lx,["Y"] = ly})
  37.     lx = lx + 1
  38.     end
  39.     table.insert(click,{["Letter"] = "<",["X"] = click[1].X,["Y"] = ly + 1})
  40.     table.insert(click,{["Letter"] = "=",["X"] = click[1].X + 1,["Y"] = ly + 1})
  41. mon.setTextColor(colors.cyan)
  42. for a = 1, #click, 1 do
  43.    
  44.     mon.setCursorPos(click[a].X,click[a].Y)
  45.     mon.write(click[a].Letter)
  46. end
  47. mon.setTextColor(colors.white)
  48. end
  49. fx = 2
  50.  
  51. function send(check)
  52.     if pw == testPass then
  53.         mon.setCursorPos(2,3)
  54.         mon.setTextColor(colors.green)
  55.         mon.write("Password akzeptiert")
  56.         mon.setTextColor(colors.white)
  57.         rs.setOutput("bottom",true)
  58.         sleep(4)
  59.         rs.setOutput("bottom",false)
  60.     else
  61.         mon.setCursorPos(2,3)
  62.         mon.setTextColor(colors.red)
  63.         mon.write("Password falsch")
  64.         mon.setTextColor(colors.white)
  65.         sleep(3)
  66.     end
  67.     mon.clear()
  68. end
  69.  
  70. testPass = ""
  71.  
  72. while true do
  73. writeLetters()
  74. evt, side, x, y = os.pullEvent("monitor_touch")
  75.  
  76. mon.setCursorPos(fx,2)
  77.     for co = 1, #click, 1 do
  78.     if x == click[co].X and y == click[co].Y then
  79.         if click[co].Letter == "<" then
  80.         fx = fx - 1
  81.  
  82.         if fx == 1 then
  83.             fx = 2
  84.         end
  85.         if string.len(testPass) < 1 then
  86.             shell.run("reboot")
  87.         end
  88.  
  89.         mon.setCursorPos(fx,2)
  90.         mon.write(" ")
  91.         testPass = testPass:sub(1,-2)
  92.        
  93.        
  94.  
  95.         elseif click[co].Letter == "=" then
  96.         send(testPass)
  97.         testPass = ""
  98.         fx = 2
  99.         else
  100.         mon.setTextColor(colors.orange)
  101.         mon.write(click[co].Letter)
  102.         mon.setTextColor(colors.white)
  103.         testPass = testPass .. click[co].Letter
  104.         fx = fx + 1
  105.         end
  106.     end
  107.     end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement