require 'addon'
local http = require("socket.http")
local servers = { -- Сервера, которые нужно пинговать
["185.169.134.3:7777"] = "Phoenix",
["185.169.134.4:7777"] = "Tucson",
["185.169.134.43:7777"] = "Scottdale",
["185.169.134.44:7777"] = "Chandler",
["185.169.134.45:7777"] = "Brainburg",
["185.169.134.5:7777"] = "Saint-Rose",
["185.169.134.59:7777"] = "Mesa",
["185.169.134.61:7777"] = "Red-Rock",
["185.169.134.107:7777"] = "Yuma",
["185.169.134.109:7777"] = "Surprise",
["185.169.134.166:7777"] = "Prescott",
["185.169.134.171:7777"] = "Glendale",
["185.169.134.172:7777"] = "Kingman",
["185.169.134.173:7777"] = "Winslow",
["185.169.134.174:7777"] = "Payson",
["80.66.82.191:7777"] = "Gilbert",
["80.66.82.190:7777"] = "Show-Low",
["80.66.82.188:7777"] = "Casa-Grande",
["80.66.82.168:7777"] = "Page",
["80.66.82.159:7777"] = "Sun-City",
["80.66.82.200:7777"] = "Queen-Creek",
["80.66.82.144:7777"] = "Sedona",
["80.66.82.132:7777"] = "Holiday",
["80.66.82.128:7777"] = "Wednesday",
["80.66.82.113:7777"] = "Yava",
["80.66.82.82:7777"] = "Faraway",
["80.66.82.54:7777"] = "Christmas",
["80.66.82.87:7777"] = "Bumble-Bee",
["80.66.82.39:7777"] = "Mirage",
["80.66.82.33:7777"] = "Love",
["80.66.82.22:7777"] = "Drake"
}
local function ping()
local server_ip = getServerAddress():match("(.+):.+")
local req = "http://" .. server_ip .. ":80"
local _, code, _, _ = http.request(req)
code = tonumber(code) or 0
print(string.format('Server ping %s (code: %d)', (code ~= 200 and code ~= 404) and '\x1b[1;31mfailed\x1b[0m' or '\x1b[1;32msuccessfull\x1b[0m', code))
if code ~= 200 and code ~= 404 then
newTask(ping, 2500)
end
end
function onRequestConnect()
if servers[getServerAddress()] then
ping()
end
end