34 TC_LOG_INFO(
"server.loading",
"Loading IP Location Database...");
36 std::string databaseFilePath =
sConfigMgr->GetStringDefault(
"IPLocationFile",
"");
37 if (databaseFilePath.empty())
41 std::ifstream databaseFile(databaseFilePath);
44 TC_LOG_ERROR(
"server.loading",
"IPLocation: No ip database file exists ({}).", databaseFilePath);
48 if (!databaseFile.is_open())
50 TC_LOG_ERROR(
"server.loading",
"IPLocation: Ip database file ({}) can not be opened.", databaseFilePath);
56 std::string countryCode;
57 std::string countryName;
61 ipv6MappedMask <<= 32;
63 auto parseStringToIPv6 = [&](std::string
const& str) ->
Optional<std::array<uint8, 16>>
69 if (bnParser <= ipv4Max)
70 bnParser += ipv6MappedMask;
74 while (databaseFile.good())
77 if (!std::getline(databaseFile, ipFrom,
','))
79 if (!std::getline(databaseFile, ipTo,
','))
81 if (!std::getline(databaseFile, countryCode,
','))
83 if (!std::getline(databaseFile, countryName,
'\n'))
87 std::erase_if(countryName, [](
char c) {
return c ==
'\r' || c ==
'\n'; });
90 std::erase(ipFrom,
'"');
91 std::erase(ipTo,
'"');
92 std::erase(countryCode,
'"');
93 std::erase(countryName,
'"');
95 if (countryCode ==
"-")
109 _ipLocationStore.emplace_back(*from, *to, std::move(countryCode), std::move(countryName));
114 "Overlapping IP ranges detected in database file");
116 databaseFile.close();
123 boost::system::error_code error;
124 boost::asio::ip::address address = Trinity::Net::make_address(ipAddress, error);
128 std::array<uint8, 16> bytes = [&]() -> std::array<uint8, 16>
131 return address.to_v6().to_bytes();
133 return Trinity::Net::make_address_v6(Trinity::Net::v4_mapped, address.to_v4()).to_bytes();
140 if (bytes < itr->IpFrom)