Add Filter for connecting players (fixes #1263)

This commit is contained in:
Dennis Felsing 2018-08-21 09:03:29 +02:00
parent 36a243e395
commit e2eb4a66dc
5 changed files with 56 additions and 13 deletions

View file

@ -147,7 +147,7 @@ bool CServerBrowser::SortCompareNumPlayers(int Index1, int Index2) const
{
CServerEntry *a = m_ppServerlist[Index1];
CServerEntry *b = m_ppServerlist[Index2];
return a->m_Info.m_NumPlayers < b->m_Info.m_NumPlayers;
return FilteredPlayers(a->m_Info) < FilteredPlayers(b->m_Info);
}
bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
@ -157,6 +157,32 @@ bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
return a->m_Info.m_NumClients < b->m_Info.m_NumClients;
}
int CServerBrowser::FilteredPlayers(const CServerInfo &Item) const
{
int NumPlayers = 0;
for(int i = 0; i < MAX_CLIENTS; i++)
{
const CServerInfo::CClient &Client = Item.m_aClients[i];
if(Client.m_aName[0] == '\0')
continue;
if(g_Config.m_BrFilterSpectators && !Client.m_Player)
continue;
if(g_Config.m_BrFilterFriends && Client.m_FriendState == IFriends::FRIEND_NO)
continue;
if(g_Config.m_BrFilterConnectingPlayers && str_comp(Client.m_aName, "(connecting)") == 0 && Client.m_aClan[0] == '\0' && Client.m_Country == -1 && Client.m_Score == 0)
continue;
NumPlayers++;
}
return NumPlayers;
}
void CServerBrowser::Filter()
{
int i = 0, p = 0;
@ -176,10 +202,9 @@ void CServerBrowser::Filter()
{
int Filtered = 0;
if(g_Config.m_BrFilterEmpty && ((g_Config.m_BrFilterSpectators && m_ppServerlist[i]->m_Info.m_NumPlayers == 0) || m_ppServerlist[i]->m_Info.m_NumClients == 0))
if(g_Config.m_BrFilterEmpty && FilteredPlayers(m_ppServerlist[i]->m_Info) == 0)
Filtered = 1;
else if(g_Config.m_BrFilterFull && ((g_Config.m_BrFilterSpectators && m_ppServerlist[i]->m_Info.m_NumPlayers == m_ppServerlist[i]->m_Info.m_MaxPlayers) ||
m_ppServerlist[i]->m_Info.m_NumClients == m_ppServerlist[i]->m_Info.m_MaxClients))
else if(g_Config.m_BrFilterFull && Players(m_ppServerlist[i]->m_Info) == Max(m_ppServerlist[i]->m_Info))
Filtered = 1;
else if(g_Config.m_BrFilterPw && m_ppServerlist[i]->m_Info.m_Flags&SERVER_FLAG_PASSWORD)
Filtered = 1;
@ -318,7 +343,7 @@ void CServerBrowser::Filter()
int CServerBrowser::SortHash() const
{
int i = g_Config.m_BrSort&0xf;
int i = g_Config.m_BrSort&0xff;
i |= g_Config.m_BrFilterEmpty<<4;
i |= g_Config.m_BrFilterFull<<5;
i |= g_Config.m_BrFilterSpectators<<6;
@ -331,7 +356,7 @@ int CServerBrowser::SortHash() const
i |= g_Config.m_BrFilterGametypeStrict<<13;
i |= g_Config.m_BrFilterUnfinishedMap<<14;
i |= g_Config.m_BrFilterCountry<<15;
i |= g_Config.m_BrFilterPing<<16;
i |= g_Config.m_BrFilterConnectingPlayers<<16;
return i;
}
@ -350,8 +375,7 @@ void CServerBrowser::Sort()
else if(g_Config.m_BrSort == IServerBrowser::SORT_MAP)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap));
else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMPLAYERS)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this,
g_Config.m_BrFilterSpectators ? &CServerBrowser::SortCompareNumPlayers : &CServerBrowser::SortCompareNumClients));
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareNumPlayers));
else if(g_Config.m_BrSort == IServerBrowser::SORT_GAMETYPE)
std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype));

View file

@ -68,6 +68,18 @@ public:
int NumServers() const { return m_NumServers; }
int FilteredPlayers(const CServerInfo &Item) const;
int Players(const CServerInfo &Item) const
{
return g_Config.m_BrFilterSpectators ? Item.m_NumPlayers : Item.m_NumClients;
}
int Max(const CServerInfo &Item) const
{
return g_Config.m_BrFilterSpectators ? Item.m_MaxPlayers : Item.m_MaxClients;
}
int NumSortedServers() const { return m_NumSortedServers; }
const CServerInfo *SortedGet(int Index) const;

View file

@ -112,6 +112,10 @@ public:
virtual int NumServers() const = 0;
virtual int FilteredPlayers(const CServerInfo &Item) const = 0;
virtual int Players(const CServerInfo &Item) const = 0;
virtual int Max(const CServerInfo &Item) const = 0;
virtual int NumSortedServers() const = 0;
virtual const CServerInfo *SortedGet(int Index) const = 0;

View file

@ -47,6 +47,7 @@ MACRO_CONFIG_INT(BrFilterPw, br_filter_pw, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT,
MACRO_CONFIG_INT(BrFilterPing, br_filter_ping, 999, 0, 999, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Ping to filter by in the server browser")
MACRO_CONFIG_STR(BrFilterGametype, br_filter_gametype, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Game types to filter")
MACRO_CONFIG_INT(BrFilterGametypeStrict, br_filter_gametype_strict, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Strict gametype filter")
MACRO_CONFIG_INT(BrFilterConnectingPlayers, br_filter_connecting_players, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter connecting players")
MACRO_CONFIG_STR(BrFilterServerAddress, br_filter_serveraddress, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server address to filter")
MACRO_CONFIG_INT(BrFilterPure, br_filter_pure, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard servers in browser")
MACRO_CONFIG_INT(BrFilterPureMap, br_filter_pure_map, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard maps in browser")

View file

@ -243,7 +243,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
{
int ItemIndex = i;
const CServerInfo *pItem = ServerBrowser()->SortedGet(ItemIndex);
NumPlayers += g_Config.m_BrFilterSpectators ? pItem->m_NumPlayers : pItem->m_NumClients;
NumPlayers += ServerBrowser()->FilteredPlayers(*pItem);
CUIRect Row;
CUIRect SelectHitBox;
@ -407,10 +407,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
DoButton_Icon(IMAGE_BROWSEICONS, SPRITE_BROWSE_HEART, &Icon);
}
if(g_Config.m_BrFilterSpectators)
str_format(aTemp, sizeof(aTemp), "%i/%i", pItem->m_NumPlayers, pItem->m_MaxPlayers);
else
str_format(aTemp, sizeof(aTemp), "%i/%i", pItem->m_NumClients, pItem->m_MaxClients);
str_format(aTemp, sizeof(aTemp), "%i/%i", ServerBrowser()->FilteredPlayers(*pItem), ServerBrowser()->Max(*pItem));
if(g_Config.m_BrFilterString[0] && (pItem->m_QuickSearchHit&IServerBrowser::QUICK_PLAYER))
TextRender()->TextColor(0.4f,0.4f,1.0f,1);
UI()->DoLabelScaled(&Button, aTemp, 12.0f, 1);
@ -670,6 +667,10 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
m_Popup = POPUP_COUNTRY;
}
ServerFilter.HSplitTop(20.0f, &Button, &ServerFilter);
if(DoButton_CheckBox(&g_Config.m_BrFilterConnectingPlayers, Localize("Filter connecting players"), g_Config.m_BrFilterConnectingPlayers, &Button))
g_Config.m_BrFilterConnectingPlayers ^= 1;
CUIRect ResetButton;
//ServerFilter.HSplitBottom(5.0f, &ServerFilter, 0);
@ -892,6 +893,7 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
g_Config.m_BrFilterPing = 999;
g_Config.m_BrFilterGametype[0] = 0;
g_Config.m_BrFilterGametypeStrict = 0;
g_Config.m_BrFilterConnectingPlayers = 1;
g_Config.m_BrFilterUnfinishedMap = 0;
g_Config.m_BrFilterServerAddress[0] = 0;
g_Config.m_BrFilterPure = 0;