Add placeholder country/type for servers without community

Add a country "none" with tee flag (code `-1`) and a type "None" for all servers without community.

Previously, the country and type for these servers was unset and their handling special-cased, so any non-empty country/type filter would exclude servers without country/type information. Now individual countries/types can be excluded without also excluding all servers without community.

Closes #7961.
This commit is contained in:
Robert Müller 2024-02-11 13:35:46 +01:00
parent e4e4227709
commit f0e71219a9
2 changed files with 14 additions and 14 deletions

View file

@ -27,6 +27,9 @@
#include <engine/http.h>
#include <engine/storage.h>
static constexpr const char *COMMUNITY_COUNTRY_NONE = "none";
static constexpr const char *COMMUNITY_TYPE_NONE = "None";
class CSortWrap
{
typedef bool (CServerBrowser::*SortFunc)(int, int) const;
@ -1497,7 +1500,12 @@ void CServerBrowser::LoadDDNetServers()
}
// Add default none community
m_vCommunities.emplace_back(COMMUNITY_NONE, "None", SHA256_ZEROED, "");
{
CCommunity NoneCommunity(COMMUNITY_NONE, "None", SHA256_ZEROED, "");
NoneCommunity.m_vCountries.emplace_back(COMMUNITY_COUNTRY_NONE, -1);
NoneCommunity.m_vTypes.emplace_back(COMMUNITY_TYPE_NONE);
m_vCommunities.push_back(std::move(NoneCommunity));
}
// Remove unknown elements from exclude lists
CleanFilters();
@ -1543,8 +1551,8 @@ void CServerBrowser::UpdateServerCommunity(CServerInfo *pInfo) const
}
}
str_copy(pInfo->m_aCommunityId, COMMUNITY_NONE);
str_copy(pInfo->m_aCommunityCountry, "");
str_copy(pInfo->m_aCommunityType, "");
str_copy(pInfo->m_aCommunityCountry, COMMUNITY_COUNTRY_NONE);
str_copy(pInfo->m_aCommunityType, COMMUNITY_TYPE_NONE);
}
void CServerBrowser::UpdateServerRank(CServerInfo *pInfo) const
@ -1876,11 +1884,6 @@ void CExcludedCommunityCountryFilterList::Clear()
bool CExcludedCommunityCountryFilterList::Filtered(const char *pCountryName) const
{
// If the needle is not defined, we exclude it if there is any other
// exclusion, i.e. we only show those elements when the filter is empty.
if(pCountryName[0] == '\0')
return !Empty();
const auto Communities = m_CurrentCommunitiesGetter();
return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) {
if(!pCommunity->HasCountry(pCountryName))
@ -2020,11 +2023,6 @@ void CExcludedCommunityTypeFilterList::Clear()
bool CExcludedCommunityTypeFilterList::Filtered(const char *pTypeName) const
{
// If the needle is not defined, we exclude it if there is any other
// exclusion, i.e. we only show those elements when the filter is empty.
if(pTypeName[0] == '\0')
return !Empty();
const auto Communities = m_CurrentCommunitiesGetter();
return std::none_of(Communities.begin(), Communities.end(), [&](const CCommunity *pCommunity) {
if(!pCommunity->HasType(pTypeName))

View file

@ -724,7 +724,9 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
}
}
if(!m_CommunityCache.m_vpSelectableCountries.empty() || !m_CommunityCache.m_vpSelectableTypes.empty())
// countries and types filters (not shown if there are no countries and types, or if only the none community is selected)
if((!m_CommunityCache.m_vpSelectableCountries.empty() || !m_CommunityCache.m_vpSelectableTypes.empty()) &&
(m_CommunityCache.m_vpSelectedCommunities.size() != 1 || str_comp(m_CommunityCache.m_vpSelectedCommunities[0]->Id(), IServerBrowser::COMMUNITY_NONE) != 0))
{
const ColorRGBA ColorActive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.3f);
const ColorRGBA ColorInactive = ColorRGBA(0.0f, 0.0f, 0.0f, 0.15f);