- 29
- 1
Помогите с прокси что бы постоянно меняло прокси, когда сервер пишет you are banned
local proxies = {}
local currentProxyIndex = 0
local maxRetries = 3
local retryCount = 0
function loadProxiesFromFile()
local filename = "accounts\\proxies.txt"
local file = io.open(filename, "r")
if not file then
print("Ошибка: не могу открыть файл " .. filename)
return false
end
for line in file:lines() do
line = line:gsub("%s+", "")
if line ~= "" then
-- Форматы: ip:port или ip:port:user:pass
table.insert(proxies, line)
end
end
file:close()
print("Загружено прокси: " .. #proxies)
return #proxies > 0
end
function connectToNextProxy()
if #proxies == 0 then
print("Нет доступных прокси!")
return false
end
currentProxyIndex = currentProxyIndex + 1
if currentProxyIndex > #proxies then
currentProxyIndex = 1
end
local proxyData = proxies[currentProxyIndex]
print("Попытка подключения к прокси " .. currentProxyIndex .. "/" .. #proxies .. ": " .. proxyData)
local parts = {}
for part in proxyData:gmatch("[^:]+") do
table.insert(parts, part)
end
if #parts == 2 then -- ip:port
return proxyConnect(proxyData, "", "")
elseif #parts == 4 then -- ip:port:user:pass
return proxyConnect(parts[1] .. ":" .. parts[2], parts[3], parts[4])
else
print("Неверный формат прокси: " .. proxyData)
return false
end
end
function onLoad()
if loadProxiesFromFile() then
connectToNextProxy()
else
print("Не удалось загрузить прокси, работа без прокси")
end
setRate(RATE_LUA, 100)
end
function onProxyError()
print("Ошибка прокси #" .. currentProxyIndex)
retryCount = retryCount + 1
if retryCount >= maxRetries then
print("Превышено количество попыток, пробуем следующую прокси")
retryCount = 0
wait(2000)
connectToNextProxy()
else
print("Повторная попытка (" .. retryCount .. "/" .. maxRetries .. ")")
wait(1000)
connectToNextProxy()
end
end
function onProxyConnect()
print("Успешно подключились к прокси! (" .. currentProxyIndex .. "/" .. #proxies .. ")")
retryCount = 0
end
function onRequestConnect()
if not isProxyConnected() then
print("Прокси не подключен, отменяем соединение")
return false
end
end
local proxies = {}
local currentProxyIndex = 0
local maxRetries = 3
local retryCount = 0
function loadProxiesFromFile()
local filename = "accounts\\proxies.txt"
local file = io.open(filename, "r")
if not file then
print("Ошибка: не могу открыть файл " .. filename)
return false
end
for line in file:lines() do
line = line:gsub("%s+", "")
if line ~= "" then
-- Форматы: ip:port или ip:port:user:pass
table.insert(proxies, line)
end
end
file:close()
print("Загружено прокси: " .. #proxies)
return #proxies > 0
end
function connectToNextProxy()
if #proxies == 0 then
print("Нет доступных прокси!")
return false
end
currentProxyIndex = currentProxyIndex + 1
if currentProxyIndex > #proxies then
currentProxyIndex = 1
end
local proxyData = proxies[currentProxyIndex]
print("Попытка подключения к прокси " .. currentProxyIndex .. "/" .. #proxies .. ": " .. proxyData)
local parts = {}
for part in proxyData:gmatch("[^:]+") do
table.insert(parts, part)
end
if #parts == 2 then -- ip:port
return proxyConnect(proxyData, "", "")
elseif #parts == 4 then -- ip:port:user:pass
return proxyConnect(parts[1] .. ":" .. parts[2], parts[3], parts[4])
else
print("Неверный формат прокси: " .. proxyData)
return false
end
end
function onLoad()
if loadProxiesFromFile() then
connectToNextProxy()
else
print("Не удалось загрузить прокси, работа без прокси")
end
setRate(RATE_LUA, 100)
end
function onProxyError()
print("Ошибка прокси #" .. currentProxyIndex)
retryCount = retryCount + 1
if retryCount >= maxRetries then
print("Превышено количество попыток, пробуем следующую прокси")
retryCount = 0
wait(2000)
connectToNextProxy()
else
print("Повторная попытка (" .. retryCount .. "/" .. maxRetries .. ")")
wait(1000)
connectToNextProxy()
end
end
function onProxyConnect()
print("Успешно подключились к прокси! (" .. currentProxyIndex .. "/" .. #proxies .. ")")
retryCount = 0
end
function onRequestConnect()
if not isProxyConnected() then
print("Прокси не подключен, отменяем соединение")
return false
end
end