about summary refs log tree commit diff
path: root/src/engine/client
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-20 15:33:49 +0100
committeroy <Tom_Adams@web.de>2011-03-20 15:33:49 +0100
commit96808a11451f2ccf22346253bd22f8f559207ac8 (patch)
treea91ecb0ea18cff36e8515f234c5028c6c1c1b628 /src/engine/client
parent2547bfa4fcc8916a47eceb9a929fe73c8a1d83b9 (diff)
downloadzcatch-96808a11451f2ccf22346253bd22f8f559207ac8.tar.gz
zcatch-96808a11451f2ccf22346253bd22f8f559207ac8.zip
made it possible to just show the number of player slots of a server (instead of client ones). Closes #68
Diffstat (limited to 'src/engine/client')
-rw-r--r--src/engine/client/client.cpp26
-rw-r--r--src/engine/client/srvbrowse.cpp19
-rw-r--r--src/engine/client/srvbrowse.h1
3 files changed, 32 insertions, 14 deletions
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index 723b8791..cb477304 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -1018,8 +1018,12 @@ const char *CClient::LoadMapSearch(const char *pMapName, int WantedCrc)
 
 int CClient::PlayerScoreComp(const void *a, const void *b)
 {
-	CServerInfo::CPlayer *p0 = (CServerInfo::CPlayer *)a;
-	CServerInfo::CPlayer *p1 = (CServerInfo::CPlayer *)b;
+	CServerInfo::CClient *p0 = (CServerInfo::CClient *)a;
+	CServerInfo::CClient *p1 = (CServerInfo::CClient *)b;
+	if(p0->m_Player && !p1->m_Player)
+		return -1;
+	if(!p0->m_Player && p1->m_Player)
+		return 1;
 	if(p0->m_Score == p1->m_Score)
 		return 0;
 	if(p0->m_Score < p1->m_Score)
@@ -1106,27 +1110,31 @@ void CClient::ProcessConnlessPacket(CNetChunk *pPacket)
 		Info.m_Flags = str_toint(Up.GetString());
 		Info.m_NumPlayers = str_toint(Up.GetString());
 		Info.m_MaxPlayers = str_toint(Up.GetString());
+		Info.m_NumClients = str_toint(Up.GetString());
+		Info.m_MaxClients = str_toint(Up.GetString());
 
 		// don't add invalid info to the server browser list
-		if(Info.m_NumPlayers < 0 || Info.m_NumPlayers > MAX_CLIENTS || Info.m_MaxPlayers < 0 || Info.m_MaxPlayers > MAX_CLIENTS)
+		if(Info.m_NumClients < 0 || Info.m_NumClients > MAX_CLIENTS || Info.m_MaxClients < 0 || Info.m_MaxClients > MAX_CLIENTS ||
+			Info.m_NumPlayers < 0 || Info.m_NumPlayers > Info.m_NumClients || Info.m_MaxPlayers < 0 || Info.m_MaxPlayers > Info.m_MaxClients)
 			return;
 
 		str_format(Info.m_aAddress, sizeof(Info.m_aAddress), "%d.%d.%d.%d:%d",
 			pPacket->m_Address.ip[0], pPacket->m_Address.ip[1], pPacket->m_Address.ip[2],
 			pPacket->m_Address.ip[3], pPacket->m_Address.port);
 
-		for(int i = 0; i < Info.m_NumPlayers; i++)
+		for(int i = 0; i < Info.m_NumClients; i++)
 		{
-			str_copy(Info.m_aPlayers[i].m_aName, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aPlayers[i].m_aName));
-			str_copy(Info.m_aPlayers[i].m_aClan, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aPlayers[i].m_aClan));
-			Info.m_aPlayers[i].m_Country = GameClient()->GetCountryIndex(str_toint(Up.GetString()));
-			Info.m_aPlayers[i].m_Score = str_toint(Up.GetString());
+			str_copy(Info.m_aClients[i].m_aName, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aClients[i].m_aName));
+			str_copy(Info.m_aClients[i].m_aClan, Up.GetString(CUnpacker::SANITIZE_CC|CUnpacker::SKIP_START_WHITESPACES), sizeof(Info.m_aClients[i].m_aClan));
+			Info.m_aClients[i].m_Country = GameClient()->GetCountryIndex(str_toint(Up.GetString()));
+			Info.m_aClients[i].m_Score = str_toint(Up.GetString());
+			Info.m_aClients[i].m_Player = str_toint(Up.GetString()) != 0 ? true : false;
 		}
 
 		if(!Up.Error())
 		{
 			// sort players
-			qsort(Info.m_aPlayers, Info.m_NumPlayers, sizeof(*Info.m_aPlayers), PlayerScoreComp);
+			qsort(Info.m_aClients, Info.m_NumClients, sizeof(*Info.m_aClients), PlayerScoreComp);
 
 			if(net_addr_comp(&m_ServerAddress, &pPacket->m_Address) == 0)
 			{
diff --git a/src/engine/client/srvbrowse.cpp b/src/engine/client/srvbrowse.cpp
index fb350c43..506d2e02 100644
--- a/src/engine/client/srvbrowse.cpp
+++ b/src/engine/client/srvbrowse.cpp
@@ -115,6 +115,13 @@ bool CServerBrowser::SortCompareNumPlayers(int Index1, int Index2) const
 	return a->m_Info.m_NumPlayers < b->m_Info.m_NumPlayers;
 }
 
+bool CServerBrowser::SortCompareNumClients(int Index1, int Index2) const
+{
+	CServerEntry *a = m_ppServerlist[Index1];
+	CServerEntry *b = m_ppServerlist[Index2];
+	return a->m_Info.m_NumClients < b->m_Info.m_NumClients;
+}
+
 void CServerBrowser::Filter()
 {
 	int i = 0, p = 0;
@@ -134,9 +141,10 @@ void CServerBrowser::Filter()
 	{
 		int Filtered = 0;
 
-		if(g_Config.m_BrFilterEmpty && m_ppServerlist[i]->m_Info.m_NumPlayers == 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))
 			Filtered = 1;
-		else if(g_Config.m_BrFilterFull && m_ppServerlist[i]->m_Info.m_NumPlayers == m_ppServerlist[i]->m_Info.m_MaxPlayers)
+		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))
 			Filtered = 1;
 		else if(g_Config.m_BrFilterPw && m_ppServerlist[i]->m_Info.m_Flags&SERVER_FLAG_PASSWORD)
 			Filtered = 1;
@@ -187,8 +195,8 @@ void CServerBrowser::Filter()
 			// match against players
 			for(p = 0; p < m_ppServerlist[i]->m_Info.m_NumPlayers; p++)
 			{
-				if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aPlayers[p].m_aName, g_Config.m_BrFilterString) ||
-					str_find_nocase(m_ppServerlist[i]->m_Info.m_aPlayers[p].m_aClan, g_Config.m_BrFilterString))
+				if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aClients[p].m_aName, g_Config.m_BrFilterString) ||
+					str_find_nocase(m_ppServerlist[i]->m_Info.m_aClients[p].m_aClan, g_Config.m_BrFilterString))
 				{
 					MatchFound = 1;
 					m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_PLAYER;
@@ -241,7 +249,8 @@ void CServerBrowser::Sort()
 	else if(g_Config.m_BrSort == IServerBrowser::SORT_MAP)
 		std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareMap));
 	else if(g_Config.m_BrSort == IServerBrowser::SORT_NUMPLAYERS)
-		std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareNumPlayers));
+		std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this,
+					g_Config.m_BrFilterSpectators ? &CServerBrowser::SortCompareNumPlayers : &CServerBrowser::SortCompareNumClients));
 	else if(g_Config.m_BrSort == IServerBrowser::SORT_GAMETYPE)
 		std::sort(m_pSortedServerlist, m_pSortedServerlist+m_NumSortedServers, SortWrap(this, &CServerBrowser::SortCompareGametype));
 
diff --git a/src/engine/client/srvbrowse.h b/src/engine/client/srvbrowse.h
index c00ce752..b3d0f9ed 100644
--- a/src/engine/client/srvbrowse.h
+++ b/src/engine/client/srvbrowse.h
@@ -93,6 +93,7 @@ private:
 	bool SortComparePing(int Index1, int Index2) const;
 	bool SortCompareGametype(int Index1, int Index2) const;
 	bool SortCompareNumPlayers(int Index1, int Index2) const;
+	bool SortCompareNumClients(int Index1, int Index2) const;
 
 	//
 	void Filter();