From 0809eefc1c8e6b4f86c2044e141ba70598a0998e Mon Sep 17 00:00:00 2001 From: nheir Date: Sat, 15 Dec 2018 09:36:53 +0100 Subject: [PATCH] sort by real players/clients --- src/engine/client/serverbrowser_filter.cpp | 26 ++++++++++++++++++++-- src/engine/client/serverbrowser_filter.h | 2 ++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/engine/client/serverbrowser_filter.cpp b/src/engine/client/serverbrowser_filter.cpp index 9bb987f6c..42d591a7e 100644 --- a/src/engine/client/serverbrowser_filter.cpp +++ b/src/engine/client/serverbrowser_filter.cpp @@ -252,8 +252,12 @@ void CServerBrowserFilter::CServerFilter::Sort() std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowserFilter::CServerFilter::SortCompareMap)); break; case IServerBrowser::SORT_NUMPLAYERS: - std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, - (m_FilterInfo.m_SortHash&IServerBrowser::FILTER_SPECTATORS) ? &CServerBrowserFilter::CServerFilter::SortCompareNumPlayers : &CServerBrowserFilter::CServerFilter::SortCompareNumClients)); + if(!(m_FilterInfo.m_SortHash&IServerBrowser::FILTER_BOTS)) + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, + (m_FilterInfo.m_SortHash&IServerBrowser::FILTER_SPECTATORS) ? &CServerBrowserFilter::CServerFilter::SortCompareNumPlayers : &CServerBrowserFilter::CServerFilter::SortCompareNumClients)); + else + std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, + (m_FilterInfo.m_SortHash&IServerBrowser::FILTER_SPECTATORS) ? &CServerBrowserFilter::CServerFilter::SortCompareNumRealPlayers : &CServerBrowserFilter::CServerFilter::SortCompareNumRealClients)); break; case IServerBrowser::SORT_GAMETYPE: std::stable_sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowserFilter::CServerFilter::SortCompareGametype)); @@ -302,6 +306,15 @@ bool CServerBrowserFilter::CServerFilter::SortCompareNumPlayers(int Index1, int (a->m_Info.m_NumPlayers == b->m_Info.m_NumPlayers && !(a->m_Info.m_Flags&IServerBrowser::FLAG_PURE) && (b->m_Info.m_Flags&IServerBrowser::FLAG_PURE)); } +bool CServerBrowserFilter::CServerFilter::SortCompareNumRealPlayers(int Index1, int Index2) const +{ + CServerEntry *a = m_pServerBrowserFilter->m_ppServerlist[Index1]; + CServerEntry *b = m_pServerBrowserFilter->m_ppServerlist[Index2]; + // are ia allowed in vanilla ? + return (a->m_Info.m_NumPlayers - a->m_Info.m_NumBotPlayers) < (b->m_Info.m_NumPlayers - b->m_Info.m_NumBotPlayers) || + ((a->m_Info.m_NumPlayers - a->m_Info.m_NumBotPlayers) == (b->m_Info.m_NumPlayers - b->m_Info.m_NumBotPlayers) && !(a->m_Info.m_Flags&IServerBrowser::FLAG_PURE) && (b->m_Info.m_Flags&IServerBrowser::FLAG_PURE)); +} + bool CServerBrowserFilter::CServerFilter::SortCompareNumClients(int Index1, int Index2) const { CServerEntry *a = m_pServerBrowserFilter->m_ppServerlist[Index1]; @@ -310,6 +323,15 @@ bool CServerBrowserFilter::CServerFilter::SortCompareNumClients(int Index1, int (a->m_Info.m_NumClients == b->m_Info.m_NumClients && !(a->m_Info.m_Flags&IServerBrowser::FLAG_PURE) && (b->m_Info.m_Flags&IServerBrowser::FLAG_PURE)); } +bool CServerBrowserFilter::CServerFilter::SortCompareNumRealClients(int Index1, int Index2) const +{ + CServerEntry *a = m_pServerBrowserFilter->m_ppServerlist[Index1]; + CServerEntry *b = m_pServerBrowserFilter->m_ppServerlist[Index2]; + // are ia allowed in vanilla ? in spec ? + return (a->m_Info.m_NumClients - a->m_Info.m_NumBotPlayers - a->m_Info.m_NumBotSpectators) < (b->m_Info.m_NumClients - b->m_Info.m_NumBotPlayers - b->m_Info.m_NumBotSpectators) || + ((a->m_Info.m_NumClients - a->m_Info.m_NumBotPlayers - a->m_Info.m_NumBotSpectators) < (b->m_Info.m_NumClients - b->m_Info.m_NumBotPlayers - b->m_Info.m_NumBotSpectators) && !(a->m_Info.m_Flags&IServerBrowser::FLAG_PURE) && (b->m_Info.m_Flags&IServerBrowser::FLAG_PURE)); +} + // CServerBrowserFilter void CServerBrowserFilter::Init(IFriends *pFriends, const char *pNetVersion) { diff --git a/src/engine/client/serverbrowser_filter.h b/src/engine/client/serverbrowser_filter.h index 621d506e7..ebb98eac2 100644 --- a/src/engine/client/serverbrowser_filter.h +++ b/src/engine/client/serverbrowser_filter.h @@ -42,7 +42,9 @@ public: bool SortComparePing(int Index1, int Index2) const; bool SortCompareGametype(int Index1, int Index2) const; bool SortCompareNumPlayers(int Index1, int Index2) const; + bool SortCompareNumRealPlayers(int Index1, int Index2) const; bool SortCompareNumClients(int Index1, int Index2) const; + bool SortCompareNumRealClients(int Index1, int Index2) const; }; //