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
This commit is contained in:
heinrich5991 2021-04-24 15:48:27 +02:00
parent acbaa87835
commit 9eca91de74
4 changed files with 12 additions and 3 deletions

View file

@ -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;

View file

@ -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,
};

View file

@ -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]));

View file

@ -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);
}