about summary refs log tree commit diff
path: root/src/engine
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-18 19:03:13 +0100
committeroy <Tom_Adams@web.de>2011-03-18 19:03:13 +0100
commita8bf857c6877679ff943ad9dbfba5aac1870ccae (patch)
treed6ec05d43c840242e8036af662c2d38cf189670a /src/engine
parenta3c9ec889f487c2de307f41904454e85b0efa21c (diff)
downloadzcatch-a8bf857c6877679ff943ad9dbfba5aac1870ccae.tar.gz
zcatch-a8bf857c6877679ff943ad9dbfba5aac1870ccae.zip
improved server browser list resorting and made search work on IP addresses. Closes #482
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/client.h1
-rw-r--r--src/engine/client/client.cpp21
-rw-r--r--src/engine/client/client.h4
-rw-r--r--src/engine/client/srvbrowse.cpp65
-rw-r--r--src/engine/client/srvbrowse.h2
-rw-r--r--src/engine/shared/config_variables.h2
6 files changed, 55 insertions, 40 deletions
diff --git a/src/engine/client.h b/src/engine/client.h
index 539bed44..31b6f794 100644
--- a/src/engine/client.h
+++ b/src/engine/client.h
@@ -80,6 +80,7 @@ public:
 	virtual void DemoRecorder_HandleAutoStart() = 0;
 	virtual void DemoRecorder_Stop() = 0;
 	virtual void AutoScreenshot_Start() = 0;
+	virtual void ServerBrowserUpdate() = 0;
 
 	// networking
 	virtual void EnterGame() = 0;
diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp
index 49abd2e9..7277cecd 100644
--- a/src/engine/client/client.cpp
+++ b/src/engine/client/client.cpp
@@ -1760,7 +1760,8 @@ void CClient::Update()
 	MasterServer()->Update();
 
 	// update the server browser
-	m_ServerBrowser.Update();
+	m_ServerBrowser.Update(m_ResortServerBrowser);
+	m_ResortServerBrowser = false;
 }
 
 void CClient::VersionUpdate()
@@ -2234,6 +2235,18 @@ void CClient::Con_StopRecord(IConsole::IResult *pResult, void *pUserData)
 	pSelf->DemoRecorder_Stop();
 }
 
+void CClient::ServerBrowserUpdate()
+{
+	m_ResortServerBrowser = true;
+}
+
+void CClient::ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
+{
+	pfnCallback(pResult, pCallbackUserData);
+	if(pResult->NumArguments())
+		((CClient *)pUserData)->ServerBrowserUpdate();
+}
+
 void CClient::RegisterCommands()
 {
 	m_pConsole = Kernel()->RequestInterface<IConsole>();
@@ -2260,8 +2273,12 @@ void CClient::RegisterCommands()
 	m_pConsole->Register("play", "r", CFGFLAG_CLIENT, Con_Play, this, "Play the file specified");
 	m_pConsole->Register("record", "?s", CFGFLAG_CLIENT, Con_Record, this, "Record to the file");
 	m_pConsole->Register("stoprecord", "", CFGFLAG_CLIENT, Con_StopRecord, this, "Stop recording");
-
 	m_pConsole->Register("add_favorite", "s", CFGFLAG_CLIENT, Con_AddFavorite, this, "Add a server as a favorite");
+
+	// used for server browser update
+	m_pConsole->Chain("br_filter_string", ConchainServerBrowserUpdate, this);
+	m_pConsole->Chain("br_filter_gametype", ConchainServerBrowserUpdate, this);
+	m_pConsole->Chain("br_filter_serveraddress", ConchainServerBrowserUpdate, this);
 }
 
 static CClient m_Client;
diff --git a/src/engine/client/client.h b/src/engine/client/client.h
index e0cd17a2..b5be566b 100644
--- a/src/engine/client/client.h
+++ b/src/engine/client/client.h
@@ -121,6 +121,7 @@ class CClient : public IClient, public CDemoPlayer::IListner
 	bool m_AutoScreenshotRecycle;
 	bool m_EditorActive;
 	bool m_SoundInitFailed;
+	bool m_ResortServerBrowser;
 
 	int m_AckGameTick;
 	int m_CurrentRecvTick;
@@ -304,6 +305,7 @@ public:
 	static void Con_Play(IConsole::IResult *pResult, void *pUserData);
 	static void Con_Record(IConsole::IResult *pResult, void *pUserData);
 	static void Con_StopRecord(IConsole::IResult *pResult, void *pUserData);
+	static void ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
 
 	void RegisterCommands();
 
@@ -314,5 +316,7 @@ public:
 
 	void AutoScreenshot_Start();
 	void AutoScreenshot_Cleanup();
+
+	void ServerBrowserUpdate();
 };
 #endif
diff --git a/src/engine/client/srvbrowse.cpp b/src/engine/client/srvbrowse.cpp
index 81ee175f..fb350c43 100644
--- a/src/engine/client/srvbrowse.cpp
+++ b/src/engine/client/srvbrowse.cpp
@@ -167,50 +167,44 @@ void CServerBrowser::Filter()
 			Filtered = 1;
 		else if(g_Config.m_BrFilterCompatversion && str_comp_num(m_ppServerlist[i]->m_Info.m_aVersion, m_aNetVersion, 3) != 0)
 			Filtered = 1;
-		else
+		else if(g_Config.m_BrFilterServerAddress[0] && !str_find_nocase(m_ppServerlist[i]->m_Info.m_aAddress, g_Config.m_BrFilterServerAddress))
+			Filtered = 1;
+		else if(g_Config.m_BrFilterGametype[0] && !str_find_nocase(m_ppServerlist[i]->m_Info.m_aGameType, g_Config.m_BrFilterGametype))
+			Filtered = 1;
+		else if(g_Config.m_BrFilterString[0] != 0)
 		{
-			if(g_Config.m_BrFilterString[0] != 0)
-			{
-				int MatchFound = 0;
+			int MatchFound = 0;
 
-				m_ppServerlist[i]->m_Info.m_QuickSearchHit = 0;
-
-				// match against server name
-				if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aName, g_Config.m_BrFilterString))
-				{
-					MatchFound = 1;
-					m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_SERVERNAME;
-				}
+			m_ppServerlist[i]->m_Info.m_QuickSearchHit = 0;
 
-				// 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))
-					{
-						MatchFound = 1;
-						m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_PLAYER;
-						break;
-					}
-				}
+			// match against server name
+			if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aName, g_Config.m_BrFilterString))
+			{
+				MatchFound = 1;
+				m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_SERVERNAME;
+			}
 
-				// match against map
-				if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aMap, g_Config.m_BrFilterString))
+			// 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))
 				{
 					MatchFound = 1;
-					m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_MAPNAME;
+					m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_PLAYER;
+					break;
 				}
-
-				if(!MatchFound)
-					Filtered = 1;
 			}
 
-			if(!Filtered && g_Config.m_BrFilterGametype[0] != 0)
+			// match against map
+			if(str_find_nocase(m_ppServerlist[i]->m_Info.m_aMap, g_Config.m_BrFilterString))
 			{
-				// match against game type
-				if(!str_find_nocase(m_ppServerlist[i]->m_Info.m_aGameType, g_Config.m_BrFilterGametype))
-					Filtered = 1;
+				MatchFound = 1;
+				m_ppServerlist[i]->m_Info.m_QuickSearchHit |= IServerBrowser::QUICK_MAPNAME;
 			}
+
+			if(!MatchFound)
+				Filtered = 1;
 		}
 
 		if(Filtered == 0)
@@ -532,7 +526,7 @@ void CServerBrowser::Request(const NETADDR &Addr) const
 }
 
 
-void CServerBrowser::Update()
+void CServerBrowser::Update(bool ForceResort)
 {
 	int64 Timeout = time_freq()/2;	// TODO 0.6: increase this again
 	int64 Now = time_get();
@@ -606,8 +600,7 @@ void CServerBrowser::Update()
 	}
 
 	// check if we need to resort
-	// TODO: remove the str_comp
-	if(m_Sorthash != SortHash() || str_comp(m_aFilterString, g_Config.m_BrFilterString) != 0 || str_comp(m_aFilterGametypeString, g_Config.m_BrFilterGametype) != 0)
+	if(m_Sorthash != SortHash() || ForceResort)
 		Sort();
 }
 
diff --git a/src/engine/client/srvbrowse.h b/src/engine/client/srvbrowse.h
index 43bd1807..c00ce752 100644
--- a/src/engine/client/srvbrowse.h
+++ b/src/engine/client/srvbrowse.h
@@ -45,7 +45,7 @@ public:
 	void RemoveFavorite(const NETADDR &Addr);
 
 	//
-	void Update();
+	void Update(bool ForceResort);
 	void Set(const NETADDR &Addr, int Type, int Token, const CServerInfo *pInfo);
 	void Request(const NETADDR &Addr) const;
 
diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h
index c495461e..68e615bd 100644
--- a/src/engine/shared/config_variables.h
+++ b/src/engine/shared/config_variables.h
@@ -28,12 +28,12 @@ MACRO_CONFIG_INT(ClEventthread, cl_eventthread, 0, 0, 1, CFGFLAG_CLIENT, "Enable
 MACRO_CONFIG_INT(InpGrab, inp_grab, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use forceful input grabbing method")
 
 MACRO_CONFIG_STR(BrFilterString, br_filter_string, 25, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server browser filtering string")
-
 MACRO_CONFIG_INT(BrFilterFull, br_filter_full, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out full server in browser")
 MACRO_CONFIG_INT(BrFilterEmpty, br_filter_empty, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out empty server in browser")
 MACRO_CONFIG_INT(BrFilterPw, br_filter_pw, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out password protected servers in browser")
 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_STR(BrFilterServerAddress, br_filter_serveraddress, 128, "", CFGFLAG_SAVE|CFGFLAG_CLIENT, "Server address to filter")
 MACRO_CONFIG_INT(BrFilterPure, br_filter_pure, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard servers in browser")
 MACRO_CONFIG_INT(BrFilterPureMap, br_filter_pure_map, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-standard maps in browser")
 MACRO_CONFIG_INT(BrFilterCompatversion, br_filter_compatversion, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Filter out non-compatible servers in browser")