TIMAS_Bro

bankomat

Oct 10th, 2023 (edited)
1,193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mn = peripheral.wrap("front")
  2. local dside = "drive_7"
  3. local screen = 1
  4. rednet.open("back")
  5. os.loadAPI("Base64")
  6. local card = nil
  7. local isCard = false
  8. mn.setBackgroundColor(colors.white)
  9. mn.clear()
  10. mn.setCursorPos(1,1)
  11. mn.write("Vstavte")
  12. mn.setCursorPos(1,2)
  13. mn.write("kartu")
  14. -- funcs
  15. local function clear()
  16.   mn.clear()
  17. end
  18. local function setTextColor(clr)
  19.   mn.setTextColor(clr)
  20. end
  21. local function setCursorPos(x,y)
  22.   mn.setCursorPos(x,y)
  23. end
  24. local function setBackgroundColor(clr)
  25.   mn.setBackgroundColor(clr)
  26. end
  27. local function write(txt)
  28.   mn.write(txt)
  29. end
  30. local sx,sy = mn.getSize()
  31. function drawBT(colorm, txt, line)
  32. setBackgroundColor(colorm)
  33. setCursorPos(1,line)
  34. for i=1,sx do
  35.  setBackgroundColor(colorm)
  36.     for g=line,3 do
  37.         setCursorPos(i,g)
  38.         write(" ")
  39.     end
  40. end
  41. setCursorPos(3,line+1)
  42. write(txt)
  43. end
  44. -- loop
  45. mn.setTextScale(0.5)
  46. function bank()
  47. while true do
  48.   local event, side = os.pullEvent()
  49.   local cardfile = fs.open("/disk/card","r")
  50.   if  (side == dside) then
  51.   if (cardfile) then
  52.     clear()
  53.     screen = 2
  54.     drawBT(colors.green,"Enter PIN",1)
  55.     setBackgroundColor(colors.red)
  56.     setTextColor(colors.white)
  57.     isCard = true
  58.     setCursorPos(1,sy)
  59.     pin = nil
  60.     write("OtmeHitb")
  61.     card = cardfile.readLine()
  62.     cardfile.close()
  63.   elseif (isCard == true and isCard ~= "ignore") then
  64.     clear()
  65.     setCursorPos(1,2)
  66.     setTextColor(colors.red)
  67.     setBackgroundColor(colors.white)
  68.     write("Dosvidanija!")
  69.     screen = 1
  70.     isCard = false
  71.     disk.eject(dside)
  72.     os.sleep(1)
  73.     setBackgroundColor(colors.white)
  74.     clear()
  75.     setCursorPos(1,1)
  76.     write("Bctabte")
  77.     setCursorPos(1,2)
  78.     write("kartu")
  79.   else if (isCard == "ignore") then
  80.     isCard = false
  81.   else
  82.     clear()
  83.     setCursorPos(1,2)
  84.     setTextColor(colors.red)
  85.     setBackgroundColor(colors.white)
  86.     write("Eto ne karta!")
  87.     screen = 1
  88.     isCard = false
  89.     disk.eject(dside)
  90.     os.sleep(1)
  91.     setBackgroundColor(colors.white)
  92.     clear()
  93.     setCursorPos(1,1)
  94.     write("Bctabte")
  95.     setCursorPos(1,2)
  96.     write("kartu")
  97.     end
  98.   end
  99.   end
  100. end
  101. end
  102. local pin = nil
  103. --pin
  104. function drawPinBT(color,textcolor,startX,endX,startY,endY,txt,txtLine)
  105.   setBackgroundColor(color)
  106.   setTextColor(textcolor)
  107.   for i=startX,endX do
  108.     for g=startY,endY do
  109.       setCursorPos(i,g)
  110.       write(" ")
  111.     end
  112.   end
  113.   setCursorPos(startX,txtLine)
  114.   write(txt)
  115. end
  116. function removeFromPin()
  117.   setBackgroundColor(colors.white)
  118.   setTextColor(colors.black)
  119.   setCursorPos(1,1)
  120.   if pin then
  121.   for i=1,20 do
  122.     setCursorPos(i,1)
  123.     write(" ")
  124.   end
  125.   setCursorPos(1,1)
  126.   pin = string.sub(pin, 1, -2)
  127.   write(pin)
  128.   end
  129. end
  130. function addToPin(value)
  131.   setBackgroundColor(colors.white)
  132.   if (not pin or string.len(pin) < 11) then
  133.   if pin ~= nil then
  134.   setCursorPos(1,1)
  135.   setTextColor(colors.black)
  136.   pin = pin..value
  137.   for i=1,string.len(pin) do
  138.     setCursorPos(i,1)
  139.     write("*")
  140.   end
  141.   setCursorPos(string.len(pin),1)
  142.   write(string.sub(pin,-1))
  143.   else
  144.   pin = value
  145.   setCursorPos(1,1)
  146.   setTextColor(colors.black)
  147.   write(pin)
  148.   end
  149.   end
  150. end
  151. function drawPin()
  152.     pin = nil
  153.     drawPinBT(colors.red,colors.white,2,2,2,2,"1",2)
  154.     drawPinBT(colors.orange,colors.white,4,4,2,2,"2",2)
  155.     drawPinBT(colors.red,colors.white,6,6,2,2,"3",2)
  156.     drawPinBT(colors.orange,colors.white,2,2,4,4,"4",4)
  157.     drawPinBT(colors.red,colors.white,4,4,4,4,"5",4)
  158.     drawPinBT(colors.orange,colors.white,6,6,4,4,"6",4)
  159.     drawPinBT(colors.red,colors.white,2,2,6,6,"7",6)
  160.     drawPinBT(colors.orange,colors.white,4,4,6,6,"8",6)
  161.     drawPinBT(colors.red,colors.white,6,6,6,6,"9",6)
  162.     drawPinBT(colors.orange,colors.white,4,4,8,8,"0",8)
  163.  drawPinBT(colors.red,colors.white,6,6,8,8,"C",8)
  164.  drawPinBT(colors.green,colors.white,8,15,8,8,"Confirm",8)
  165. end
  166. --
  167. local nick = nil
  168. local bal = nil
  169. --
  170. function click()
  171.   while true do
  172.     event, side, xPos, yPos = os.pullEvent("monitor_touch")
  173.     if (screen == 2) then
  174.       if (yPos > 0 and yPos < 4 and xPos> 0 and xPos < sx+1) then
  175.         print("PIN")
  176.         screen = 3
  177.         setBackgroundColor(colors.white)
  178.         clear()
  179.         drawPin()
  180.       elseif (yPos == sy and xPos< 10) then
  181.         print("SCREEN 1")
  182.         clear()
  183.         setCursorPos(1,2)
  184.         setTextColor(colors.red)
  185.         setBackgroundColor(colors.white)
  186.         write("Dosvidanija!")
  187.         screen = 1
  188.         disk.eject(dside)
  189.         isCard = "ignore"
  190.         os.sleep(1)
  191.         setBackgroundColor(colors.white)
  192.         clear()
  193.         setCursorPos(1,1)
  194.         write("Vstavte")
  195.         setCursorPos(1,2)
  196.         write("kartu")  
  197.       end
  198.    elseif (screen == 3) then
  199.      if (yPos == 2 and xPos == 2) then
  200.        addToPin("1")
  201.      elseif (yPos == 2 and xPos == 4) then
  202.        addToPin("2")
  203.      elseif (yPos == 2 and xPos == 6) then
  204.        addToPin("3")
  205.      elseif (yPos == 4 and xPos == 2) then
  206.        addToPin("4")
  207.      elseif (yPos == 4 and xPos == 4) then
  208.        addToPin("5")
  209.      elseif (yPos == 4 and xPos == 6) then
  210.        addToPin("6")
  211.      elseif (yPos == 6 and xPos == 2) then
  212.        addToPin("7")
  213.      elseif (yPos == 6 and xPos == 4) then
  214.        addToPin("8")
  215.      elseif (yPos == 6 and xPos == 6) then
  216.        addToPin("9")
  217.      elseif (yPos == 8 and xPos == 4) then
  218.        addToPin("0")
  219.      elseif (yPos == 8 and xPos == 6) then
  220.        removeFromPin()
  221.      elseif (yPos == 8 and xPos > 7 and xPos < 16) then
  222.        rednet.send(40,Base64.encode("login "..card.." "..pin),"bank44")
  223.        event, senderId, message, distance = os.pullEvent("rednet_message")
  224.        message = Base64.decode(message)
  225.        local ii = 1
  226.        for word in string.gmatch(message,"%S+") do
  227.          if (ii == 1) then
  228.            nick = word
  229.          elseif (ii == 2) then
  230.            bal = word
  231.          end
  232.          ii = ii +1
  233.        end
  234.        if (message == "error1") then
  235.         print("SCREEN 1")
  236.         clear()
  237.         setCursorPos(1,2)
  238.         setTextColor(colors.red)
  239.         setBackgroundColor(colors.white)
  240.         write("ERROR")
  241.         setCursorPos(1,3)
  242.         write("Takoy karty netu!")
  243.         screen = 1
  244.         isCard = "ignore"
  245.         disk.eject(dside)
  246.         os.sleep(1)
  247.         setBackgroundColor(colors.white)
  248.         clear()
  249.         setCursorPos(1,1)
  250.         write("Vstavte")
  251.         setCursorPos(1,2)
  252.         write("kartu")
  253.        elseif (message == "error2") then
  254.         print("SCREEN 1")
  255.         clear()
  256.         setCursorPos(1,2)
  257.         setTextColor(colors.red)
  258.         setBackgroundColor(colors.white)
  259.         write("ERROR")
  260.         setCursorPos(1,3)
  261.         write("Nevernyi parol!")
  262.         screen = 1
  263.         isCard = "ignore"
  264.         disk.eject(dside)
  265.         os.sleep(1)
  266.         setBackgroundColor(colors.white)
  267.         clear()
  268.         setCursorPos(1,1)
  269.         write("Vstavte")
  270.         setCursorPos(1,2)
  271.         write("kartu")
  272.        else
  273.          setBackgroundColor(colors.white)
  274.          clear()
  275.          screen = 4
  276.          drawPinBT(colors.red,colors.white,1,8,2,2,"Balance",2)
  277.          drawPinBT(colors.red,colors.white,1,16,4,4,"Snyat nalichku",4)
  278.          drawPinBT(colors.red,colors.white,1,16,6,6,"Perevesti dengi",6)
  279.          drawPinBT(colors.green,colors.white,1,6,10,10,"Vyiti",10)
  280.        end
  281.      end
  282.      elseif (screen == 4) then
  283.        if (yPos == 2 and xPos > 0 and xPos < 9) then
  284.          setBackgroundColor(colors.white)
  285.          clear()
  286.          drawPinBT(colors.white,colors.red,1,15,2,2,"Balans: "..bal.."AR",2)
  287.          drawPinBT(colors.red,colors.white,1,7,8,8,"Vyiti",8)
  288.          screen = 5
  289.        elseif (yPos == 4 and xPos < 17) then
  290.        elseif (yPos == 6 and xPos < 17) then
  291.        elseif(yPos == 10 and xPos < 7) then
  292.         print("SCREEN 1")
  293.         clear()
  294.         setCursorPos(1,2)
  295.         setTextColor(colors.red)
  296.         setBackgroundColor(colors.white)
  297.         write("Dosvidanija!")
  298.         screen = 1
  299.         isCard = "ignore"
  300.         disk.eject(dside)
  301.         os.sleep(1)
  302.         setBackgroundColor(colors.white)
  303.         clear()
  304.         setCursorPos(1,1)
  305.         write("Vstavte")
  306.         setCursorPos(1,2)
  307.         write("kartu")
  308.        end
  309.      elseif (screen == 5) then
  310.        if (yPos == 8 and xPos > 0 and xPos < 9) then
  311.          screen = 4
  312.          setBackgroundColor(colors.white)
  313.          drawPinBT(colors.red,colors.white,1,8,2,2,"Balance",2)
  314.          drawPinBT(colors.red,colors.white,1,16,4,4,"Snyat nalichku",4)
  315.          drawPinBT(colors.red,colors.white,1,16,6,6,"Perevesti dengi",6)
  316.          drawPinBT(colors.green,colors.white,1,6,10,10,"Vyiti",10)
  317.          clear()
  318.        end
  319.      end
  320.   end
  321. end
  322. parallel.waitForAll(bank,click)
Add Comment
Please, Sign In to add comment