Advertisement
Guest User

startup

a guest
Feb 20th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.27 KB | None | 0 0
  1. function headline(title)
  2.     term.setBackgroundColor(colors.black)
  3.     term.clear()
  4.     paintutils.drawLine(1, 1, 52, 1, colors.blue)
  5.     term.setTextColor(colors.orange)
  6.     term.setCursorPos(1, 1)
  7.     print(title)
  8.     term.setCursorPos(24,1)
  9.     print("v1.0")
  10.     term.setCursorPos(39, 1)
  11.     print("by MagicMarky")
  12.    
  13.     term.setBackgroundColor(colors.black)
  14.     term.setTextColor(colors.white)
  15. end
  16.  
  17. function centerText(text, y)
  18.     local sx, sy = term.getSize()
  19.     term.setCursorPos(math.ceil((sx/2)-(#text)/2), y)
  20.     print(text)
  21. end
  22.  
  23. function start()
  24.     headline("MMTL System")
  25.    
  26.     --Felder
  27.     paintutils.drawPixel(2, 3, colors.lime)
  28.     paintutils.drawPixel(2, 5, colors.lime)
  29.     term.setBackgroundColor(colors.black)
  30.     term.setTextColor(colors.white)
  31.     term.setCursorPos(4, 3)
  32.     print("Login")
  33.     term.setCursorPos(4, 5)
  34.     print("TåBCr åB6ffnen")
  35.    
  36.     while true do
  37.         local event, button, x, y = os.pullEvent("mouse_click")
  38.  
  39.         if x >= 2 and x <= 8 and y == 3 then
  40.             login()
  41.             break
  42.         elseif x >= 2 and x <= 14 and y == 5 then
  43.             passwort()
  44.             break
  45.         end
  46.     end
  47. end
  48.  
  49. username = ""
  50. password = ""
  51. function login()
  52.     rednet.open("back")
  53.    
  54.     headline("MMTL Login")
  55.  
  56.     --Username/Passwort
  57.     term.setBackgroundColor(colors.black)
  58.     term.setTextColor(colors.cyan)
  59.     term.setCursorPos(14, 6)
  60.     print("Username: ")
  61.     term.setCursorPos(14, 7)
  62.     print("Passwort: ")
  63.    
  64.     --Abfrage
  65.     term.setTextColor(colors.yellow)
  66.     term.setCursorPos(24, 6)
  67.     username = read()
  68.     term.setCursorPos(24, 7)
  69.     password = read("*")
  70.  
  71.     local msg = "LOGIN " .. username .. ":" .. password
  72.     rednet.send(62, msg)
  73.    
  74.     local ret = "N/A"
  75.     while true do
  76.         id, ret = rednet.receive(10)
  77.         if id == nil then
  78.             break
  79.         elseif id == 62 then
  80.             if ret == "USER_NOT_EXISTS" or ret == "RIGHT_PASSWORD" or ret == "WRONG_PASSWORD" then
  81.                 break
  82.             end
  83.         end
  84.     end
  85.  
  86.     if ret == "RIGHT_PASSWORD" then
  87.         term.setTextColor(colors.lime)
  88.         centerText("Logging in..", 14)
  89.         os.sleep(2)
  90.         interface()
  91.     elseif ret == "WRONG_PASSWORD" then
  92.         term.setTextColor(colors.red)
  93.         centerText("Passwort falsch!", 14)
  94.         os.sleep(2)
  95.         login()
  96.     elseif ret == "USER_NOT_EXISTS" then
  97.         term.setTextColor(colors.red)
  98.         centerText("User nicht vorhanden!", 14)
  99.         os.sleep(2)
  100.         login()
  101.     elseif ret == "N/A" then
  102.         term.setTextColor(colors.red)
  103.         centerText("Keine Antwort vom Server!", 14)
  104.         os.sleep(2)
  105.         login()
  106.     end
  107. end
  108.  
  109. function interface()
  110.     headline("MMTL Interface")
  111.  
  112.     --Felder
  113.     paintutils.drawPixel(2, 3, colors.lime)
  114.     paintutils.drawPixel(2, 5, colors.lime)
  115.     paintutils.drawPixel(42, 18, colors.red)
  116.  
  117.     term.setBackgroundColor(colors.black)
  118.     term.setTextColor(colors.white)
  119.     term.setCursorPos(4, 3)
  120.     print("Mail")
  121.     term.setCursorPos(4, 5)
  122.     print("Hello World")
  123.     term.setCursorPos(44, 18)
  124.     print("Logout")
  125.  
  126.     --Click
  127.     while true do
  128.         local event, button, x, y = os.pullEvent("mouse_click")
  129.  
  130.         if x >= 2 and x <= 7 and y == 3 then
  131.             mail()
  132.             break
  133.         elseif x >=2 and x <= 14 and y == 5 then
  134.             term.clear()
  135.             headline("MMTL Interface")
  136.             term.setCursorPos(1, 3)
  137.             shell.run("hello")
  138.             os.sleep(1)
  139.             interface()
  140.             break
  141.         elseif x >= 42 and x <= 49 and y == 18 then
  142.             os.reboot()
  143.             break
  144.         end
  145.     end
  146. end
  147.  
  148. function mail()
  149.     rednet.open("back")
  150.  
  151.     headline("MMTL Mail")
  152.  
  153.     --Click
  154.     function posteingang()
  155.         term.clear()
  156.         headline("MMTL Mail")
  157.        
  158.         paintutils.drawPixel(2, 3, colors.lime)
  159.         paintutils.drawPixel(2, 5, colors.lime)
  160.         paintutils.drawPixel(42, 18, colors.red)
  161.         term.setBackgroundColor(colors.black)
  162.         term.setTextColor(colors.white)
  163.         term.setCursorPos(4, 3)
  164.         print("Posteingang")
  165.         term.setCursorPos(4, 5)
  166.         print("E-Mail senden")
  167.         term.setCursorPos(44, 18)
  168.         print("ZuråBCck")
  169.        
  170.         while true do
  171.             local event, button, x, y = os.pullEvent("mouse_click")
  172.             if x >=2 and x <= 14 and y == 3 then
  173.                 -- Mail Abrufen
  174.                 headline("MMTL Mail")
  175.                 term.setTextColor(colors.yellow)
  176.                 centerText("Checking..", 9)
  177.                 receive()
  178.                 --ZuråBCck
  179.                 paintutils.drawPixel(42, 18, colors.red)
  180.                 term.setBackgroundColor(colors.black)
  181.                 term.setTextColor(colors.white)
  182.                 term.setCursorPos(44, 18)
  183.                 print("ZuråBCck")
  184.                 zurueck()
  185.                 break
  186.             elseif x >= 42 and x <= 49 and y == 18 then
  187.                 interface()
  188.                 break
  189.             elseif x >= 2 and x <= 16 and y == 5 then
  190.                 headline("MMTL Mail")
  191.                 term.setTextColor(colors.lime)
  192.                 term.setCursorPos(1, 3)
  193.                 print("An: ")
  194.                 print("Nachricht: ")
  195.                 term.setTextColor(colors.white)
  196.                 term.setCursorPos(5, 3)
  197.                 local ziel = read()
  198.                 term.setCursorPos(12, 4)
  199.                 local input = read()
  200.                
  201.                 term.setTextColor(colors.yellow)
  202.                 centerText("Sending...", 9)
  203.                
  204.                 term.setTextColor(colors.yellow)
  205.                 send(ziel, input)
  206.                 local ret = "N/A"
  207.                 while true do
  208.                     id, ret = rednet.receive(5)
  209.                     if id == nil then
  210.                         break
  211.                     elseif id == 62 then
  212.                         if ret == "SUCCESSFUL_SENT" or ret == "FAILED_SENT" then
  213.                             break
  214.                         end
  215.                     end
  216.                 end
  217.                
  218.                 sleep(2)
  219.                
  220.                 if id == nil then
  221.                     headline("MMTL Mail")
  222.                     term.setTextColor(colors.red)
  223.                     centerText("Keine Antwort vom Server!", 9)
  224.                     sleep(1.5)
  225.                 else
  226.                     if ret == "SUCCESSFUL_SENT" then
  227.                         headline("MMTL Mail")
  228.                         term.setTextColor(colors.yellow)
  229.                         centerText("Successfully sent", 9)
  230.                         sleep(1.5)
  231.                     elseif ret == "TARGET_NOT_EXISTS" then
  232.                         headline("MMTL Mail")
  233.                         term.setTextColor(colors.red)
  234.                         centerText("User nicht vorhanden!", 9)
  235.                         sleep(1.5)
  236.                     elseif ret == "FAILED_SENT" then
  237.                         headline("MMTL Mail")
  238.                         term.setTextColor(colors.red)
  239.                         centerText("E-Mail senden gescheitert!", 9)
  240.                         sleep(1.5)
  241.                     end
  242.                 end
  243.                
  244.                 mail()
  245.                 break
  246.             end
  247.         end
  248.     end
  249.  
  250.     function zurueck()
  251.         while true do
  252.             local event, button, x, y = os.pullEvent("mouse_click")
  253.             if x >= 42 and x <= 49 and y == 18 then
  254.                 posteingang()
  255.                 break
  256.             end
  257.         end
  258.     end
  259.  
  260.     function receive()
  261.         while true do
  262.             local id, msg = rednet.receive(1.5)
  263.             headline("MMTL Mail")
  264.             term.setCursorPos(2, 3)
  265.             print(msg)
  266.             break
  267.         end
  268.     end
  269.  
  270.     function send(ziel, input)
  271.         local nachricht = "SEND " .. username .. ":" .. password .. " ".. ziel .." " .. input
  272.         rednet.send(62, nachricht)
  273.     end
  274.  
  275.     posteingang()
  276. end
  277.  
  278. function passwort()
  279.     term.setBackgroundColor(colors.black)
  280.     term.clear()
  281.     term.setTextColor(colors.blue)
  282.     term.setCursorPos(1, 3)
  283.     print("---------------------------------------------------")
  284.     print(" ")
  285.     centerText("Willkommen in der Zentrale von", 5)
  286.     print(" ")
  287.     centerText("Michi, Lu, Tim und Markus!", 7)
  288.     print(" ")
  289.     print("---------------------------------------------------")
  290.     term.setTextColor(colors.gray)
  291.     term.setCursorPos(1, 19)
  292.     print("(Hacken ist nicht måB6glich)")
  293.     term.setCursorPos(1, 16)
  294.     term.setTextColor(colors.lime)
  295.     write("Bitte Passwort eingeben: ")
  296.     term.setTextColor(colors.yellow)
  297.     passwort = read("*")
  298.    
  299.     if passwort == " lutschn " then
  300.         rs.setOutput("bottom", true)
  301.         term.setTextColor(colors.lime)
  302.         term.setCursorPos(1, 16)
  303.         term.clearLine()
  304.         term.setCursorPos(1, 18)
  305.         term.clearLine()
  306.         term.setCursorPos(23, 13)
  307.         print("      + ")
  308.         term.setCursorPos(23, 14)
  309.         print("     +  ")
  310.         term.setCursorPos(23, 15)
  311.         print("  + +   ")
  312.         term.setCursorPos(23, 16)
  313.         print("   +    ")
  314.         os.sleep(2)
  315.         rs.setOutput("bottom", false)
  316.     elseif passwort == "zu" then
  317.         rs.setOutput("bottom", false)
  318.         term.setTextColor(colors.lightGray)
  319.         term.setCursorPos(1, 16)
  320.         term.clearLine()
  321.         term.setCursorPos(1, 18)
  322.         term.clearLine()
  323.         term.setCursorPos(23, 12)
  324.         print("   ++   ")
  325.         term.setCursorPos(23, 13)
  326.         print("  +  +  ")
  327.         term.setTextColor(colors.orange)
  328.         term.setCursorPos(23, 14)
  329.         print(" ++++++ ")
  330.         term.setCursorPos(23, 15)
  331.         print(" ++++++ ")
  332.         term.setCursorPos(23, 16)
  333.         print(" ++++++ ")
  334.         os.sleep(2)
  335.     else
  336.         local file = fs.open("log", fs.exists("log") and "a" or "w")
  337.         file.writeLine(passwort)
  338.         file.close()
  339.         term.setTextColor(colors.red)
  340.         term.setCursorPos(1, 16)
  341.         term.clearLine()
  342.         term.setCursorPos(1, 18)
  343.         term.clearLine()
  344.         term.setCursorPos(23, 12)
  345.         print("+       +")
  346.         term.setCursorPos(23, 13)
  347.         print("  +   +  ")
  348.         term.setCursorPos(23, 14)
  349.         print("    +    ")
  350.         term.setCursorPos(23, 15)
  351.         print("  +   +  ")
  352.         term.setCursorPos(23, 16)
  353.         print("+       +")
  354.         os.sleep(2)
  355.     end
  356.     start()
  357. end
  358.  
  359. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement