summaryrefslogtreecommitdiff
path: root/common/ServerBrowser
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /common/ServerBrowser
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'common/ServerBrowser')
-rw-r--r--common/ServerBrowser/IServerBrowser.h57
-rw-r--r--common/ServerBrowser/blacklisted_server_manager.cpp290
-rw-r--r--common/ServerBrowser/blacklisted_server_manager.h74
3 files changed, 421 insertions, 0 deletions
diff --git a/common/ServerBrowser/IServerBrowser.h b/common/ServerBrowser/IServerBrowser.h
new file mode 100644
index 0000000..32d1b44
--- /dev/null
+++ b/common/ServerBrowser/IServerBrowser.h
@@ -0,0 +1,57 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+#ifndef ISERVERBROWSER_H
+#define ISERVERBROWSER_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "interface.h"
+
+//-----------------------------------------------------------------------------
+// Purpose: Interface to server browser module
+//-----------------------------------------------------------------------------
+abstract_class IServerBrowser
+{
+public:
+ // activates the server browser window, brings it to the foreground
+ virtual bool Activate() = 0;
+
+ // joins a game directly
+ virtual bool JoinGame( uint32 unGameIP, uint16 usGamePort, const char *pszConnectCode ) = 0;
+
+ // joins a specified game - game info dialog will only be opened if the server is fully or passworded
+ virtual bool JoinGame( uint64 ulSteamIDFriend, const char *pszConnectCode ) = 0;
+
+ // opens a game info dialog to watch the specified server; associated with the friend 'userName'
+ virtual bool OpenGameInfoDialog( uint64 ulSteamIDFriend, const char *pszConnectCode ) = 0;
+
+ // forces the game info dialog closed
+ virtual void CloseGameInfoDialog( uint64 ulSteamIDFriend ) = 0;
+
+ // closes all the game info dialogs
+ virtual void CloseAllGameInfoDialogs() = 0;
+
+ /// Given a map name, strips off some stuff and returns the "friendly" name of the map.
+ /// Returns the cleaned out map name into the caller's buffer, and returns the friendly
+ /// game type name.
+ virtual const char *GetMapFriendlyNameAndGameType( const char *pszMapName, char *szFriendlyMapName, int cchFriendlyName ) = 0;
+
+ // Enable filtering of workshop maps, requires the game/tool loading us to feed subscription data. This is a
+ // slightly ugly workaround to TF2 not yet having native workshop UI in quickplay, once that is in place this should
+ // either be stripped back out or expanded to be directly aware of the steam workshop without being managed.
+ virtual void SetWorkshopEnabled( bool bManaged ) = 0;
+ virtual void AddWorkshopSubscribedMap( const char *pszMapName ) = 0;
+ virtual void RemoveWorkshopSubscribedMap( const char *pszMapName ) = 0;
+};
+
+#define SERVERBROWSER_INTERFACE_VERSION "ServerBrowser005"
+
+
+
+#endif // ISERVERBROWSER_H
diff --git a/common/ServerBrowser/blacklisted_server_manager.cpp b/common/ServerBrowser/blacklisted_server_manager.cpp
new file mode 100644
index 0000000..95fcbfc
--- /dev/null
+++ b/common/ServerBrowser/blacklisted_server_manager.cpp
@@ -0,0 +1,290 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================
+
+//#include "..\..\serverbrowser\pch_serverbrowser.h"
+
+#undef _snprintf // needed since matchmakingtypes.h inlines a bare _snprintf
+
+#include "convar.h"
+#include "KeyValues.h"
+#include "filesystem.h"
+#include "steam/steamclientpublic.h"
+#include "steam/matchmakingtypes.h"
+#include <time.h>
+#include "blacklisted_server_manager.h"
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CBlacklistedServerManager::CBlacklistedServerManager()
+{
+ m_iNextServerID = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Reset the list of blacklisted servers to empty.
+//-----------------------------------------------------------------------------
+void CBlacklistedServerManager::Reset( void )
+{
+ m_Blacklist.RemoveAll();
+ m_iNextServerID = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Appends all the servers inside the specified file to the blacklist.
+// Returns count of appended servers, zero for failure.
+//-----------------------------------------------------------------------------
+int CBlacklistedServerManager::LoadServersFromFile( const char *pszFilename, bool bResetTimes )
+{
+ KeyValues *pKV = new KeyValues( "serverblacklist" );
+ if ( !pKV->LoadFromFile( g_pFullFileSystem, pszFilename, "MOD" ) )
+ return 0;
+
+ int count = 0;
+
+ for ( KeyValues *pData = pKV->GetFirstSubKey(); pData != NULL; pData = pData->GetNextKey() )
+ {
+ const char *pszName = pData->GetString( "name" );
+
+ uint32 ulDate = pData->GetInt( "date" );
+ if ( bResetTimes )
+ {
+ time_t today;
+ time( &today );
+ ulDate = today;
+ }
+
+ const char *pszNetAddr = pData->GetString( "addr" );
+ if ( pszNetAddr && pszNetAddr[0] && pszName && pszName[0] )
+ {
+ int iIdx = m_Blacklist.AddToTail();
+
+ m_Blacklist[iIdx].m_nServerID = m_iNextServerID++;
+ V_strncpy( m_Blacklist[iIdx].m_szServerName, pszName, sizeof( m_Blacklist[iIdx].m_szServerName ) );
+ m_Blacklist[iIdx].m_ulTimeBlacklistedAt = ulDate;
+ m_Blacklist[iIdx].m_NetAdr.SetFromString( pszNetAddr );
+
+ ++count;
+ }
+ }
+
+ pKV->deleteThis();
+
+ return count;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: save blacklist to disk
+//-----------------------------------------------------------------------------
+void CBlacklistedServerManager::SaveToFile( const char *pszFilename )
+{
+ KeyValues *pKV = new KeyValues( "serverblacklist" );
+
+ for ( int i = 0; i < m_Blacklist.Count(); i++ )
+ {
+ KeyValues *pSubKey = new KeyValues( "server" );
+ pSubKey->SetString( "name", m_Blacklist[i].m_szServerName );
+ pSubKey->SetInt( "date", m_Blacklist[i].m_ulTimeBlacklistedAt );
+ pSubKey->SetString( "addr", m_Blacklist[i].m_NetAdr.ToString() );
+ pKV->AddSubKey( pSubKey );
+ }
+
+ pKV->SaveToFile( g_pFullFileSystem, pszFilename, "MOD" );
+
+ pKV->deleteThis();
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Add the given server to the blacklist. Return added server.
+//-----------------------------------------------------------------------------
+blacklisted_server_t *CBlacklistedServerManager::AddServer( gameserveritem_t &server )
+{
+ // Make sure we don't already have this IP in the list somewhere
+ netadr_t netAdr( server.m_NetAdr.GetIP(), server.m_NetAdr.GetConnectionPort() );
+
+ // Don't let them add reserved addresses to their blacklists
+ if ( netAdr.IsReservedAdr() )
+ return NULL;
+
+ int iIdx = m_Blacklist.AddToTail();
+ V_strncpy( m_Blacklist[iIdx].m_szServerName, server.GetName(), sizeof( m_Blacklist[iIdx].m_szServerName ) );
+
+ time_t today;
+ time( &today );
+ m_Blacklist[iIdx].m_ulTimeBlacklistedAt = today;
+ m_Blacklist[iIdx].m_NetAdr = netAdr;
+ m_Blacklist[iIdx].m_nServerID = m_iNextServerID++;
+
+ return &m_Blacklist[iIdx];
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Add the given server to the blacklist. Return added server.
+//-----------------------------------------------------------------------------
+blacklisted_server_t *CBlacklistedServerManager::AddServer( const char *serverName, uint32 serverIP, int serverPort )
+{
+ netadr_t netAdr( serverIP, serverPort );
+
+ // Don't let them add reserved addresses to their blacklists
+ if ( netAdr.IsReservedAdr() )
+ return NULL;
+
+ int iIdx = m_Blacklist.AddToTail();
+
+ V_strncpy( m_Blacklist[iIdx].m_szServerName, serverName, sizeof( m_Blacklist[iIdx].m_szServerName ) );
+
+ time_t today;
+ time( &today );
+ m_Blacklist[iIdx].m_ulTimeBlacklistedAt = today;
+
+ m_Blacklist[iIdx].m_NetAdr = netAdr;
+ m_Blacklist[iIdx].m_nServerID = m_iNextServerID++;
+
+ return &m_Blacklist[iIdx];
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Add the given server to the blacklist. Return added server.
+//-----------------------------------------------------------------------------
+blacklisted_server_t *CBlacklistedServerManager::AddServer( const char *serverName, const char *netAddressString, uint32 timestamp )
+{
+ netadr_t netAdr( netAddressString );
+
+ // Don't let them add reserved addresses to their blacklists
+ if ( netAdr.IsReservedAdr() )
+ return NULL;
+
+ int iIdx = m_Blacklist.AddToTail();
+
+ V_strncpy( m_Blacklist[iIdx].m_szServerName, serverName, sizeof( m_Blacklist[iIdx].m_szServerName ) );
+ m_Blacklist[iIdx].m_ulTimeBlacklistedAt = timestamp;
+ m_Blacklist[iIdx].m_NetAdr = netAdr;
+ m_Blacklist[iIdx].m_nServerID = m_iNextServerID++;
+
+ return &m_Blacklist[iIdx];
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Remove server with matching 'server id' from list
+//-----------------------------------------------------------------------------
+void CBlacklistedServerManager::RemoveServer( int iServerID )
+{
+ for ( int i = 0; i < m_Blacklist.Count(); i++ )
+ {
+ if ( m_Blacklist[i].m_nServerID == iServerID )
+ {
+ m_Blacklist.Remove(i);
+ break;
+ }
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Given a serverID, return its blacklist entry
+//-----------------------------------------------------------------------------
+blacklisted_server_t *CBlacklistedServerManager::GetServer( int iServerID )
+{
+ for ( int i = 0; i < m_Blacklist.Count(); i++ )
+ {
+ if ( m_Blacklist[i].m_nServerID == iServerID )
+ return &m_Blacklist[i];
+ }
+
+ return NULL;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if given server is blacklisted
+//-----------------------------------------------------------------------------
+bool CBlacklistedServerManager::IsServerBlacklisted( const gameserveritem_t &server ) const
+{
+ return IsServerBlacklisted( server.m_NetAdr.GetIP(), server.m_NetAdr.GetConnectionPort(), server.GetName() );
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if given server is blacklisted
+//-----------------------------------------------------------------------------
+bool CBlacklistedServerManager::IsServerBlacklisted( uint32 serverIP, int serverPort, const char *serverName ) const
+{
+ netadr_t netAdr( serverIP, serverPort );
+
+ ConVarRef sb_showblacklists( "sb_showblacklists" );
+
+ for ( int i = 0; i < m_Blacklist.Count(); i++ )
+ {
+ if ( m_Blacklist[i].m_NetAdr.ip[3] == 0 )
+ {
+ if ( m_Blacklist[i].m_NetAdr.CompareClassCAdr( netAdr ) )
+ {
+ if ( sb_showblacklists.IsValid() && sb_showblacklists.GetBool() )
+ {
+ Msg( "Blacklisted '%s' (%s), due to rule '%s' (Class C).\n", serverName, netAdr.ToString(), m_Blacklist[i].m_NetAdr.ToString() );
+ }
+ return true;
+ }
+ }
+ else
+ {
+ if ( m_Blacklist[i].m_NetAdr.CompareAdr( netAdr, (m_Blacklist[i].m_NetAdr.GetPort() == 0) ) )
+ {
+ if ( sb_showblacklists.IsValid() && sb_showblacklists.GetBool() )
+ {
+ Msg( "Blacklisted '%s' (%s), due to rule '%s'.\n", serverName, netAdr.ToString(), m_Blacklist[i].m_NetAdr.ToString() );
+ }
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if the given server is allowed to be blacklisted at all
+//-----------------------------------------------------------------------------
+bool CBlacklistedServerManager::CanServerBeBlacklisted( gameserveritem_t &server ) const
+{
+ return CanServerBeBlacklisted( server.m_NetAdr.GetIP(), server.m_NetAdr.GetConnectionPort(), server.GetName() );
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns true if the given server is allowed to be blacklisted at all
+//-----------------------------------------------------------------------------
+bool CBlacklistedServerManager::CanServerBeBlacklisted( uint32 serverIP, int serverPort, const char *serverName ) const
+{
+ netadr_t netAdr( serverIP, serverPort );
+
+ if ( !netAdr.IsValid() )
+ return false;
+
+ // Don't let them add reserved addresses to their blacklists
+ if ( netAdr.IsReservedAdr() )
+ return false;
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Returns vector of blacklisted servers
+//-----------------------------------------------------------------------------
+const CUtlVector< blacklisted_server_t > &CBlacklistedServerManager::GetServerVector( void ) const
+{
+ return m_Blacklist;
+}
diff --git a/common/ServerBrowser/blacklisted_server_manager.h b/common/ServerBrowser/blacklisted_server_manager.h
new file mode 100644
index 0000000..cd8173f
--- /dev/null
+++ b/common/ServerBrowser/blacklisted_server_manager.h
@@ -0,0 +1,74 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================
+
+#ifndef BLACKLISTEDSERVERMANAGER_H
+#define BLACKLISTEDSERVERMANAGER_H
+#ifdef _WIN32
+#pragma once
+#endif
+
+#include "platform.h"
+#include "netadr.h"
+#include "utlvector.h"
+
+#define BLACKLIST_DEFAULT_SAVE_FILE "cfg/server_blacklist.txt"
+
+class gameserveritem_t;
+
+struct blacklisted_server_t
+{
+ int m_nServerID;
+ char m_szServerName[64];
+ uint32 m_ulTimeBlacklistedAt;
+ netadr_t m_NetAdr;
+};
+
+
+//-----------------------------------------------------------------------------
+// Purpose: Collection of blacklisted servers
+//-----------------------------------------------------------------------------
+class CBlacklistedServerManager
+{
+public:
+ CBlacklistedServerManager();
+
+ void Reset( void );
+
+ blacklisted_server_t *AddServer( gameserveritem_t &server );
+ blacklisted_server_t *AddServer( const char *serverName, uint32 serverIP, int serverPort );
+ blacklisted_server_t *AddServer( const char *serverName, const char *netAddressString, uint32 timestamp );
+
+ void RemoveServer( int iServerID ); // remove server with matching 'server id' from list
+
+ void SaveToFile( const char *filename );
+ int LoadServersFromFile( const char *pszFilename, bool bResetTimes ); // returns count of appended servers, zero for failure
+
+ blacklisted_server_t *GetServer( int iServerID ); // return server with matching 'server id'
+ int GetServerCount( void ) const;
+
+ const CUtlVector< blacklisted_server_t > &GetServerVector( void ) const;
+
+ bool IsServerBlacklisted( const gameserveritem_t &server ) const;
+ bool IsServerBlacklisted( uint32 serverIP, int serverPort, const char *serverName ) const;
+
+ bool CanServerBeBlacklisted( gameserveritem_t &server ) const;
+ bool CanServerBeBlacklisted( uint32 serverIP, int serverPort, const char *serverName ) const;
+
+private:
+ CUtlVector< blacklisted_server_t > m_Blacklist;
+ int m_iNextServerID; // for vgui use
+};
+
+inline int CBlacklistedServerManager::GetServerCount( void ) const
+{
+ return m_Blacklist.Count();
+}
+
+
+
+
+#endif // BLACKLISTEDSERVERMANAGER_H