Skip to content

Commit e75bf42

Browse files
committed
Improved client connecting through firewalls
1 parent 002f65f commit e75bf42

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

Client/core/CConnectManager.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const
146146
m_pServerItem = new CServerListItem ( m_Address, m_usPort );
147147
m_pServerItem->m_iTimeoutLength = 2000;
148148
m_bIsDetectingVersion = true;
149-
OpenServerFirewall( m_Address, 80, true );
149+
OpenServerFirewall( m_Address, CServerBrowser::GetSingletonPtr()->FindServerHttpPort(m_strHost, m_usPort), true );
150150

151151
// Display the status box
152152
SString strBuffer ( _("Connecting to %s:%u ..."), m_strHost.c_str(), m_usPort );
@@ -466,21 +466,29 @@ void CConnectManager::OnServerExists ( void )
466466
//
467467
void CConnectManager::OpenServerFirewall( in_addr Address, ushort usHttpPort, bool bHighPriority )
468468
{
469-
if ( usHttpPort == 0 )
470-
usHttpPort = 80;
471-
472469
uint uiTimeOut;
473470
if ( bHighPriority )
474471
{
475472
// Clear previously queued requests if this is high priority
476473
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->Reset();
474+
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->SetMaxConnections(2);
477475
uiTimeOut = 2000;
478476
}
479477
else
480478
{
481479
uiTimeOut = 1000;
482480
}
483481

484-
SString strDummyUrl( "http://%s:%d/mta_client_firewall_probe/", inet_ntoa( Address ), usHttpPort );
485-
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->QueueFile( strDummyUrl, NULL, "", 0, true, NULL, NULL, false, 1, uiTimeOut );
482+
if ( usHttpPort )
483+
{
484+
// Send to server http port if known
485+
SString strDummyUrl( "http://%s:%d/mta_client_firewall_probe/", inet_ntoa( Address ), usHttpPort );
486+
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->QueueFile( strDummyUrl, NULL, "", 0, true, NULL, NULL, false, 1, uiTimeOut );
487+
}
488+
if ( usHttpPort == 0 || bHighPriority )
489+
{
490+
// Send to standard http port
491+
SString strDummyUrl( "http://%s/mta_client_firewall_probe/", inet_ntoa( Address ) );
492+
g_pCore->GetNetwork()->GetHTTPDownloadManager( EDownloadMode::CONNECT_TCP_SEND )->QueueFile( strDummyUrl, NULL, "", 0, true, NULL, NULL, false, 1, uiTimeOut );
493+
}
486494
}

Client/core/Serverbrowser/CServerBrowser.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ CServerListItem* CServerBrowser::FindServerFromRow ( ServerBrowserType Type, int
20432043
// Finds a server at any point in the active list
20442044
//
20452045
/////////////////////////////////////////////////////////////////
2046-
CServerListItem* CServerBrowser::FindServer ( std::string strHost, unsigned short usPort )
2046+
CServerListItem* CServerBrowser::FindServer ( const std::string& strHost, unsigned short usPort )
20472047
{
20482048
ServerBrowserType Type = GetCurrentServerBrowserType ();
20492049
CServerList * pList = GetServerList ( Type );
@@ -2060,6 +2060,26 @@ CServerListItem* CServerBrowser::FindServer ( std::string strHost, unsigned shor
20602060
}
20612061

20622062

2063+
/////////////////////////////////////////////////////////////////
2064+
//
2065+
// CServerBrowser::FindServerHttpPort
2066+
//
2067+
// Finds a server http port. Returns 0 if not found.
2068+
//
2069+
/////////////////////////////////////////////////////////////////
2070+
unsigned short CServerBrowser::FindServerHttpPort ( const std::string& strHost, unsigned short usPort )
2071+
{
2072+
CServerList * pList = GetServerList ( ServerBrowserTypes::INTERNET );
2073+
CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd ();
2074+
for ( CServerListIterator i = i_b; i != i_e; i++ )
2075+
{
2076+
CServerListItem * pServer = *i;
2077+
if ( pServer->strHost == strHost && pServer->usGamePort == usPort )
2078+
return pServer->m_usHttpPort;
2079+
}
2080+
return 0;
2081+
}
2082+
20632083

20642084
/////////////////////////////////////////////////////////////////
20652085
//

Client/core/Serverbrowser/CServerBrowser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ class CServerBrowser : public CSingleton < CServerBrowser >
102102

103103
CServerListItem* FindSelectedServer ( ServerBrowserType Type );
104104
CServerListItem* FindServerFromRow ( ServerBrowserType Type, int iRow );
105-
CServerListItem* FindServer ( std::string strHost, unsigned short usPort );
105+
CServerListItem* FindServer ( const std::string& strHost, unsigned short usPort );
106+
unsigned short FindServerHttpPort ( const std::string& strHost, unsigned short usPort );
106107
int FindRowFromServer ( ServerBrowserType Type, const CServerListItem * pServer );
107108
void UpdateSelectedServerPlayerList ( ServerBrowserType Type );
108109
void GetVisibleEndPointList ( std::vector < SAddressPort >& outEndpointList );

Client/loader/MainFunctions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ void HandleIfGTAIsAlreadyRunning( void )
566566
{
567567
if ( MessageBoxUTF8 ( 0, _("An instance of GTA: San Andreas is already running. It needs to be terminated before MTA:SA can be started. Do you want to do that now?"), _("Information")+_E("CL10"), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST ) == IDYES )
568568
{
569+
TerminateOtherMTAIfRunning();
569570
TerminateGTAIfRunning ();
570571
if ( IsGTARunning () )
571572
{

Client/loader/Utils.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,11 +1390,26 @@ bool Is32bitProcess ( DWORD processID )
13901390
///////////////////////////////////////////////////////////////////////////
13911391
void TerminateProcess( DWORD dwProcessID, uint uiExitCode )
13921392
{
1393-
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, 0, dwProcessID );
1394-
if ( hProcess )
1393+
HMODULE hModule = GetLibraryHandle ( "kernel32.dll" );
1394+
if ( hModule )
13951395
{
1396-
TerminateProcess( hProcess, uiExitCode );
1397-
CloseHandle( hProcess );
1396+
typedef bool (*PFNTerminateProcess) ( uint, uint );
1397+
PFNTerminateProcess pfnTerminateProcess = static_cast< PFNTerminateProcess > ( static_cast < PVOID > ( GetProcAddress ( hModule, "NtTerminateProcess" ) ) );
1398+
1399+
if ( pfnTerminateProcess )
1400+
{
1401+
bool bResult = pfnTerminateProcess ( dwProcessID, uiExitCode );
1402+
AddReportLog ( 8070, SString ( "TerminateProcess %d result: %d", dwProcessID, bResult ) );
1403+
}
1404+
else
1405+
{
1406+
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, 0, dwProcessID );
1407+
if ( hProcess )
1408+
{
1409+
TerminateProcess( hProcess, uiExitCode );
1410+
CloseHandle( hProcess );
1411+
}
1412+
}
13981413
}
13991414
}
14001415

0 commit comments

Comments
 (0)