From b3c93b091a54b7cd9cf891cbf1435913a64e882c Mon Sep 17 00:00:00 2001 From: def Date: Sun, 31 Jan 2021 11:15:09 +0100 Subject: [PATCH] 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 --- src/engine/client.h | 1 + src/engine/client/client.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/engine/client.h b/src/engine/client.h index 515f62269..595f83864 100644 --- a/src/engine/client.h +++ b/src/engine/client.h @@ -49,6 +49,7 @@ protected: public: char m_aNews[3000]; + char m_aMapDownloadUrl[256]; int m_Points; int64 m_ReconnectTime; diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index ba6e1e8f1..3fae59832 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -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(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;