Advertisement
Nikitos228

СЕРВЕР

Aug 26th, 2020
44
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local event = require("event")
  3. local term = require("term")
  4. local fs = require("filesystem")
  5. local gsm = require("gsm")
  6. local ini = require("ini")
  7.  
  8. local addresses = {"АДРЕС ПК ДЛЯ ПИЧАТИ КАРТ", "АДРЕС БАНКОМАТА"}
  9. local DATA_RAID = "f45"
  10. local LISTEN_PORT = 812
  11. local PAYMENT_IDENT = "4"
  12. local BANK_IDENT = "27630"
  13.  
  14. term.clear()
  15. print("Банк-сервер запущен.")
  16.  
  17. function check_luhn(number)
  18. local final_amount = 0
  19. for i = 1, #number do
  20. if (i % 2) == 0 then
  21. final_amount = final_amount + number:sub(i, i)
  22. else
  23. if (number:sub(i, i) * 2) > 9 then
  24. final_amount = final_amount + (number:sub(i, i) * 2 - 9)
  25. else
  26. final_amount = final_amount + (number:sub(i, i) * 2)
  27. end
  28. end
  29. end
  30. if (final_amount % 10) == 0 then
  31. return true
  32. else
  33. return false
  34. end
  35. end
  36.  
  37. function contains(array, element)
  38. for _, value in pairs(array) do
  39. if value == element then
  40. return true
  41. end
  42. end
  43. return false
  44. end
  45.  
  46. function split(s, delimiter)
  47. result = {};
  48. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  49. table.insert(result, match);
  50. end
  51. return result;
  52. end
  53.  
  54. function handler()
  55. local request = gsm.listen(LISTEN_PORT)
  56. local data = split(request[5], ":")
  57. if data[1] == "new_card" then
  58. print("Запрос на регистрацию новой карты.")
  59. if contains(addresses, request[3]) then
  60. if #data == 2 then
  61. local number_card = PAYMENT_IDENT .. BANK_IDENT
  62. while true do
  63. for i = 1, 9 do
  64. number_card = number_card .. math.random(0, 9)
  65. end
  66. for i = 0, 9 do
  67. if check_luhn(number_card .. i) then
  68. number_card = number_card .. i
  69. break
  70. end
  71. end
  72. if not fs.exists("/mnt/" .. DATA_RAID .. "/cards/" .. number_card .. ".card") then
  73. break
  74. end
  75. end
  76. local CVC = math.random(100, 999)
  77. local PIN = math.random(1000, 9999)
  78. ini.saveFile("/mnt/" .. DATA_RAID .. "/cards/" .. number_card .. ".card", {number = number_card, owner = data[2], cvc = CVC, pin = PIN, balance = 0})
  79. gsm.send(request[3], request[4], "success:" .. number_card .. ":" .. data[2] .. ":" .. CVC .. ":" .. PIN)
  80. else
  81. gsm.send(request[3], request[4], "invalid_structure")
  82. end
  83. end
  84. end
  85. if data[1] == "get_card" then
  86. print("Запрос на получение информации о карте.")
  87. if contains(addresses, request[3]) then
  88. if #data == 2 then
  89. if fs.exists("/mnt/" .. DATA_RAID .. "/cards/" .. data[2] .. ".card") then
  90. local card = ini.loadFile("/mnt/" .. DATA_RAID .. "/cards/" .. data[2] .. ".card")
  91. gsm.send(request[3], request[4], "success:" .. card["number"] .. ":" .. card["owner"] .. ":" .. card["cvc"] .. ":" .. card["balance"] .. ":" .. card["pin"])
  92. else
  93. gsm.send(request[3], request[4], "card_not_found")
  94. end
  95. else
  96. gsm.send(request[3], request[4], "invalid_structure")
  97. end
  98. end
  99. end
  100. if data[1] == "deposit" then
  101. print("Запрос на депозит карты [ATM].")
  102. if contains(addresses, request[3]) then
  103. if #data == 3 then
  104. if fs.exists("/mnt/" .. DATA_RAID .. "/cards/" .. data[2] .. ".card") then
  105. local card = ini.loadFile("/mnt/" .. DATA_RAID .. "/cards/" .. data[2] .. ".card")
  106. card["balance"] = card["balance"] + data[3]
  107. ini.saveFile("/mnt/" .. DATA_RAID .. "/cards/" .. data[2] .. ".card", card)
  108. gsm.send(request[3], request[4], "success")
  109. else
  110. gsm.send(request[3], request[4], "card_not_found")
  111. end
  112. else
  113. gsm.send(request[3], request[4], "invalid_structure")
  114. end
  115. end
  116. end
  117. end
  118.  
  119. while true do
  120. pcall(handler)
  121. end
Advertisement
RAW Paste Data Copied
Advertisement