Skip to content

Commit

Permalink
Don't add IP country if there is no IP-DB match, user shorter country…
Browse files Browse the repository at this point in the history
… format by default
  • Loading branch information
maksis committed Oct 18, 2020
1 parent fe8d4fb commit 3977fe0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion airdcpp/airdcpp/GeoIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ string GeoIP::getCountry(const string& ip) const {
&mmdb_error
);

if (mmdb_error == MMDB_SUCCESS && gai_error == 0) {
if (res.found_entry && mmdb_error == MMDB_SUCCESS && gai_error == 0) {
const string& setting = SETTING(COUNTRY_FORMAT);

ParamMap params;
Expand Down
2 changes: 1 addition & 1 deletion airdcpp/airdcpp/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ SettingsManager::SettingsManager() : connectionRegex("(\\d+(\\.\\d+)?)")
setDefault(ALLOW_MATCH_FULL_LIST, true);
setDefault(REPORT_ADDED_SOURCES, false);
setDefault(EXPAND_BUNDLES, false);
setDefault(COUNTRY_FORMAT, "%[2code] - %[name]");
setDefault(COUNTRY_FORMAT, "%[2code]");
setDefault(FORMAT_DIR_REMOTE_TIME, false);
setDefault(DISCONNECT_MIN_SOURCES, 2);
setDefault(USE_SLOW_DISCONNECTING_DEFAULT, true);
Expand Down
5 changes: 4 additions & 1 deletion windows/HubFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,8 @@ LRESULT HubFrame::onCustomDraw(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)

case CDDS_SUBITEM | CDDS_ITEMPREPAINT: {
if(SETTING(GET_USER_COUNTRY) && (ctrlUsers.findColumn(cd->iSubItem) == UserUtil::COLUMN_IP4 || ctrlUsers.findColumn(cd->iSubItem) == UserUtil::COLUMN_IP6)) {
auto isV6 = ctrlUsers.findColumn(cd->iSubItem) == UserUtil::COLUMN_IP6;

CRect rc;
ctrlUsers.GetSubItemRect((int)cd->nmcd.dwItemSpec, cd->iSubItem, LVIR_BOUNDS, rc);

Expand All @@ -1808,7 +1810,8 @@ LRESULT HubFrame::onCustomDraw(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
POINT p = { rc.left, top };

const auto ii = (ItemInfo*)cd->nmcd.lItemlParam;
auto countryInfo = FormatUtil::toCountryInfo(ii->onlineUser->getIdentity().getTcpConnectIp());
const auto userIp = isV6 ? ii->onlineUser->getIdentity().getIp6() : ii->onlineUser->getIdentity().getIp4();
auto countryInfo = FormatUtil::toCountryInfo(userIp);
ResourceLoader::flagImages.Draw(cd->nmcd.hdc, countryInfo.flagIndex, p, LVSIL_SMALL);

top = rc.top + (rc.Height() - WinUtil::getTextHeight(cd->nmcd.hdc) - 1)/2;
Expand Down

0 comments on commit 3977fe0

Please sign in to comment.