4576: HTTP Serverbrowser: Quit faster (fixes #4563) r=heinrich5991 a=def-

```
[2022-01-08 09:57:03][serverbrowse_http]: found master, url='https://master1.ddnet.tw/ddnet/15/servers.json' time=54ms
[2022-01-08 09:57:03][client]: disconnecting. reason='unknown'
[2022-01-08 09:57:03][http]: https://master2.ddnet.tw/ddnet/15/servers.json failed. libcurl error: Callback aborted
[2022-01-08 09:57:03][serverbrowse_http]: master chooser aborted
```

Not instantaneous but much faster, depends on how often curl calls the PROGRESSFUNCTION.

<!-- 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
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] 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)


4670: Lib updates r=heinrich5991 a=def-

curl 7.79.0 -> 7.81.0
freetype 2.11.0 -> 2.11.1
sqlite 3.36.0 -> 3.37.2
ffmpeg 4.4 -> 5.0
websockets 4.2 -> 4.3

<!-- 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
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] 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)


4671: Update Chinese translations (by cheeser0613) r=heinrich5991 a=def-

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

## Checklist

- [ ] 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
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] 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: Dennis Felsing <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2022-02-07 11:01:38 +00:00 committed by GitHub
commit d7ed57fa3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 35 deletions

View file

@ -2633,11 +2633,11 @@ if(CLIENT AND DMGBUILD)
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/ddnet-libs/sdl/${LIB_DIR}/SDL2.framework ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/SDL2.framework
${DMG_DISCORD_COPY_COMMAND}
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/freetype/${LIB_DIR}/libfreetype.6.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavcodec.58.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavformat.58.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavutil.56.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libswresample.3.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libswscale.5.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavcodec.59.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavformat.59.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libavutil.57.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libswresample.4.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/ddnet-libs/ffmpeg/${LIB_DIR}/libswscale.6.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/libsteam_api.dylib ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/Frameworks/
COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/scripts/darwin_strip_rpath.py ${CMAKE_OTOOL} ${CMAKE_INSTALL_NAME_TOOL} ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/MacOS/${TARGET_CLIENT}
COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath @loader_path/../Frameworks ${DMG_TMPDIR}/${TARGET_CLIENT}.app/Contents/MacOS/${TARGET_CLIENT}

View file

@ -12,35 +12,35 @@ endif()
set_extra_dirs_lib(FFMPEG ffmpeg)
find_library(AVCODEC_LIBRARY
NAMES avcodec.58 avcodec libavcodec
NAMES avcodec.59 avcodec libavcodec
HINTS ${HINTS_FFMPEG_LIBDIR} ${PC_AVCODEC_LIBRARY_DIRS}
PATHS ${PATHS_AVCODEC_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
)
find_library(AVFORMAT_LIBRARY
NAMES avformat.58 avformat libavformat
NAMES avformat.59 avformat libavformat
HINTS ${HINTS_FFMPEG_LIBDIR} ${PC_AVFORMAT_LIBRARY_DIRS}
PATHS ${PATHS_AVFORMAT_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
)
find_library(AVUTIL_LIBRARY
NAMES avutil.56 avutil libavutil
NAMES avutil.57 avutil libavutil
HINTS ${HINTS_FFMPEG_LIBDIR} ${PC_AVUTIL_LIBRARY_DIRS}
PATHS ${PATHS_AVUTIL_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
)
find_library(SWSCALE_LIBRARY
NAMES swscale.5 swscale libswscale
NAMES swscale.6 swscale libswscale
HINTS ${HINTS_FFMPEG_LIBDIR} ${PC_SWSCALE_LIBRARY_DIRS}
PATHS ${PATHS_SWSCALE_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
)
find_library(SWRESAMPLE_LIBRARY
NAMES swresample.3 swresample libswresample
NAMES swresample.4 swresample libswresample
HINTS ${HINTS_FFMPEG_LIBDIR} ${PC_SWRESAMPLE_LIBRARY_DIRS}
PATHS ${PATHS_SWRESAMPLE_LIBDIR}
${CROSSCOMPILING_NO_CMAKE_SYSTEM_PATH}
@ -150,19 +150,19 @@ set(FFMPEG_COPY_FILES)
if(FFMPEG_BUNDLED)
if(TARGET_OS STREQUAL "windows")
set(FFMPEG_COPY_FILES
"${EXTRA_FFMPEG_LIBDIR}/avcodec-58.dll"
"${EXTRA_FFMPEG_LIBDIR}/avformat-58.dll"
"${EXTRA_FFMPEG_LIBDIR}/avutil-56.dll"
"${EXTRA_FFMPEG_LIBDIR}/swresample-3.dll"
"${EXTRA_FFMPEG_LIBDIR}/swscale-5.dll"
"${EXTRA_FFMPEG_LIBDIR}/avcodec-59.dll"
"${EXTRA_FFMPEG_LIBDIR}/avformat-59.dll"
"${EXTRA_FFMPEG_LIBDIR}/avutil-57.dll"
"${EXTRA_FFMPEG_LIBDIR}/swresample-4.dll"
"${EXTRA_FFMPEG_LIBDIR}/swscale-6.dll"
)
elseif(TARGET_OS STREQUAL "mac")
set(FFMPEG_COPY_FILES
"${EXTRA_FFMPEG_LIBDIR}/libavcodec.58.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libavformat.58.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libavutil.56.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libswresample.3.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libswscale.5.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libavcodec.59.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libavformat.59.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libavutil.57.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libswresample.4.dylib"
"${EXTRA_FFMPEG_LIBDIR}/libswscale.6.dylib"
)
endif()
endif()

View file

@ -33,7 +33,7 @@ if(WEBSOCKETS_FOUND)
if(TARGET_OS STREQUAL "windows")
set(WEBSOCKETS_COPY_FILES "${EXTRA_WEBSOCKETS_LIBDIR}/libwebsockets.dll")
elseif(TARGET_OS STREQUAL "mac")
set(WEBSOCKETS_COPY_FILES "${EXTRA_WEBSOCKETS_LIBDIR}/libwebsockets.18.dylib")
set(WEBSOCKETS_COPY_FILES "${EXTRA_WEBSOCKETS_LIBDIR}/libwebsockets.19.dylib")
endif()
endif()
endif()

View file

@ -15,6 +15,7 @@
# 2021-06-01 TsFreddie
# 2021-11-19 cheeser0613
# 2021-12-21 cheeser0613
# 2022-02-07 cheeser0613
##### /authors #####
##### translated strings #####
@ -1360,4 +1361,4 @@ Chat command (e.g. showall 1)
== 聊天指令 (例如: showall 1)
Windowed fullscreen
==
== 窗口化全屏

View file

@ -8,6 +8,7 @@
# 2021-06-01 TsFreddie
# 2021-11-19 cheeser0613
# 2021-12-21 cheeser0613
# 2022-02-07 cheeser0613
##### /authors #####
##### translated strings #####
@ -1353,4 +1354,4 @@ Chat command (e.g. showall 1)
== 聊天指令 (例如: showall 1)
Windowed fullscreen
==
== 視窗化全螢幕

@ -1 +1 @@
Subproject commit b917d9a3010f67f6cb77eed68512c05156b1cd65
Subproject commit 239dc15f4fdc98dd709d1fa313c389ae04ad72aa

View file

@ -23,7 +23,7 @@ public:
MAX_URLS = 16,
};
CChooseMaster(IEngine *pEngine, VALIDATOR pfnValidator, const char **ppUrls, int NumUrls, int PreviousBestIndex);
virtual ~CChooseMaster() {}
virtual ~CChooseMaster();
bool GetBestUrl(const char **pBestUrl) const;
void Reset();
@ -44,13 +44,17 @@ private:
};
class CJob : public IJob
{
LOCK m_Lock;
std::shared_ptr<CData> m_pData;
std::unique_ptr<CHead> m_pHead PT_GUARDED_BY(m_Lock);
std::unique_ptr<CGet> m_pGet PT_GUARDED_BY(m_Lock);
virtual void Run();
public:
CJob(std::shared_ptr<CData> pData) :
m_pData(std::move(pData)) {}
virtual ~CJob() {}
m_pData(std::move(pData)) { m_Lock = lock_create(); }
virtual ~CJob() { lock_destroy(m_Lock); }
void Abort();
};
IEngine *m_pEngine;
@ -76,6 +80,14 @@ CChooseMaster::CChooseMaster(IEngine *pEngine, VALIDATOR pfnValidator, const cha
}
}
CChooseMaster::~CChooseMaster()
{
if(m_pJob)
{
m_pJob->Abort();
}
}
int CChooseMaster::GetBestIndex() const
{
int BestIndex = m_pData->m_BestIndex.load();
@ -113,6 +125,21 @@ void CChooseMaster::Refresh()
m_pEngine->AddJob(m_pJob = std::make_shared<CJob>(m_pData));
}
void CChooseMaster::CJob::Abort()
{
lock_wait(m_Lock);
if(m_pHead != nullptr)
{
m_pHead->Abort();
}
if(m_pGet != nullptr)
{
m_pGet->Abort();
}
lock_unlock(m_Lock);
}
void CChooseMaster::CJob::Run()
{
// Check masters in a random order.
@ -139,21 +166,37 @@ void CChooseMaster::CJob::Run()
{
aTimeMs[i] = -1;
const char *pUrl = m_pData->m_aaUrls[aRandomized[i]];
CHead Head(pUrl, Timeout, HTTPLOG::FAILURE);
IEngine::RunJobBlocking(&Head);
if(Head.State() != HTTP_DONE)
CHead *pHead = new CHead(pUrl, Timeout, HTTPLOG::FAILURE);
lock_wait(m_Lock);
m_pHead = std::unique_ptr<CHead>(pHead);
lock_unlock(m_Lock);
IEngine::RunJobBlocking(pHead);
if(pHead->State() == HTTP_ABORTED)
{
dbg_msg("serverbrowse_http", "master chooser aborted");
return;
}
if(pHead->State() != HTTP_DONE)
{
continue;
}
int64_t StartTime = time_get_microseconds();
CGet Get(pUrl, Timeout, HTTPLOG::FAILURE);
IEngine::RunJobBlocking(&Get);
CGet *pGet = new CGet(pUrl, Timeout, HTTPLOG::FAILURE);
lock_wait(m_Lock);
m_pGet = std::unique_ptr<CGet>(pGet);
lock_unlock(m_Lock);
IEngine::RunJobBlocking(pGet);
int Time = (time_get_microseconds() - StartTime) / 1000;
if(Get.State() != HTTP_DONE)
if(pHead->State() == HTTP_ABORTED)
{
dbg_msg("serverbrowse_http", "master chooser aborted");
return;
}
if(pGet->State() != HTTP_DONE)
{
continue;
}
json_value *pJson = Get.ResultJson();
json_value *pJson = pGet->ResultJson();
if(!pJson)
{
continue;
@ -195,7 +238,7 @@ class CServerBrowserHttp : public IServerBrowserHttp
{
public:
CServerBrowserHttp(IEngine *pEngine, IConsole *pConsole, const char **ppUrls, int NumUrls, int PreviousBestIndex);
virtual ~CServerBrowserHttp() {}
virtual ~CServerBrowserHttp();
void Update();
bool IsRefreshing() { return m_State != STATE_DONE; }
void Refresh();
@ -261,6 +304,15 @@ CServerBrowserHttp::CServerBrowserHttp(IEngine *pEngine, IConsole *pConsole, con
{
m_pChooseMaster->Refresh();
}
CServerBrowserHttp::~CServerBrowserHttp()
{
if(m_pGetServers != nullptr)
{
m_pGetServers->Abort();
}
}
void CServerBrowserHttp::Update()
{
if(m_State == STATE_WANTREFRESH)