Advertisement
Nikitos228

Untitled

Aug 26th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.73 KB | None | 0 0
  1. local component = require("component")
  2. local event = require("event")
  3. local gsm = require("gsm")
  4. local term = require("term")
  5. local keypad = component.os_keypad
  6.  
  7. function split(s, delimiter)
  8.     result = {};
  9.     for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  10.         table.insert(result, match);
  11.     end
  12.     return result;
  13. end
  14.  
  15. local BANK_SERVER = "ТУТ АДРЕС БЕСПРОВОДНОЙ КАРТЫ СЕРВЕРА БАНКА"
  16. local CONTROLLER_ADDRESS = "ТУТ АДРЕС РОБОТА"
  17.  
  18. local BANK_PORT = 812
  19. local CONTROLLER_PORT = 988
  20.  
  21. keypad.setEventName("os_keypad_click")
  22. customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "C", "0", "#"}
  23. customButtonColor = {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
  24. keypad.setKey(customButtons, customButtonColor)
  25.  
  26. function handler()
  27.   term.clear()
  28.   print("------ATM------")
  29.   print("Поднесите карту к считывателю.")
  30.   keypad.setDisplay("...")
  31.   local evt = {event.pull("magData")}
  32.   local card = split(evt[4], ":")
  33.   if #card ~= 3 then
  34.     print("Неверный формат банковской карты.")
  35.     return
  36.   end
  37.   print("Банковская карта прочитана.")
  38.   local pin = ""
  39.   print("Ожидаем PIN-CODE...")
  40.   while true do
  41.     local cipher = ""
  42.     for i = 1, #pin do
  43.       cipher = cipher .. "*"
  44.     end
  45.     keypad.setDisplay(cipher)
  46.     local evt_click = {event.pull("os_keypad_click")}
  47.     if evt_click[3] == 10 then
  48.       if #pin ~= 0 then
  49.         pin = pin:sub(1, -2)
  50.       end
  51.     elseif evt_click[3] == 12 then
  52.       if #pin == 4 then
  53.         break
  54.       end      
  55.     else
  56.       if #pin < 4 then
  57.         pin = pin .. evt_click[4]
  58.       end
  59.     end
  60.   end
  61.   keypad.setDisplay("...")
  62.   local info_card = split(gsm.listen(gsm.send(BANK_SERVER, BANK_PORT, "get_card:" .. card[1]))[5], ":")
  63.   if info_card[1] == "success" then
  64.     if info_card[3] == card[2] and info_card[4] == card[3] then
  65.       if pin == info_card[6] then
  66.         term.clear()
  67.         print("Нажмите кнопку для продолжения:\n1. Узнать баланс.\n2. Внести наличные.")
  68.  
  69.         local option = 0
  70.  
  71.         while true do
  72.           keypad.setDisplay("")
  73.           local key_option = {event.pull("os_keypad_click")}
  74.           if key_option[3] == 1 or key_option[3] == 2 then
  75.             option = key_option[3]
  76.             break
  77.           end
  78.         end
  79.  
  80.         keypad.setDisplay("...")
  81.        
  82.         if option == 1 then
  83.           print("Баланс карты: " .. info_card[5])                          
  84.         end
  85.  
  86.         if option == 2 then
  87.           print("Положите наличные в сундук и нажмите клавишу #.")
  88.           keypad.setDisplay("")
  89.           while true do
  90.             local key_option = {event.pull("os_keypad_click")}
  91.             if key_option[3] == 12 then
  92.               break
  93.             end
  94.           end
  95.           keypad.setDisplay("...")
  96.           local amount_deposited = gsm.listen(gsm.send(CONTROLLER_ADDRESS, CONTROLLER_PORT, "deposit"))[5]
  97.           gsm.send(BANK_SERVER, BANK_PORT, "deposit:" .. info_card[2] .. ":" .. amount_deposited)
  98.           print("Наличных внесено: " .. amount_deposited)
  99.         end
  100.       else
  101.         print("PIN-CODE введён неверно.")
  102.       end
  103.     else
  104.       print("Банковская карта содержит неверные данные.")
  105.     end
  106.   elseif info_card[1] == "card_not_found" then
  107.     print("Банковская карта не найдена в базе данных.")
  108.   else
  109.     print("Произошла неизвестная ошибка.")
  110.   end    
  111. end
  112.  
  113. while true do
  114.   pcall(handler)
  115.   os.sleep(5)
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement