VdanielV

Twitter CC Client phone

Jul 8th, 2021 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.49 KB | None | 0 0
  1. modem = peripheral.wrap("back")
  2. modem.open(125)
  3. image0 = paintutils.loadImage("/aplikacje/Twitter/loadsc.nfp")
  4. image = paintutils.loadImage("/aplikacje/Twitter/lsc.nfp")
  5. image2 = paintutils.loadImage("/aplikacje/Twitter/lscr.nfp")
  6. image3 = paintutils.loadImage("/aplikacje/Twitter/mainsc.nfp")
  7. image4 = paintutils.loadImage("/aplikacje/Twitter/mainscw.nfp")
  8.  
  9. message = nil
  10.  
  11. function system()
  12.     term.setBackgroundColor(colors.black)
  13.     term.setTextColor(colors.yellow)
  14.     term.setCursorPos(1,1)
  15.     term.clear()
  16.     print(os.version())
  17.     error()
  18. end
  19.  
  20. function loginscreen()
  21.     term.setCursorPos(1,1)
  22.     term.setBackgroundColor(colors.blue)
  23.     term.clear()
  24.     paintutils.drawImage(image, 1, 1)
  25.     term.setCursorPos(1,1)
  26.     term.setBackgroundColor(colors.blue)
  27.     term.setTextColor(colors.white)
  28.     io.write("Twitter")
  29.     term.setCursorPos(26,1)
  30.     io.write("X")
  31.     term.setCursorPos(9,7)
  32.     io.write("Zarejestruj")
  33.     term.setCursorPos(10,13)
  34.     term.setBackgroundColor(colors.white)
  35.     term.setTextColor(colors.blue)
  36.     io.write("Zaloguj")
  37.     ekran = true
  38.     while ekran == true do
  39.         event, button, x, y = os.pullEvent("mouse_click")
  40.         if (button == 1) and (x >= 6) and (x <= 21) and (y >= 5) and (y <= 8) then
  41.             term.setCursorPos(1,1)
  42.             term.setBackgroundColor(colors.blue)
  43.             term.clear()
  44.             paintutils.drawImage(image2, 1, 1)
  45.             term.setCursorPos(1,1)
  46.             term.setBackgroundColor(colors.blue)
  47.             term.setTextColor(colors.white)
  48.             io.write("<---")
  49.             term.setCursorPos(26,1)
  50.             io.write("X")
  51.             term.setCursorPos(8,1)
  52.             io.write("Rejestracja")
  53.             term.setCursorPos(8,3)
  54.             term.setBackgroundColor(colors.cyan)
  55.             io.write("Login")
  56.             term.setCursorPos(8,7)
  57.             io.write("Haslo")
  58.             term.setCursorPos(10,13)
  59.             term.setBackgroundColor(colors.blue)
  60.             io.write("Potwierdz")
  61.             log = {}
  62.             log2 = {}
  63.             reg = {}
  64.             reg2 = {}
  65.             ekranreg = true
  66.             while ekranreg == true do
  67.                 event, button, x, y = os.pullEvent("mouse_click")
  68.                 term.setBackgroundColor(colors.white)
  69.                 term.setTextColor(colors.black)
  70.                 if (button == 1) and (x >= 1) and (x <= 4) and (y == 1) then
  71.                     loginscreen()
  72.                 elseif (button == 1) and (x == 26) and (y == 1) then
  73.                     system()
  74.                 elseif (button == 1) and (x >= 8) and (x <= 19) and (y >= 4) and (y <= 5) then
  75.                     term.setCursorPos(8,17)
  76.                     term.setBackgroundColor(colors.cyan)
  77.                     io.write("              ")
  78.                     term.setBackgroundColor(colors.white)        
  79.                     term.setCursorPos(8,5)
  80.                     io.write("            ")
  81.                     term.setCursorPos(8,5)
  82.                     reg[1] = io.read()
  83.                 elseif (button == 1) and (x >= 8) and (x <= 19) and (y >= 8) and (y <= 9) then
  84.                     term.setCursorPos(8,19)
  85.                     term.setBackgroundColor(colors.cyan)
  86.                     io.write("              ")
  87.                     term.setCursorPos(8,9)
  88.                     term.setBackgroundColor(colors.white)
  89.                     io.write("            ")
  90.                     term.setCursorPos(8,9)
  91.                     reg[2] = io.read()
  92.                 elseif (button == 1) and (x >= 9) and (x <= 18) and (y >= 12) and (y <= 13) then
  93.                     reg[3] = "R"
  94.                     reg[4] = os.computerID()
  95.                     LoginNum = #reg[1]
  96.                     HasloNum = #reg[2]
  97.                     if reg[1] == nil then
  98.                         term.setCursorPos(2,17)
  99.                         term.setBackgroundColor(colors.cyan)
  100.                         term.setTextColor(colors.white)
  101.                         print("Login nie moze byc pusty")
  102.                     end
  103.                     if reg[2] == nil then
  104.                         term.setCursorPos(2,17)
  105.                         term.setBackgroundColor(colors.cyan)
  106.                         term.setTextColor(colors.white)
  107.                         print("Haslo nie moze byc puste")
  108.                     end
  109.                     if (LoginNum > 12) then
  110.                         term.setCursorPos(8,17)
  111.                         term.setBackgroundColor(colors.cyan)
  112.                         term.setTextColor(colors.white)
  113.                         print("Za dlugi login")
  114.                     end
  115.                     if (HasloNum > 12) then
  116.                         term.setCursorPos(8,19)
  117.                         term.setBackgroundColor(colors.cyan)
  118.                         term.setTextColor(colors.white)
  119.                         print("Za dlugie haslo")
  120.                     end
  121.                     if (LoginNum <= 12) and (HasloNum <= 12) and (reg[1] ~= nil) and (reg[2] ~= nil) then
  122.                         msg = textutils.serialize(reg)
  123.                         modem.transmit(120, 9, msg)
  124.                         sleep(4)
  125.                         if message ~= nil then
  126.                             if message == "User exist" then
  127.                                 loginscreen()
  128.                             else
  129.                                 reg2 = textutils.unserialize(message)
  130.                                 if (reg2[1] == reg[1]) and (reg2[2] == reg[2]) and (reg2[4] == reg[4])then
  131.                                     settings.set("R", reg)
  132.                                     print("Zarejestrowany")
  133.                                     settings.save()
  134.                                     sleep(1)
  135.                                     premain()
  136.                                 end
  137.                             end
  138.                         else
  139.                             term.setCursorPos(8,18)
  140.                             term.setTextColor(colors.white)
  141.                             term.setBackgroundColor(colors.cyan)
  142.                             print("Wystapil blad")
  143.                         end
  144.                     elseif (button == 1) and (x == 26) and (y == 1) then
  145.                         system()
  146.                     end
  147.                 end
  148.             end
  149.         elseif (button == 1) and (x >= 6) and (x <= 21) and (y >= 11) and (y <= 14) then
  150.             term.setCursorPos(1,1)
  151.             term.setBackgroundColor(colors.blue)
  152.             term.clear()
  153.             paintutils.drawImage(image2, 1, 1)
  154.             term.setCursorPos(1,1)
  155.             term.setBackgroundColor(colors.blue)
  156.             term.setTextColor(colors.white)
  157.             io.write("<---")
  158.             term.setCursorPos(26,1)
  159.             io.write("X")
  160.             term.setCursorPos(8,1)
  161.             io.write("Logowanie")
  162.             term.setCursorPos(8,3)
  163.             term.setBackgroundColor(colors.cyan)
  164.             io.write("Login")
  165.             term.setCursorPos(8,7)
  166.             io.write("Haslo")
  167.             term.setCursorPos(10,13)
  168.             term.setBackgroundColor(colors.blue)
  169.             io.write("Potwierdz")
  170.             log = {}
  171.             log2 = {}
  172.             reg = {}
  173.             reg2 = {}
  174.             ekranlog = true
  175.             while ekranlog == true do
  176.                 event, button, x, y = os.pullEvent("mouse_click")
  177.                 term.setBackgroundColor(colors.white)
  178.                 term.setTextColor(colors.black)
  179.                 if (button == 1) and (x >= 1) and (x <= 4) and (y == 1) then
  180.                     loginscreen()
  181.                 elseif (button == 1) and (x == 26) and (y == 1) then
  182.                     system()
  183.                 elseif (button == 1) and (x >= 8) and (x <= 19) and (y >= 4) and (y <= 5) then
  184.                     term.setCursorPos(8,17)
  185.                     term.setBackgroundColor(colors.cyan)
  186.                     io.write("              ")
  187.                     term.setBackgroundColor(colors.white)        
  188.                     term.setCursorPos(8,5)
  189.                     io.write("            ")
  190.                     term.setCursorPos(8,5)
  191.                     log[1] = io.read()
  192.                 elseif (button == 1) and (x >= 8) and (x <= 19) and (y >= 8) and (y <= 9) then
  193.                     term.setCursorPos(8,19)
  194.                     term.setBackgroundColor(colors.cyan)
  195.                     io.write("              ")
  196.                     term.setCursorPos(8,9)
  197.                     term.setBackgroundColor(colors.white)
  198.                     io.write("            ")
  199.                     term.setCursorPos(8,9)
  200.                     log[2] = io.read()
  201.                 elseif (button == 1) and (x >= 9) and (x <= 18) and (y >= 12) and (y <= 13) then
  202.                     log[3] = "Z"
  203.                     log[4] = os.computerID()
  204.                     LoginNum = #log[1]
  205.                     HasloNum = #log[2]
  206.                     if log[1] == nil then
  207.                         term.setCursorPos(2,17)
  208.                         term.setBackgroundColor(colors.cyan)
  209.                         term.setTextColor(colors.white)
  210.                         print("Login nie może być pusty")
  211.                     end
  212.                     if log[2] == nil then
  213.                         term.setCursorPos(2,17)
  214.                         term.setBackgroundColor(colors.cyan)
  215.                         term.setTextColor(colors.white)
  216.                         print("Hasło nie może być puste")
  217.                     end
  218.                     if (LoginNum > 12) then
  219.                         term.setCursorPos(8,17)
  220.                         term.setBackgroundColor(colors.cyan)
  221.                         term.setTextColor(colors.white)
  222.                         print("Za dlugi login")
  223.                     end
  224.                     if (HasloNum > 12) then
  225.                         term.setCursorPos(8,19)
  226.                         term.setBackgroundColor(colors.cyan)
  227.                         term.setTextColor(colors.white)
  228.                         print("Za dlugie haslo")
  229.                     end
  230.                     if (LoginNum <= 12) and (HasloNum <= 12) and (log[1] ~= nil) and (log[2] ~= nil) then
  231.                         msg = textutils.serialize(log)
  232.                         modem.transmit(120, 9, msg)
  233.                         sleep(4)
  234.                         if message ~= nil then
  235.                             settings.load()
  236.                             log2 = textutils.unserialize(message)
  237.                             if log2[2] == "Invalid User or password" then
  238.                                 print("Logowanie nieudane")
  239.                                 sleep(2)
  240.                                 loginscreen()
  241.                             else
  242.                                 print(message)
  243.                                 if (log2[1] == log[1]) and (log2[2] == log[2]) then
  244.                                     settings.set("R", log)
  245.                                     print("Zalogowany")
  246.                                     settings.save()
  247.                                     sleep(1)
  248.                                     premain()
  249.                                 end
  250.                             end
  251.                         else
  252.                             term.setCursorPos(8,18)
  253.                             term.setTextColor(colors.white)
  254.                             term.setBackgroundColor(colors.cyan)
  255.                             print("Wystapil blad")
  256.                         end
  257.                     end
  258.                 end
  259.             end
  260.         elseif (button == 1) and (x == 26) and (y == 1) then
  261.             system()
  262.         end
  263.     end
  264. end
  265.  
  266. function odbieraniezid()
  267.     rlcheck = true
  268.     i = 1
  269.     while rlcheck == true do
  270.         event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  271.         rl = textutils.unserialize(message)
  272.         if rl[4] == os.computerID() then
  273.             rlcheck = false
  274.             break
  275.         elseif rl[4] ~= os.computerID() then
  276.             message = nil
  277.             sleep(0.5)
  278.             i = i + 1
  279.         end
  280.         if i == 5 then
  281.             break
  282.         end
  283.     end    
  284. end
  285.  
  286. function odbieranieref()
  287.     odbref = true
  288.     while odbref == true do
  289.         event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  290.         rl = textutils.unserialize(message)
  291.         if rl[4] ~= os.computerID() then
  292.             message = nil
  293.         end
  294.     end
  295. end
  296.  
  297. function scroll()
  298.     while true do
  299.         event, scrollDirection, x, y = os.pullEvent("mouse_scroll")
  300.         if scrollDirection == -1 then
  301.             win2 = term.redirect(myWindow)
  302.             term.scroll(2)
  303.             term.redirect(win2)
  304.         elseif scrollDirection == 1 then
  305.             win2 = term.redirect(myWindow)
  306.             term.scroll(-2)
  307.             term.redirect(win2)
  308.         end
  309.     end
  310. end
  311.  
  312. function loading()
  313.     term.setCursorPos(1,1)
  314.     term.clear()
  315.     paintutils.drawImage(image0, 1, 1)
  316.     term.setCursorPos(10,2)
  317.     term.setTextColor(colors.white)
  318.     term.setBackgroundColor(colors.cyan)
  319.     io.write("TWITTER")
  320.     term.setCursorPos(6,20)
  321. end
  322.  
  323. function probazalogowania()
  324.     R = settings.get("R")
  325.     R[3] = "Z"
  326.     R[4] = os.computerID()
  327.     probamsg = textutils.serialize(R)
  328.     modem.transmit(120, 9, probamsg)
  329.     sleep(3)
  330.     if message ~= nil then
  331.         if message == "Invalid User or password" then
  332.             print("Logowanie nieudane")
  333.             sleep(2)
  334.             loginscreen()
  335.         else
  336.             probamsg2 = textutils.unserialize(message)
  337.             if (R[1] == probamsg2[1]) and (R[2] == probamsg2[2]) then
  338.                 table.remove(probamsg2, 3)
  339.                 table.remove(R, 3)
  340.                 premain()
  341.             end
  342.         end
  343.     else
  344.         io.write("Wystapil blad")
  345.         sleep(1)
  346.         loginscreen()
  347.     end
  348. end
  349.  
  350. function wyslijwiad()
  351.     term.setCursorPos(1,1)
  352.     term.clear()
  353.     paintutils.drawImage(image4, 1, 1)
  354.     term.setCursorPos(1,1)
  355.     term.setBackgroundColor(colors.blue)
  356.     term.setTextColor(colors.white)
  357.     io.write("<---")
  358.     term.setCursorPos(26,1)
  359.     io.write("X")
  360.     term.setCursorPos(6,4)
  361.     term.setBackgroundColor(colors.cyan)
  362.     io.write("Wpisz wiadomosc")
  363.     term.setCursorPos(6,15)
  364.     io.write("Wyslij wiadomosc")
  365.     wyswiad = true
  366.     while wyswiad == true do
  367.         event, button, x, y = os.pullEvent("mouse_click")
  368.         if (button == 1) and (x >= 1) and (x <= 4) and (y == 1) then
  369.             premain()
  370.         elseif (button == 1) and (x == 26) and (y == 1) then
  371.             system()
  372.         elseif (button == 1) and (x >= 5) and (x <= 22) and (y >= 5) and (y <= 10) then
  373.             term.setCursorPos(5,10)
  374.             term.setBackgroundColor(colors.white)
  375.             io.write("                  ")
  376.             term.setCursorPos(23,10)
  377.             term.setBackgroundColor(colors.cyan)
  378.             io.write("   ")
  379.             term.setTextColor(colors.black)
  380.             term.setBackgroundColor(colors.white)
  381.             term.setCursorPos(5,10)
  382.             wyswiadtxt = io.read()
  383.         elseif (button == 1) and (x >= 5) and (x <= 22) and (y >= 14) and (y <= 16) then
  384.             nick = settings.get("R")
  385.             textwiad = nick[1]..":".." "..wyswiadtxt
  386.             modem.transmit(124, 9, textwiad)
  387.             premain()
  388.         end
  389.     end
  390. end
  391.  
  392. function main()
  393.     term.setCursorPos(1,1)
  394.     term.clear()
  395.     paintutils.drawImage(image3, 1, 1)
  396.     term.setCursorPos(2,2)
  397.     term.setBackgroundColor(colors.cyan)
  398.     term.setTextColor(colors.white)
  399.     io.write("@")
  400.     term.setCursorPos(7,2)
  401.     io.write("Napisz tweet'a")
  402.     term.setCursorPos(25,2)
  403.     io.write("X")
  404.     term.setCursorPos(15,20)
  405.     term.setBackgroundColor(colors.blue)
  406.     io.write("Wyloguj sie")
  407.     term.setCursorPos(6,19)
  408.     myWindow = window.create(term.current(),4,5,20,14)
  409.     myWindow.setBackgroundColor(colors.blue)
  410.     myWindow.setCursorPos(1,1)
  411.     myWindow.clear()
  412.     odswiez()
  413.     mcos = true
  414.     while mcos == true do
  415.         event, button, x, y = os.pullEvent("mouse_click")
  416.         if (button == 1) and (x == 2) and (y == 2) then
  417.             odswiez()
  418.         elseif (button == 1) and (x == 25) and (y == 2) then
  419.             system()
  420.         elseif (button == 1) and (x >= 8) and (x <= 18) and (y == 2) then
  421.             wyslijwiad()
  422.         elseif (button == 1) and (x >= 15) and (x <= 25) and (y == 20) then
  423.             settings.unset("R")
  424.             settings.save()
  425.             loginscreen()
  426.         end
  427.     end
  428. end
  429.  
  430. function premain()
  431.     parallel.waitForAll(odbieranieref, main)
  432. end
  433.  
  434. function odswiez()
  435.     ait = true
  436.     ai = 1
  437.     while ait == true do
  438.         message = nil
  439.         ref = {}
  440.         refmsg = {}
  441.         refmsg2 = {}
  442.         ref[1] = "refresh"
  443.         ref[4] = os.computerID()
  444.         refmsg = textutils.serialize(ref)
  445.         modem.transmit(122, 9, refmsg)
  446.         sleep(2)
  447.         if message ~= nil then
  448.             myWindow.setBackgroundColor(colors.blue)
  449.             myWindow.setCursorPos(1,1)
  450.             myWindow.clear()
  451.             refmsg2 = textutils.unserialize(message)
  452.             win3 = term.redirect(myWindow)
  453.             print(refmsg2[1])
  454.             term.redirect(win3)
  455.             ait = false
  456.             break
  457.         else
  458.             ai = ai + 1
  459.             if ai == 3 then
  460.                 ait = false
  461.                 break
  462.             end
  463.         end
  464.     end
  465. end
  466.  
  467. settings.load()
  468.  
  469. if settings.get("R") == nil then
  470.     loading()
  471.     sleep(3)
  472.     parallel.waitForAny(odbieranieref, loginscreen)
  473. else
  474.     loading()
  475.     message = nil
  476.     parallel.waitForAny(odbieranieref, probazalogowania)
  477. end
  478.  
Add Comment
Please, Sign In to add comment