From 9eca91de748ef35594c2a9be8dac24a64da1d956 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Sat, 24 Apr 2021 15:48:27 +0200 Subject: [PATCH] Special case China as its own continent for ping estimation It has an exceptionally bad connection to the outside due to the Great Firewall of China: https://en.wikipedia.org/w/index.php?title=Great_Firewall&oldid=1019589632 --- src/engine/client/serverbrowser.cpp | 7 ++++--- src/engine/serverbrowser.h | 5 +++++ src/game/client/components/menus_browser.cpp | 1 + src/test/serverinfo.cpp | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 31a103d13..893c091f7 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -1559,7 +1559,7 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString) return true; } // ISO continent code. Allow antarctica, but treat it as unknown. - static const char LOCATIONS[][3] = { + static const char LOCATIONS[][6] = { "an", // LOC_UNKNOWN "af", // LOC_AFRICA "as", // LOC_ASIA @@ -1567,10 +1567,11 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString) "eu", // LOC_EUROPE "na", // LOC_NORTH_AMERICA "sa", // LOC_SOUTH_AMERICA + "as:cn", // LOC_CHINA }; - for(unsigned i = 0; i < sizeof(LOCATIONS) / sizeof(LOCATIONS[0]); i++) + for(int i = sizeof(LOCATIONS) / sizeof(LOCATIONS[0]) - 1; i >= 0; i--) { - if(str_comp_num(pString, LOCATIONS[i], 2) == 0) + if(str_startswith(pString, LOCATIONS[i])) { *pResult = i; return false; diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index 6bb89a573..ccc95f678 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -23,6 +23,11 @@ public: LOC_EUROPE, LOC_NORTH_AMERICA, LOC_SOUTH_AMERICA, + // Special case China because it has an exceptionally bad + // connection to the outside due to the Great Firewall of + // China: + // https://en.wikipedia.org/w/index.php?title=Great_Firewall&oldid=1019589632 + LOC_CHINA, NUM_LOCS, }; diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 2eea36e66..d9ed87491 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -46,6 +46,7 @@ void FormatServerbrowserPing(char *pBuffer, int BufferLength, const CServerInfo "EUR", // LOC_EUROPE // Localize("EUR") "NA", // LOC_NORTH_AMERICA // Localize("NA") "SA", // LOC_SOUTH_AMERICA // Localize("SA") + "CHN", // LOC_CHINA // Localize("CHN") }; dbg_assert(0 <= pInfo->m_Location && pInfo->m_Location < CServerInfo::NUM_LOCS, "location out of range"); str_format(pBuffer, BufferLength, "%s", Localize(LOCATION_NAMES[pInfo->m_Location])); diff --git a/src/test/serverinfo.cpp b/src/test/serverinfo.cpp index 48692cbf8..b8ef86a6c 100644 --- a/src/test/serverinfo.cpp +++ b/src/test/serverinfo.cpp @@ -21,6 +21,8 @@ TEST(ServerInfo, ParseLocation) EXPECT_EQ(Result, CServerInfo::LOC_SOUTH_AMERICA); EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "as:e")); EXPECT_EQ(Result, CServerInfo::LOC_ASIA); + EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "as:cn")); + EXPECT_EQ(Result, CServerInfo::LOC_CHINA); EXPECT_FALSE(CServerInfo::ParseLocation(&Result, "oc")); EXPECT_EQ(Result, CServerInfo::LOC_AUSTRALIA); }