39 TC_LOG_INFO(
"server.loading",
"Loading IP Location Database...");
41 std::string databaseFilePath =
sConfigMgr->GetStringDefault(
"IPLocationFile",
"");
42 if (databaseFilePath.empty())
46 std::ifstream databaseFile(databaseFilePath);
49 TC_LOG_ERROR(
"server.loading",
"IPLocation: No ip database file exists ({}).", databaseFilePath);
53 if (!databaseFile.is_open())
55 TC_LOG_ERROR(
"server.loading",
"IPLocation: Ip database file ({}) can not be opened.", databaseFilePath);
61 std::string countryCode;
62 std::string countryName;
64 while (databaseFile.good())
67 if (!std::getline(databaseFile, ipFrom,
','))
69 if (!std::getline(databaseFile, ipTo,
','))
71 if (!std::getline(databaseFile, countryCode,
','))
73 if (!std::getline(databaseFile, countryName,
'\n'))
77 countryName.erase(std::remove(countryName.begin(), countryName.end(),
'\r'), countryName.end());
78 countryName.erase(std::remove(countryName.begin(), countryName.end(),
'\n'), countryName.end());
81 ipFrom.erase(std::remove(ipFrom.begin(), ipFrom.end(),
'"'), ipFrom.end());
82 ipTo.erase(std::remove(ipTo.begin(), ipTo.end(),
'"'), ipTo.end());
83 countryCode.erase(std::remove(countryCode.begin(), countryCode.end(),
'"'), countryCode.end());
84 countryName.erase(std::remove(countryName.begin(), countryName.end(),
'"'), countryName.end());
97 _ipLocationStore.emplace_back(*from, *to, std::move(countryCode), std::move(countryName));
102 "Overlapping IP ranges detected in database file");
104 databaseFile.close();
111 boost::system::error_code error;
112 boost::asio::ip::address_v4 address = Trinity::Net::make_address_v4(ipAddress, error);
121 if (ip < itr->IpFrom)
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_INFO(filterType__,...)
std::optional< T > Optional
Optional helper class to wrap optional values within.
void strToLower(std::string &str)
IpLocationRecord const * GetLocationRecord(std::string const &ipAddress) const
static IpLocationStore * Instance()
std::vector< IpLocationRecord > _ipLocationStore
uint32 address_to_uint(boost::asio::ip::address_v4 const &address)