Use map download url from info2.ddnet.tw (fixes #3546)

which info2.ddnet.tw provides using a geolite db to provide a better
server for players in China
This commit is contained in:
def 2021-01-31 11:15:09 +01:00
parent 697d03e5c3
commit b3c93b091a
2 changed files with 11 additions and 1 deletions

View file

@ -49,6 +49,7 @@ protected:
public:
char m_aNews[3000];
char m_aMapDownloadUrl[256];
int m_Points;
int64 m_ReconnectTime;

View file

@ -330,6 +330,7 @@ CClient::CClient() :
str_format(m_aDDNetInfoTmp, sizeof(m_aDDNetInfoTmp), DDNET_INFO ".%d.tmp", pid());
m_pDDNetInfoTask = NULL;
m_aNews[0] = '\0';
m_aMapDownloadUrl[0] = '\0';
m_Points = -1;
m_CurrentServerInfoRequestTime = -1;
@ -1743,7 +1744,8 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket)
char aUrl[256];
char aEscaped[256];
EscapeUrl(aEscaped, sizeof(aEscaped), aFilename);
str_format(aUrl, sizeof(aUrl), "%s/%s", g_Config.m_ClMapDownloadUrl, aEscaped);
bool UseConfigUrl = str_comp(g_Config.m_ClMapDownloadUrl, "https://maps2.ddnet.tw") != 0 || m_aMapDownloadUrl[0] == '\0';
str_format(aUrl, sizeof(aUrl), "%s/%s", UseConfigUrl ? g_Config.m_ClMapDownloadUrl : m_aMapDownloadUrl, aEscaped);
m_pMapdownloadTask = std::make_shared<CGetFile>(Storage(), aUrl, m_aMapdownloadFilename, IStorage::TYPE_SAVE, CTimeout{g_Config.m_ClMapDownloadConnectTimeoutMs, g_Config.m_ClMapDownloadLowSpeedLimit, g_Config.m_ClMapDownloadLowSpeedTime});
Engine()->AddJob(m_pMapdownloadTask);
@ -2529,6 +2531,13 @@ void CClient::LoadDDNetInfo()
str_copy(m_aNews, pNewsString, sizeof(m_aNews));
}
const json_value *pMapDownloadUrl = json_object_get(pDDNetInfo, "map-download-url");
if(pMapDownloadUrl->type == json_string)
{
const char *pMapDownloadUrlString = json_string_get(pMapDownloadUrl);
str_copy(m_aMapDownloadUrl, pMapDownloadUrlString, sizeof(m_aMapDownloadUrl));
}
const json_value *pPoints = json_object_get(pDDNetInfo, "points");
if(pPoints->type == json_integer)
m_Points = pPoints->u.integer;