Skip to content

Commit 5c50de4

Browse files
committed
Fixed #9091 (Players reconnect when downloading an updated file from external web server)
1 parent 624eeff commit 5c50de4

28 files changed

+525
-329
lines changed

MTA10/core/CConnectManager.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ CConnectManager::CConnectManager ( void )
2929
m_bIsDetectingVersion = false;
3030
m_bIsConnecting = false;
3131
m_bSave = true;
32-
m_bForceInternalHTTPServer = false;
3332
m_tConnectStarted = 0;
3433

3534
m_pOnCancelClick = new GUI_CALLBACK ( &CConnectManager::Event_OnCancelClick, this );
@@ -52,7 +51,7 @@ CConnectManager::~CConnectManager ( void )
5251
}
5352

5453

55-
bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser, bool bForceInternalHTTPServer )
54+
bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser )
5655
{
5756
assert ( szHost );
5857
assert ( szNick );
@@ -100,7 +99,6 @@ bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const
10099
m_strPassword = szPassword;
101100
m_Address.s_addr = 0;
102101
m_usPort = usPort;
103-
m_bForceInternalHTTPServer = bForceInternalHTTPServer;
104102
m_bSave = true;
105103

106104
m_strLastHost = m_strHost;
@@ -144,7 +142,7 @@ bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const
144142
m_pServerItem = new CServerListItem ( m_Address, m_usPort );
145143
m_pServerItem->m_iTimeoutLength = 2000;
146144
m_bIsDetectingVersion = true;
147-
OpenServerFirewall( m_Address );
145+
OpenServerFirewall( m_Address, 80, true );
148146

149147
// Display the status box
150148
SString strBuffer ( _("Connecting to %s:%u ..."), m_strHost.c_str(), m_usPort );
@@ -154,7 +152,7 @@ bool CConnectManager::Connect ( const char* szHost, unsigned short usPort, const
154152
}
155153

156154

157-
bool CConnectManager::Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave, bool bForceInternalHTTPServer )
155+
bool CConnectManager::Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave )
158156
{
159157
// Use previous connection datum when function arguments are not set
160158
unsigned int uiPort = 0;
@@ -185,7 +183,6 @@ bool CConnectManager::Reconnect ( const char* szHost, unsigned short usPort, con
185183
m_bSave = bSave;
186184

187185
m_bReconnect = true;
188-
m_bForceInternalHTTPServer = bForceInternalHTTPServer;
189186

190187
return true;
191188
}
@@ -336,7 +333,7 @@ void CConnectManager::DoPulse ( void )
336333
{
337334
std::string strNick;
338335
CVARS_GET ( "nick", strNick );
339-
Connect ( m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false, m_bForceInternalHTTPServer );
336+
Connect ( m_strHost.c_str(), m_usPort, strNick.c_str(), m_strPassword.c_str(), false );
340337
m_bReconnect = false;
341338
}
342339
}

MTA10/core/CConnectManager.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ class CConnectManager
2424
CConnectManager ( void );
2525
~CConnectManager ( void );
2626

27-
bool Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser = false, bool bForceInternalHTTPServer = false );
28-
bool Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true, bool bForceInternalHTTPServer = false );
27+
bool Connect ( const char* szHost, unsigned short usPort, const char* szNick, const char* szPassword, bool bNotifyServerBrowser = false );
28+
bool Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true );
2929

3030
bool Abort ( void );
3131

3232
void DoPulse ( void );
3333

3434
void OnServerExists ( void );
3535

36-
bool ShouldUseInternalHTTPServer ( void ) { return m_bForceInternalHTTPServer; }
3736
static void OpenServerFirewall ( in_addr Address, ushort usHttpPort = 80, bool bHighPriority = false );
3837

3938
static bool StaticProcessPacket ( unsigned char ucPacketID, class NetBitStreamInterface& bitStream );
@@ -53,7 +52,6 @@ class CConnectManager
5352
bool m_bIsConnecting;
5453
bool m_bReconnect;
5554
bool m_bSave;
56-
bool m_bForceInternalHTTPServer;
5755
time_t m_tConnectStarted;
5856
bool m_bHasTriedSecondConnect;
5957

MTA10/core/CCore.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,9 @@ bool CCore::IsConnected ( void )
634634
}
635635

636636

637-
bool CCore::Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave, bool bForceInternalHTTPServer )
637+
bool CCore::Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave )
638638
{
639-
return m_pConnectManager->Reconnect ( szHost, usPort, szPassword, bSave, bForceInternalHTTPServer );
640-
}
641-
642-
643-
bool CCore::ShouldUseInternalHTTPServer( void )
644-
{
645-
return m_pConnectManager->ShouldUseInternalHTTPServer();
639+
return m_pConnectManager->Reconnect ( szHost, usPort, szPassword, bSave );
646640
}
647641

648642

MTA10/core/CCore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ class CCore : public CCoreInterface, public CSingleton < CCore >
154154
// Net
155155
void SetConnected ( bool bConnected );
156156
bool IsConnected ( void );
157-
bool Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true, bool bForceInternalHTTPServer = false );
158-
bool ShouldUseInternalHTTPServer ( void );
157+
bool Reconnect ( const char* szHost, unsigned short usPort, const char* szPassword, bool bSave = true );
159158

160159
// Mod
161160
void SetOfflineMod ( bool bOffline );

MTA10/mods/deathmatch/StdInc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
#include "logic/CDeathmatchVehicle.h"
137137
#include "logic/CResource.h"
138138
#include "logic/CStaticFunctionDefinitions.h"
139+
#include "logic/CResourceFileDownloadManager.h"
139140
#include "../../version.h"
140141

141142

MTA10/mods/deathmatch/_Deathmatch 2008.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@
428428
<ClCompile Include="..\shared_logic\CRemoteCalls.cpp" />
429429
<ClCompile Include="logic\CResource.cpp" />
430430
<ClCompile Include="logic\CResourceConfigItem.cpp" />
431+
<ClCompile Include="logic\CResourceFileDownloadManager.cpp" />
431432
<ClCompile Include="logic\CResourceManager.cpp" />
432433
<ClCompile Include="logic\CScriptKeyBinds.cpp" />
433434
<ClCompile Include="logic\CServer.cpp" />
@@ -805,6 +806,7 @@
805806
<ClInclude Include="logic\CResource.h" />
806807
<ClInclude Include="logic\CResourceConfigItem.h" />
807808
<ClInclude Include="logic\CResourceFile.h" />
809+
<ClInclude Include="logic\CResourceFileDownloadManager.h" />
808810
<ClInclude Include="logic\CResourceManager.h" />
809811
<ClInclude Include="logic\CScriptKeyBinds.h" />
810812
<ClInclude Include="logic\CServer.h" />

MTA10/mods/deathmatch/_Deathmatch 2008.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@
188188
<ClCompile Include="logic\CResourceManager.cpp">
189189
<Filter>Source Files\logic</Filter>
190190
</ClCompile>
191+
<ClCompile Include="logic\CResourceFileDownloadManager.cpp">
192+
<Filter>Source Files\logic</Filter>
193+
</ClCompile>
191194
<ClCompile Include="logic\CScriptKeyBinds.cpp">
192195
<Filter>Source Files\logic</Filter>
193196
</ClCompile>
@@ -1051,6 +1054,9 @@
10511054
<ClInclude Include="logic\CResourceFile.h">
10521055
<Filter>Header Files\logic</Filter>
10531056
</ClInclude>
1057+
<ClInclude Include="logic\CResourceFileDownloadManager.h">
1058+
<Filter>Header Files\logic</Filter>
1059+
</ClInclude>
10541060
<ClInclude Include="logic\CResourceManager.h">
10551061
<Filter>Header Files\logic</Filter>
10561062
</ClInclude>

MTA10/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 3 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ CClientGame::CClientGame ( bool bLocalPlay )
203203
m_pZoneNames = new CZoneNames;
204204
m_pScriptKeyBinds = new CScriptKeyBinds;
205205
m_pRemoteCalls = new CRemoteCalls();
206+
m_pResourceFileDownloadManager = new CResourceFileDownloadManager();
206207

207208
// Create our net API
208209
m_pNetAPI = new CNetAPI ( m_pManager );
@@ -475,6 +476,7 @@ CClientGame::~CClientGame ( void )
475476
SAFE_DELETE( m_pRemoteCalls );
476477
SAFE_DELETE( m_pLuaManager );
477478
SAFE_DELETE( m_pLatentTransferManager );
479+
SAFE_DELETE( m_pResourceFileDownloadManager );
478480

479481
SAFE_DELETE( m_pRootEntity );
480482

@@ -1181,7 +1183,7 @@ void CClientGame::DoPulses ( void )
11811183
else if ( m_Status == CClientGame::STATUS_JOINED )
11821184
{
11831185
// Pulse DownloadFiles if we're transferring stuff
1184-
DownloadInitialResourceFiles ();
1186+
GetResourceFileDownloadManager()->DoPulse();
11851187
DownloadSingularResourceFiles ();
11861188
g_pNet->GetHTTPDownloadManager ( EDownloadMode::CALL_REMOTE )->ProcessQueuedFiles ();
11871189
}
@@ -4025,79 +4027,6 @@ bool CClientGame::ProcessCollisionHandler ( CEntitySAInterface* pThisInterface,
40254027
}
40264028

40274029

4028-
// Set flag and transfer box visibility
4029-
void CClientGame::SetTransferringInitialFiles ( bool bTransfer, int iDownloadPriorityGroup )
4030-
{
4031-
m_bTransferringInitialFiles = bTransfer;
4032-
m_iActiveDownloadPriorityGroup = bTransfer ? iDownloadPriorityGroup : INVALID_DOWNLOAD_PRIORITY_GROUP;
4033-
if ( bTransfer )
4034-
m_pTransferBox->Show ();
4035-
else
4036-
m_pTransferBox->Hide ();
4037-
}
4038-
4039-
4040-
// Get Download Priority Group of resources that are DOWNLOADING RIGHT NOW!
4041-
int CClientGame::GetActiveDownloadPriorityGroup ( void )
4042-
{
4043-
return m_bTransferringInitialFiles ? m_iActiveDownloadPriorityGroup : INVALID_DOWNLOAD_PRIORITY_GROUP;
4044-
}
4045-
4046-
4047-
//
4048-
// Downloading initial resource files
4049-
//
4050-
void CClientGame::DownloadInitialResourceFiles ( void )
4051-
{
4052-
if ( !IsTransferringInitialFiles () )
4053-
return;
4054-
4055-
if ( !g_pNet->IsConnected() )
4056-
return;
4057-
4058-
CNetHTTPDownloadManagerInterface* pHTTP = g_pNet->GetHTTPDownloadManager ( EDownloadMode::RESOURCE_INITIAL_FILES );
4059-
if ( !pHTTP->ProcessQueuedFiles () )
4060-
{
4061-
// Downloading
4062-
m_pTransferBox->SetInfo ( pHTTP->GetDownloadSizeNow () );
4063-
m_pTransferBox->DoPulse ();
4064-
}
4065-
else
4066-
{
4067-
// This will also hide the transfer box
4068-
SetTransferringInitialFiles ( false );
4069-
4070-
// Get the last error to occur in the HTTP Manager
4071-
const char* szHTTPError = pHTTP->GetError ();
4072-
4073-
// Was an error found?
4074-
if ( strlen (szHTTPError) == 0 )
4075-
{
4076-
// Load our ("unavailable"-flagged) resources, and make them available
4077-
m_pResourceManager->OnDownloadGroupFinished ();
4078-
}
4079-
else
4080-
{
4081-
g_pCore->GetConsole ()->Printf ( _("Download error: %s"), szHTTPError );
4082-
if ( g_pClientGame->IsUsingExternalHTTPServer() && !g_pCore->ShouldUseInternalHTTPServer() )
4083-
{
4084-
SString strMessage( "External HTTP file download error:%s (Reconnecting with internal HTTP)", szHTTPError );
4085-
g_pClientGame->TellServerSomethingImportant( 1006, strMessage, true );
4086-
g_pCore->Reconnect( "", 0, NULL, false, true );
4087-
}
4088-
else
4089-
{
4090-
// Throw the error and disconnect
4091-
AddReportLog( 7106, SString( "Game - HTTPError (%s)", szHTTPError ) );
4092-
4093-
g_pCore->GetModManager ()->RequestUnload ();
4094-
g_pCore->ShowMessageBox ( _("Error")+_E("CD20"), szHTTPError, MB_BUTTON_OK | MB_ICON_ERROR ); // HTTP Error
4095-
}
4096-
}
4097-
}
4098-
}
4099-
4100-
41014030
//
41024031
// On demand files
41034032
//
@@ -6457,8 +6386,6 @@ void CClientGame::OutputServerInfo( void )
64576386
{
64586387
SString strTotalOutput;
64596388
strTotalOutput += SString( "Server info for %s", g_pNet->GetConnectedServer( true ) );
6460-
if ( IsUsingExternalHTTPServer() )
6461-
strTotalOutput += " (External HTTP)";
64626389
strTotalOutput += "\n";
64636390
strTotalOutput += SString( "Ver: %s\n", *GetServerVersionSortable () );
64646391
strTotalOutput += SString( "AC: %s\n", *m_strACInfo );

MTA10/mods/deathmatch/logic/CClientGame.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
class CGameEntityXRefManager;
6464
class CClientModelCacheManager;
6565
class CDebugHookManager;
66+
class CResourceFileDownloadManager;
6667

6768
struct SVehExtrapolateSettings
6869
{
@@ -304,6 +305,7 @@ class CClientGame
304305
inline CElementDeleter* GetElementDeleter ( void ) { return &m_ElementDeleter; }
305306
inline CObjectRespawner* GetObjectRespawner ( void ) { return &m_ObjectRespawner; }
306307
CRemoteCalls* GetRemoteCalls ( void ) { return m_pRemoteCalls; }
308+
CResourceFileDownloadManager* GetResourceFileDownloadManager ( void ) { return m_pResourceFileDownloadManager; }
307309

308310
// Status toggles
309311
void ShowNetstat ( int iCmd );
@@ -432,7 +434,6 @@ class CClientGame
432434
void ProjectileInitiateHandler ( CClientProjectile * pProjectile );
433435
void IdleHandler ( void );
434436
void OutputServerInfo ( void );
435-
bool IsUsingExternalHTTPServer ( void ) { return m_ucHTTPDownloadType == HTTP_DOWNLOAD_ENABLED_URL; }
436437
void TellServerSomethingImportant ( uint uiId, const SString& strMessage, bool bOnlyOnceForThisId );
437438
void ChangeFloatPrecision ( bool bHigh );
438439
bool IsHighFloatPrecision ( void ) const;
@@ -484,7 +485,6 @@ class CClientGame
484485
void DrawWeaponsyncData ( CClientPlayer* pPlayer );
485486
#endif
486487

487-
void DownloadInitialResourceFiles ( void );
488488
void DownloadSingularResourceFiles ( void );
489489

490490
void QuitPlayer ( CClientPlayer* pPlayer, eQuitReason Reason );
@@ -577,11 +577,8 @@ class CClientGame
577577
void SetServerVersionSortable ( const SString& strVersion ) { m_strServerVersionSortable = strVersion; }
578578
const SString& GetServerVersionSortable ( void ) { return m_strServerVersionSortable; }
579579

580-
void SetTransferringInitialFiles ( bool bTransfer, int iDownloadPriorityGroup = INVALID_DOWNLOAD_PRIORITY_GROUP );
581-
bool IsTransferringInitialFiles ( void ) { return m_bTransferringInitialFiles; }
582580
void SetTransferringSingularFiles ( bool bTransfer ) { m_bTransferringSingularFiles = bTransfer; }
583581
bool IsTransferringSingularFiles ( void ) { return m_bTransferringSingularFiles; }
584-
int GetActiveDownloadPriorityGroup ( void );
585582

586583
void SetVehExtrapolateSettings ( const SVehExtrapolateSettings& settings ) { m_VehExtrapolateSettings = settings; }
587584
const SVehExtrapolateSettings& GetVehExtrapolateSettings ( void ) { return m_VehExtrapolateSettings; }
@@ -650,6 +647,7 @@ class CClientGame
650647
CClientModelCacheManager* m_pModelCacheManager;
651648
CDebugHookManager* m_pDebugHookManager;
652649
CRemoteCalls* m_pRemoteCalls;
650+
CResourceFileDownloadManager* m_pResourceFileDownloadManager;
653651

654652
// Revised facilities
655653
CServer m_Server;
@@ -711,9 +709,7 @@ class CClientGame
711709
bool m_bShowNetstat;
712710
bool m_bShowFPS;
713711

714-
bool m_bTransferringInitialFiles;
715712
bool m_bTransferringSingularFiles;
716-
int m_iActiveDownloadPriorityGroup;
717713

718714
float m_fGameSpeed;
719715
long m_lMoney;
@@ -730,8 +726,6 @@ class CClientGame
730726

731727
CClientGUIElement* m_pClickedGUIElement;
732728

733-
eHTTPDownloadType m_ucHTTPDownloadType;
734-
unsigned short m_usHTTPDownloadPort;
735729
SString m_strHTTPDownloadURL;
736730

737731
bool m_bReceivingBigPacket;

MTA10/mods/deathmatch/logic/CDownloadableResource.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,26 @@
1313

1414
#include <StdInc.h>
1515

16-
CDownloadableResource::CDownloadableResource ( eResourceType resourceType, const char* szName, const char* szNameShort, CChecksum serverChecksum, bool bGenerateClientChecksum, bool bAutoDownload )
16+
CDownloadableResource::CDownloadableResource ( CResource* pResource, eResourceType resourceType, const char* szName, const char* szNameShort, uint uiDownloadSize, CChecksum serverChecksum, bool bAutoDownload )
1717
{
18-
// Store the resource type
18+
m_pResource = pResource;
1919
m_resourceType = resourceType;
20-
21-
// Store the name
2220
m_strName = szName;
23-
24-
// Store the name (short)
2521
m_strNameShort = szNameShort;
26-
27-
// Store the server checksum
2822
m_ServerChecksum = serverChecksum;
29-
30-
// Check to see if the client checksum should be generated now
31-
if ( bGenerateClientChecksum )
32-
{
33-
GenerateClientChecksum ();
34-
}
35-
else
36-
{
37-
// Default the last client checksum
38-
m_LastClientChecksum = CChecksum ();
39-
}
40-
4123
m_bAutoDownload = bAutoDownload;
24+
m_bInDownloadQueue = false;
4225
m_bDownloaded = false;
26+
m_uiDownloadSize = uiDownloadSize;
27+
m_uiHttpServerIndex = 0;
28+
29+
GenerateClientChecksum ();
4330
g_pClientGame->GetResourceManager()->OnAddResourceFile( this );
4431
}
4532

4633
CDownloadableResource::~CDownloadableResource ( void )
4734
{
35+
g_pClientGame->GetResourceFileDownloadManager()->OnRemoveResourceFile( this );
4836
g_pClientGame->GetResourceManager()->OnRemoveResourceFile( this );
4937
}
5038

@@ -63,3 +51,8 @@ CChecksum CDownloadableResource::GetServerChecksum ( void )
6351
{
6452
return m_ServerChecksum;
6553
}
54+
55+
int CDownloadableResource::GetDownloadPriorityGroup ( void )
56+
{
57+
return m_pResource->GetDownloadPriorityGroup();
58+
}

0 commit comments

Comments
 (0)