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();