Skip to content

Commit fa5109a

Browse files
committed
Refactored download finished callback
1 parent 709525c commit fa5109a

19 files changed

+137
-151
lines changed

Client/cefweb/CWebCore.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,12 @@ void CWebCore::GetFilterEntriesByType ( std::vector<std::pair<SString, bool>>& o
670670
}
671671
}
672672

673-
void CWebCore::StaticFetchRevisionFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
673+
void CWebCore::StaticFetchRevisionFinished ( const SHttpDownloadResult& result )
674674
{
675-
CWebCore* pWebCore = static_cast < CWebCore* > ( pObj );
676-
if ( bSuccess )
675+
CWebCore* pWebCore = static_cast < CWebCore* > ( result.pObj );
676+
if ( result.bSuccess )
677677
{
678-
SString strData = pCompletedData;
678+
SString strData = result.pData;
679679
SString strWhiteRevision, strBlackRevision;
680680
strData.Split ( ";", &strWhiteRevision, &strBlackRevision );
681681

@@ -701,12 +701,12 @@ void CWebCore::StaticFetchRevisionFinished ( char* pCompletedData, size_t comple
701701
}
702702
}
703703

704-
void CWebCore::StaticFetchWhitelistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
704+
void CWebCore::StaticFetchWhitelistFinished ( const SHttpDownloadResult& result )
705705
{
706-
if ( !bSuccess )
706+
if ( !result.bSuccess )
707707
return;
708708

709-
CWebCore* pWebCore = static_cast < CWebCore* > ( pObj );
709+
CWebCore* pWebCore = static_cast < CWebCore* > ( result.pObj );
710710
if ( !pWebCore->m_pXmlConfig )
711711
return;
712712

@@ -715,7 +715,7 @@ void CWebCore::StaticFetchWhitelistFinished ( char* pCompletedData, size_t compl
715715

716716
CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode ();
717717
std::vector<SString> whitelist;
718-
SString strData = pCompletedData;
718+
SString strData = result.pData;
719719
strData.Split ( ";", whitelist );
720720
CXMLNode* pListNode = pRootNode->FindSubNode ( "globalwhitelist" );
721721
if ( !pListNode )
@@ -744,12 +744,12 @@ void CWebCore::StaticFetchWhitelistFinished ( char* pCompletedData, size_t compl
744744
#endif
745745
}
746746

747-
void CWebCore::StaticFetchBlacklistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
747+
void CWebCore::StaticFetchBlacklistFinished ( const SHttpDownloadResult& result )
748748
{
749-
if ( !bSuccess )
749+
if ( !result.bSuccess )
750750
return;
751751

752-
CWebCore* pWebCore = static_cast < CWebCore* > ( pObj );
752+
CWebCore* pWebCore = static_cast < CWebCore* > ( result.pObj );
753753
if ( !pWebCore->m_pXmlConfig )
754754
return;
755755

@@ -758,7 +758,7 @@ void CWebCore::StaticFetchBlacklistFinished ( char* pCompletedData, size_t compl
758758

759759
CXMLNode* pRootNode = pWebCore->m_pXmlConfig->GetRootNode ();
760760
std::vector<SString> blacklist;
761-
SString strData = pCompletedData;
761+
SString strData = result.pData;
762762
strData.Split ( ";", blacklist );
763763
CXMLNode* pListNode = pRootNode->FindSubNode ( "globalblacklist" );
764764
if ( !pListNode )

Client/cefweb/CWebCore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class CWebCore : public CWebCoreInterface
9090
void LoadListsFromXML ( bool bWhitelist, bool bBlacklist, bool bCustomLists );
9191
void WriteCustomList ( const SString& strListName, const std::vector<SString>& customList, bool bReset = true );
9292
void GetFilterEntriesByType( std::vector<std::pair<SString, bool>>& outEntries, eWebFilterType filterType, eWebFilterState state = eWebFilterState::WEBFILTER_ALL );
93-
static void StaticFetchRevisionFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
94-
static void StaticFetchWhitelistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
95-
static void StaticFetchBlacklistFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
93+
static void StaticFetchRevisionFinished ( const SHttpDownloadResult& result );
94+
static void StaticFetchWhitelistFinished ( const SHttpDownloadResult& result );
95+
static void StaticFetchBlacklistFinished ( const SHttpDownloadResult& result );
9696

9797
private:
9898
typedef std::pair<bool, eWebFilterType> WebFilterPair;

Client/core/CVersionUpdater.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class CVersionUpdater : public CVersionUpdaterInterface
7474
CNetHTTPDownloadManagerInterface* GetHTTP ( void );
7575
void GetSaveLocationList ( std::list < SString >& outSaveLocationList, const SString& strFilename );
7676
SString GetResumableSaveLocation ( const SString& strFilename, const SString& strMD5, uint iFilesize );
77-
static void StaticDownloadFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
78-
void DownloadFinished ( char* pCompletedData, size_t completedLength, bool bSuccess, int iErrorCode );
77+
static void StaticDownloadFinished ( const SHttpDownloadResult& result );
78+
void DownloadFinished ( const SHttpDownloadResult& result );
7979

8080
// Commands
8181
void _UseMasterFetchURLs ( void );
@@ -3277,26 +3277,26 @@ int CVersionUpdater::DoSendDownloadRequestToNextServer ( void )
32773277
// Handle when download finishes
32783278
//
32793279
///////////////////////////////////////////////////////////////
3280-
void CVersionUpdater::StaticDownloadFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
3280+
void CVersionUpdater::StaticDownloadFinished ( const SHttpDownloadResult& result )
32813281
{
3282-
((CVersionUpdater*)pObj)->DownloadFinished( pCompletedData, completedLength, bSuccess, iErrorCode );
3282+
((CVersionUpdater*)result.pObj)->DownloadFinished( result );
32833283
}
32843284

3285-
void CVersionUpdater::DownloadFinished( char* pCompletedData, size_t completedLength, bool bSuccess, int iErrorCode )
3285+
void CVersionUpdater::DownloadFinished( const SHttpDownloadResult& result )
32863286
{
3287-
if ( bSuccess )
3287+
if ( result.bSuccess )
32883288
{
32893289
m_JobInfo.downloadStatus = EDownloadStatus::Success;
3290-
m_JobInfo.iDownloadResultCode = iErrorCode;
3290+
m_JobInfo.iDownloadResultCode = result.iErrorCode;
32913291
// Save data if a file wasn't used
3292-
m_JobInfo.downloadBuffer.resize( completedLength );
3293-
if ( completedLength > 0 )
3294-
memcpy ( &m_JobInfo.downloadBuffer[0], pCompletedData, completedLength );
3292+
m_JobInfo.downloadBuffer.resize( result.dataSize );
3293+
if ( result.dataSize > 0 )
3294+
memcpy ( &m_JobInfo.downloadBuffer[0], result.pData, result.dataSize );
32953295
}
32963296
else
32973297
{
32983298
m_JobInfo.downloadStatus = EDownloadStatus::Failure;
3299-
m_JobInfo.iDownloadResultCode = iErrorCode;
3299+
m_JobInfo.iDownloadResultCode = result.iErrorCode;
33003300
}
33013301
}
33023302

Client/core/Serverbrowser/CServerBrowser.RemoteMasterServer.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class CRemoteMasterServer : public CRemoteMasterServerInterface
3535
bool ParseListVer2 ( CServerListItemList& itemList );
3636
CServerListItem* GetServerListItem ( CServerListItemList& itemList, in_addr Address, ushort usGamePort );
3737
CNetHTTPDownloadManagerInterface* GetHTTP ( void );
38-
static void StaticDownloadFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
39-
void DownloadFinished ( char* pCompletedData, size_t completedLength, bool bSuccess, int iErrorCode );
38+
static void StaticDownloadFinished ( const SHttpDownloadResult& result );
39+
void DownloadFinished ( const SHttpDownloadResult& result );
4040

4141
long long m_llLastRefreshTime;
4242
SString m_strStage;
@@ -139,10 +139,10 @@ void CRemoteMasterServer::Refresh ( void )
139139
// Callback during ProcessQueuedFiles
140140
//
141141
///////////////////////////////////////////////////////////////
142-
void CRemoteMasterServer::StaticDownloadFinished( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
142+
void CRemoteMasterServer::StaticDownloadFinished( const SHttpDownloadResult& result )
143143
{
144-
CRemoteMasterServer* pRemoteMasterServer = (CRemoteMasterServer*)pObj;
145-
pRemoteMasterServer->DownloadFinished( pCompletedData, completedLength, bSuccess, iErrorCode );
144+
CRemoteMasterServer* pRemoteMasterServer = (CRemoteMasterServer*)result.pObj;
145+
pRemoteMasterServer->DownloadFinished( result );
146146
pRemoteMasterServer->Release(); // Unkeep alive
147147
}
148148

@@ -154,14 +154,14 @@ void CRemoteMasterServer::StaticDownloadFinished( char* pCompletedData, size_t c
154154
// Callback during ProcessQueuedFiles
155155
//
156156
///////////////////////////////////////////////////////////////
157-
void CRemoteMasterServer::DownloadFinished( char* pCompletedData, size_t completedLength, bool bSuccess, int iErrorCode )
157+
void CRemoteMasterServer::DownloadFinished( const SHttpDownloadResult& result )
158158
{
159-
if ( bSuccess )
159+
if ( result.bSuccess )
160160
{
161161
if ( m_strStage == "waitingreply" )
162162
{
163163
m_strStage = "hasdata";
164-
m_Data = CBuffer ( pCompletedData, completedLength );
164+
m_Data = CBuffer ( result.pData, result.dataSize );
165165
if ( !CheckParsable() )
166166
m_strStage = "nogood";
167167
}

Client/mods/deathmatch/logic/CRemoteCalls.cpp

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -201,46 +201,34 @@ void CRemoteCall::MakeCall()
201201
pDownloadManager->QueueFile(m_strURL, NULL, 0, m_strData.c_str(), m_strData.length(), m_bPostBinary, this, DownloadFinishedCallback, false, m_uiConnectionAttempts, m_uiConnectTimeoutMs);
202202
}
203203

204-
void CRemoteCall::DownloadFinishedCallback( char * data, size_t dataLength, void * obj, bool bSuccess, int iErrorCode )
204+
void CRemoteCall::DownloadFinishedCallback(const SHttpDownloadResult& result)
205205
{
206-
//printf("Progress: %s\n", data);
207-
if ( bSuccess )
206+
CRemoteCall* pCall = (CRemoteCall*)result.pObj;
207+
if (!g_pClientGame->GetRemoteCalls()->CallExists(pCall))
208+
return;
209+
210+
CLuaArguments arguments;
211+
if (result.bSuccess)
208212
{
209-
CRemoteCall * call = (CRemoteCall*)obj;
210-
if ( g_pClientGame->GetRemoteCalls()->CallExists(call) )
213+
if (pCall->IsFetch())
211214
{
212-
//printf("RECIEVED: %s\n", data);
213-
CLuaArguments arguments;
214-
if ( call->IsFetch () )
215-
{
216-
arguments.PushString ( std::string ( data, dataLength ) );
217-
arguments.PushNumber ( 0 );
218-
for ( uint i = 0 ; i < call->GetFetchArguments ().Count () ; i++ )
219-
arguments.PushArgument ( *( call->GetFetchArguments ()[i] ) );
220-
}
221-
else
222-
arguments.ReadFromJSONString ( data );
223-
224-
arguments.Call ( call->m_VM, call->m_iFunction);
225-
226-
g_pClientGame->GetRemoteCalls()->Remove(call); // delete ourselves
215+
arguments.PushString(std::string(result.pData, result.dataSize));
216+
arguments.PushNumber(0);
227217
}
218+
else
219+
arguments.ReadFromJSONString(result.pData);
228220
}
229221
else
230222
{
231-
CRemoteCall * call = (CRemoteCall*)obj;
232-
if ( g_pClientGame->GetRemoteCalls()->CallExists(call) )
233-
{
234-
CLuaArguments arguments;
235-
arguments.PushString("ERROR");
236-
arguments.PushNumber( iErrorCode );
237-
if ( call->IsFetch () )
238-
for ( uint i = 0 ; i < call->GetFetchArguments ().Count () ; i++ )
239-
arguments.PushArgument ( *( call->GetFetchArguments ()[i] ) );
223+
arguments.PushString("ERROR");
224+
arguments.PushNumber(result.iErrorCode);
225+
}
240226

241-
arguments.Call ( call->m_VM, call->m_iFunction);
227+
// Append stored arguments
228+
if (pCall->IsFetch())
229+
for (uint i = 0; i < pCall->GetFetchArguments().Count(); i++ )
230+
arguments.PushArgument(*(pCall->GetFetchArguments()[i]));
242231

243-
g_pClientGame->GetRemoteCalls()->Remove(call); // delete ourselves
244-
}
245-
}
232+
arguments.Call(pCall->m_VM, pCall->m_iFunction);
233+
g_pClientGame->GetRemoteCalls()->Remove(pCall);
246234
}

Client/mods/deathmatch/logic/CRemoteCalls.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CRemoteCall
3939
CRemoteCall ( const char * szURL, CLuaArguments * fetchArguments, const SString& strPostData, bool bPostBinary, CLuaMain * luaMain, const CLuaFunctionRef& iFunction, const SString& strQueueName, uint uiConnectionAttempts, uint uiConnectTimeoutMs );
4040
~CRemoteCall ();
4141
void MakeCall();
42-
static void DownloadFinishedCallback( char * data, size_t dataLength, void * obj, bool bSuccess, int iErrorCode );
42+
static void DownloadFinishedCallback( const SHttpDownloadResult& result );
4343
CLuaMain * GetVM() {return m_VM;};
4444
bool IsFetch() {return m_bIsFetch;}
4545
CLuaArguments& GetFetchArguments() {return m_FetchArguments;}

Client/mods/deathmatch/logic/CResourceFileDownloadManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ bool CResourceFileDownloadManager::BeginResourceFileDownload( CDownloadableResou
248248
// Callback when file download has finished
249249
//
250250
///////////////////////////////////////////////////////////////
251-
void CResourceFileDownloadManager::StaticDownloadFinished( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
251+
void CResourceFileDownloadManager::StaticDownloadFinished( const SHttpDownloadResult& result )
252252
{
253-
g_pClientGame->GetResourceFileDownloadManager()->DownloadFinished( pCompletedData, completedLength, pObj, bSuccess, iErrorCode );
253+
g_pClientGame->GetResourceFileDownloadManager()->DownloadFinished( result );
254254
}
255255

256256

@@ -261,14 +261,14 @@ void CResourceFileDownloadManager::StaticDownloadFinished( char* pCompletedData,
261261
// Callback when file download has finished
262262
//
263263
///////////////////////////////////////////////////////////////
264-
void CResourceFileDownloadManager::DownloadFinished( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode )
264+
void CResourceFileDownloadManager::DownloadFinished( const SHttpDownloadResult& result )
265265
{
266-
CDownloadableResource* pResourceFile = ResolveDownloadContextString( (SString*)pObj );
266+
CDownloadableResource* pResourceFile = ResolveDownloadContextString( (SString*)result.pObj );
267267
if ( !pResourceFile )
268268
return;
269269

270270
assert( ListContains( m_ActiveFileDownloadList, pResourceFile ) );
271-
if ( bSuccess )
271+
if ( result.bSuccess )
272272
{
273273
CChecksum checksum = CChecksum::GenerateChecksumFromFile( pResourceFile->GetName() );
274274
if ( checksum != pResourceFile->GetServerChecksum() )
@@ -297,7 +297,7 @@ void CResourceFileDownloadManager::DownloadFinished( char* pCompletedData, size_
297297
{
298298
// Was re-added - Add size again to total.
299299
AddDownloadSize( pResourceFile->GetDownloadSize() );
300-
SString strMessage( "External HTTP file download error:[%d] %s (Disabling External HTTP) [%s]", iErrorCode, *strHTTPError, *ConformResourcePath( pResourceFile->GetName() ) );
300+
SString strMessage( "External HTTP file download error:[%d] %s (Disabling External HTTP) [%s]", result.iErrorCode, *strHTTPError, *ConformResourcePath( pResourceFile->GetName() ) );
301301
g_pClientGame->TellServerSomethingImportant( 1012, strMessage, 3 );
302302
return;
303303
}

Client/mods/deathmatch/logic/CResourceFileDownloadManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class CResourceFileDownloadManager
3434
void AddDownloadSize ( int iSize );
3535
bool DisableHttpServer ( uint uiHttpServerIndex );
3636
bool BeginResourceFileDownload ( CDownloadableResource* pDownloadableResource, uint uiHttpServerIndex );
37-
static void StaticDownloadFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
38-
void DownloadFinished ( char* pCompletedData, size_t completedLength, void *pObj, bool bSuccess, int iErrorCode );
37+
static void StaticDownloadFinished ( const SHttpDownloadResult& result );
38+
void DownloadFinished ( const SHttpDownloadResult& result );
3939
SString* MakeDownloadContextString ( CDownloadableResource* pDownloadableResource );
4040
CDownloadableResource* ResolveDownloadContextString ( SString* pString );
4141

Client/mods/deathmatch/logic/CSingularFileDownload.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,10 @@ CSingularFileDownload::~CSingularFileDownload ( void )
5050
}
5151

5252

53-
void CSingularFileDownload::DownloadFinishedCallBack ( char *data, size_t dataLength, void *obj, bool bSuccess, int iErrorCode )
53+
void CSingularFileDownload::DownloadFinishedCallBack ( const SHttpDownloadResult& result )
5454
{
55-
if ( bSuccess )
56-
{
57-
CSingularFileDownload * pFile = (CSingularFileDownload*)obj;
58-
pFile->CallFinished ( true );
59-
}
60-
else
61-
{
62-
CSingularFileDownload * pFile = (CSingularFileDownload*)obj;
63-
pFile->CallFinished ( false );
64-
}
55+
CSingularFileDownload* pFile = (CSingularFileDownload*)result.pObj;
56+
pFile->CallFinished(result.bSuccess);
6557
}
6658

6759

Client/mods/deathmatch/logic/CSingularFileDownload.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CSingularFileDownload
3131
CSingularFileDownload ( CResource* pResource, const char* szName, const char* szNameShort, SString strHTTPURL, CChecksum serverChecksum );
3232
~CSingularFileDownload ( void );
3333

34-
static void DownloadFinishedCallBack ( char * data, size_t dataLength, void * obj, bool bSuccess, int iErrorCode );
34+
static void DownloadFinishedCallBack ( const SHttpDownloadResult& result );
3535

3636
bool DoesClientAndServerChecksumMatch ( void );
3737

0 commit comments

Comments
 (0)