Skip to content

Commit

Permalink
Merge pull request ddnet#7502 from Robyt3/Browser-CommunityFilter-Fixes
Browse files Browse the repository at this point in the history
Prevent community filters excluding all elements, fix server browser update on community filter change via console
  • Loading branch information
heinrich5991 authored Nov 19, 2023
2 parents 228810e + ccc470e commit b4567d6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/engine/client/serverbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1233,11 +1233,17 @@ void CServerBrowser::LoadDDNetServers()
m_CommunityServersByAddr.clear();

if(!m_pDDNetInfo)
{
CleanFilters();
return;
}

const json_value &Communities = (*m_pDDNetInfo)["communities"];
if(Communities.type != json_array)
{
CleanFilters();
return;
}

for(unsigned CommunityIndex = 0; CommunityIndex < Communities.u.array.length; ++CommunityIndex)
{
Expand Down Expand Up @@ -1524,6 +1530,7 @@ bool CFilterList::Empty() const

void CFilterList::Clean(const std::vector<const char *> &vpAllowedElements)
{
size_t NumFiltered = 0;
char aNewList[512];
aNewList[0] = '\0';

Expand All @@ -1534,10 +1541,15 @@ void CFilterList::Clean(const std::vector<const char *> &vpAllowedElements)
if(aNewList[0] != '\0')
str_append(aNewList, ",");
str_append(aNewList, pElement);
++NumFiltered;
}
}

str_copy(m_pFilter, aNewList, m_FilterSize);
// Prevent filter that would exclude all allowed elements
if(NumFiltered == vpAllowedElements.size())
m_pFilter[0] = '\0';
else
str_copy(m_pFilter, aNewList, m_FilterSize);
}

void CServerBrowser::CleanFilters()
Expand Down
9 changes: 6 additions & 3 deletions src/game/client/components/menus_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,6 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
// community filter
if((g_Config.m_UiPage == PAGE_INTERNET || g_Config.m_UiPage == PAGE_FAVORITES) && !ServerBrowser()->Communities().empty())
{
ServerBrowser()->CleanFilters();

CUIRect Row;
View.HSplitTop(6.0f, nullptr, &View);
View.HSplitTop(19.0f, &Row, &View);
Expand Down Expand Up @@ -1742,8 +1740,13 @@ void CMenus::ConchainFavoritesUpdate(IConsole::IResult *pResult, void *pUserData
void CMenus::ConchainCommunitiesUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
pfnCallback(pResult, pCallbackUserData);
CMenus *pThis = static_cast<CMenus *>(pUserData);
if(pResult->NumArguments() >= 1 && (g_Config.m_UiPage == PAGE_INTERNET || g_Config.m_UiPage == PAGE_FAVORITES))
((CMenus *)pUserData)->UpdateCommunityCache(true);
{
pThis->ServerBrowser()->CleanFilters();
pThis->UpdateCommunityCache(true);
pThis->Client()->ServerBrowserUpdate();
}
}

void CMenus::UpdateCommunityCache(bool Force)
Expand Down

0 comments on commit b4567d6

Please sign in to comment.