Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local gsm = require("gsm")
- local term = require("term")
- local keypad = component.os_keypad
- function split(s, delimiter)
- result = {};
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- local BANK_SERVER = "ТУТ АДРЕС БЕСПРОВОДНОЙ КАРТЫ СЕРВЕРА БАНКА"
- local CONTROLLER_ADDRESS = "ТУТ АДРЕС РОБОТА"
- local BANK_PORT = 812
- local CONTROLLER_PORT = 988
- keypad.setEventName("os_keypad_click")
- customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "C", "0", "#"}
- customButtonColor = {7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
- keypad.setKey(customButtons, customButtonColor)
- function handler()
- term.clear()
- print("------ATM------")
- print("Поднесите карту к считывателю.")
- keypad.setDisplay("...")
- local evt = {event.pull("magData")}
- local card = split(evt[4], ":")
- if #card ~= 3 then
- print("Неверный формат банковской карты.")
- return
- end
- print("Банковская карта прочитана.")
- local pin = ""
- print("Ожидаем PIN-CODE...")
- while true do
- local cipher = ""
- for i = 1, #pin do
- cipher = cipher .. "*"
- end
- keypad.setDisplay(cipher)
- local evt_click = {event.pull("os_keypad_click")}
- if evt_click[3] == 10 then
- if #pin ~= 0 then
- pin = pin:sub(1, -2)
- end
- elseif evt_click[3] == 12 then
- if #pin == 4 then
- break
- end
- else
- if #pin < 4 then
- pin = pin .. evt_click[4]
- end
- end
- end
- keypad.setDisplay("...")
- local info_card = split(gsm.listen(gsm.send(BANK_SERVER, BANK_PORT, "get_card:" .. card[1]))[5], ":")
- if info_card[1] == "success" then
- if info_card[3] == card[2] and info_card[4] == card[3] then
- if pin == info_card[6] then
- term.clear()
- print("Нажмите кнопку для продолжения:\n1. Узнать баланс.\n2. Внести наличные.")
- local option = 0
- while true do
- keypad.setDisplay("")
- local key_option = {event.pull("os_keypad_click")}
- if key_option[3] == 1 or key_option[3] == 2 then
- option = key_option[3]
- break
- end
- end
- keypad.setDisplay("...")
- if option == 1 then
- print("Баланс карты: " .. info_card[5])
- end
- if option == 2 then
- print("Положите наличные в сундук и нажмите клавишу #.")
- keypad.setDisplay("")
- while true do
- local key_option = {event.pull("os_keypad_click")}
- if key_option[3] == 12 then
- break
- end
- end
- keypad.setDisplay("...")
- local amount_deposited = gsm.listen(gsm.send(CONTROLLER_ADDRESS, CONTROLLER_PORT, "deposit"))[5]
- gsm.send(BANK_SERVER, BANK_PORT, "deposit:" .. info_card[2] .. ":" .. amount_deposited)
- print("Наличных внесено: " .. amount_deposited)
- end
- else
- print("PIN-CODE введён неверно.")
- end
- else
- print("Банковская карта содержит неверные данные.")
- end
- elseif info_card[1] == "card_not_found" then
- print("Банковская карта не найдена в базе данных.")
- else
- print("Произошла неизвестная ошибка.")
- end
- end
- while true do
- pcall(handler)
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement