1515#include " WW3D2/surfaceclass.h"
1616#include " WW3D2/dx8wrapper.h"
1717#include < mutex>
18+ #include < utility>
1819
1920#define STB_IMAGE_WRITE_IMPLEMENTATION
2021#define STB_IMAGE_RESIZE_IMPLEMENTATION
@@ -118,7 +119,8 @@ void NGMP_OnlineServicesManager::CaptureScreenshotForProbe(EScreenshotType scree
118119 NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
119120 if (pLobbyInterface != nullptr )
120121 {
121- NGMP_OnlineServicesManager::GetInstance ()->CaptureScreenshot (true , [strURI, screenshotType](std::vector<uint8_t > vecData)
122+ const uint64_t matchID = pLobbyInterface->GetCurrentMatchID ();
123+ NGMP_OnlineServicesManager::GetInstance ()->CaptureScreenshot (true , [strURI = std::move (strURI), screenshotType, matchID](std::vector<uint8_t > vecData)
122124 {
123125 CHECK_WORKER_THREAD ;
124126
@@ -135,7 +137,7 @@ void NGMP_OnlineServicesManager::CaptureScreenshotForProbe(EScreenshotType scree
135137 }
136138 else if (screenshotType == EScreenshotType::SCREENSHOT_TYPE_SCORESCREEN )
137139 {
138- NGMP_OnlineServicesManager::GetInstance ()->CacheScreenshotBytes_EndMatch (vecData);
140+ NGMP_OnlineServicesManager::GetInstance ()->CacheScreenshotBytes_EndMatch (matchID, std::move ( vecData) );
139141 }
140142 else
141143 {
@@ -248,6 +250,13 @@ void NGMP_OnlineServicesManager::CommitReplay(AsciiString absoluteReplayPath)
248250
249251 if (serviceConf.do_replay_upload )
250252 {
253+ NGMP_OnlineServices_LobbyInterface* pLobbyInterface = NGMP_OnlineServicesManager::GetInterface<NGMP_OnlineServices_LobbyInterface>();
254+ const uint64_t matchID = pLobbyInterface == nullptr ? 0 : pLobbyInterface->GetCurrentMatchID ();
255+ if (matchID == 0 )
256+ {
257+ NetworkLog (ELogVerbosity::LOG_RELEASE , " [MediaUpload] Cannot cache replay: match ID is unavailable" );
258+ return ;
259+ }
251260 FILE * pFile = fopen (absoluteReplayPath.str (), " rb" );
252261
253262 std::vector<unsigned char > replayData;
@@ -265,11 +274,55 @@ void NGMP_OnlineServicesManager::CommitReplay(AsciiString absoluteReplayPath)
265274 }
266275
267276 // cache the data until we get an S3 URL from server
268- NGMP_OnlineServicesManager::GetInstance ()->CacheReplayBytes (replayData);
277+ NGMP_OnlineServicesManager::GetInstance ()->CacheReplayBytes (matchID, std::move ( replayData) );
269278 }
270279 }
271280}
272281
282+ void NGMP_OnlineServicesManager::CacheMatchUploadBytes (CachedMatchUpload& upload, uint64_t matchID, std::vector<uint8_t > data)
283+ {
284+ if (matchID == 0 )
285+ {
286+ return ;
287+ }
288+
289+ std::scoped_lock<std::mutex> ssLock (m_ScreenshotMutex);
290+ upload.dataMatchID = matchID;
291+ upload.bytes = std::move (data);
292+ }
293+
294+ void NGMP_OnlineServicesManager::CacheMatchUploadURI (CachedMatchUpload& upload, uint64_t matchID, std::string uri)
295+ {
296+ if (matchID == 0 )
297+ {
298+ return ;
299+ }
300+
301+ std::scoped_lock<std::mutex> ssLock (m_ScreenshotMutex);
302+ upload.uriMatchID = matchID;
303+ upload.signedURI = std::move (uri);
304+ }
305+
306+ void NGMP_OnlineServicesManager::CacheScreenshotBytes_EndMatch (uint64_t matchID, std::vector<uint8_t > data)
307+ {
308+ CacheMatchUploadBytes (m_cachedMatchEndUpload, matchID, std::move (data));
309+ }
310+
311+ void NGMP_OnlineServicesManager::CacheReplayBytes (uint64_t matchID, std::vector<uint8_t > data)
312+ {
313+ CacheMatchUploadBytes (m_cachedReplayUpload, matchID, std::move (data));
314+ }
315+
316+ void NGMP_OnlineServicesManager::SetScreenshotS3URI_EndMatch (uint64_t matchID, std::string uri)
317+ {
318+ CacheMatchUploadURI (m_cachedMatchEndUpload, matchID, std::move (uri));
319+ }
320+
321+ void NGMP_OnlineServicesManager::SetScreenshotS3URI_Replay (uint64_t matchID, std::string uri)
322+ {
323+ CacheMatchUploadURI (m_cachedReplayUpload, matchID, std::move (uri));
324+ }
325+
273326void NGMP_OnlineServicesManager::WaitForScreenshotThreads ()
274327{
275328 std::scoped_lock<std::mutex> lock (m_mutexScreenshotThreads);
@@ -910,31 +963,30 @@ void NGMP_OnlineServicesManager::Tick()
910963 }
911964 }
912965
913- if (!m_vecCachedScreenshotBytes_MatchEnd .empty ()) // we have data waiting
966+ if (!m_cachedMatchEndUpload. bytes .empty ()) // we have data waiting
914967 {
915- if (!m_strCachedScreenshot_MatchEnd_S3URI. empty ()) // and we have a URL
968+ if (m_cachedMatchEndUpload. dataMatchID == m_cachedMatchEndUpload. uriMatchID && !m_cachedMatchEndUpload. signedURI . empty ()) // and we have a matching URL
916969 {
917970 // queue it
918971 S3ScreenshotEntry newEntry;
919972 newEntry.screenshotType = EScreenshotType::SCREENSHOT_TYPE_SCORESCREEN ;
920- newEntry.vecBytes = m_vecCachedScreenshotBytes_MatchEnd ;
921- newEntry.strSignedURI = m_strCachedScreenshot_MatchEnd_S3URI ;
922- m_vecGuardedSSData.push_back (newEntry);
973+ newEntry.vecBytes = std::move (m_cachedMatchEndUpload. bytes ) ;
974+ newEntry.strSignedURI = std::move (m_cachedMatchEndUpload. signedURI ) ;
975+ m_vecGuardedSSData.push_back (std::move ( newEntry) );
923976
924977 // clear data
925- m_vecCachedScreenshotBytes_MatchEnd = std::vector<uint8_t >();
926- m_strCachedScreenshot_MatchEnd_S3URI = std::string ();
978+ m_cachedMatchEndUpload = {};
927979 }
928980 }
929981
930- if (!m_vecCachedReplayBytes .empty ()) // we have data waiting
982+ if (!m_cachedReplayUpload. bytes .empty ()) // we have data waiting
931983 {
932- if (!m_strCacheReplay_S3URI. empty ()) // and we have a URL
984+ if (m_cachedReplayUpload. dataMatchID == m_cachedReplayUpload. uriMatchID && !m_cachedReplayUpload. signedURI . empty ()) // and we have a matching URL
933985 {
934986 // do the upload
935987 std::map<std::string, std::string> mapHeaders;
936988 mapHeaders[" Content-Type" ] = " application/octet-stream" ;
937- NGMP_OnlineServicesManager::GetInstance ()->GetHTTPManager ()->SendS3PUTRequest (m_strCacheReplay_S3URI. c_str (), EIPProtocolVersion::DONT_CARE , mapHeaders, m_vecCachedReplayBytes , [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq)
989+ NGMP_OnlineServicesManager::GetInstance ()->GetHTTPManager ()->SendS3PUTRequest (m_cachedReplayUpload. signedURI . c_str (), EIPProtocolVersion::DONT_CARE , mapHeaders, m_cachedReplayUpload. bytes , [=](bool bSuccess, int statusCode, std::string strBody, HTTPRequest* pReq)
938990 {
939991#if _DEBUG
940992 if (statusCode != 200 )
@@ -947,8 +999,7 @@ void NGMP_OnlineServicesManager::Tick()
947999 }, nullptr , HTTP_UPLOAD_TIMEOUT );
9481000
9491001 // clear data
950- NGMP_OnlineServicesManager::GetInstance ()->m_vecCachedReplayBytes .clear ();
951- NGMP_OnlineServicesManager::GetInstance ()->m_strCacheReplay_S3URI = std::string ();
1002+ m_cachedReplayUpload = {};
9521003 }
9531004 }
9541005 }
0 commit comments