3566: Use map download url from info2.ddnet.tw (fixes #3546) r=heinrich5991 a=def-

which info2.ddnet.tw provides using a geolite db to provide a better
server for players in China

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [x] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-01-31 14:28:50 +00:00 committed by GitHub
commit a404be6702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;