///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::BeginResourceFileDownload
//
// Return false if file could not be queued
//
///////////////////////////////////////////////////////////////
bool CResourceFileDownloadManager::BeginResourceFileDownload(CDownloadableResource* pResourceFile, uint uiHttpServerIndex)
{
    if (uiHttpServerIndex >= m_HttpServerList.size())
        return false;

    // Find enabled server
    while (m_HttpServerList[uiHttpServerIndex].bEnabled == false)
    {
        uiHttpServerIndex++;
        if (uiHttpServerIndex >= m_HttpServerList.size())
            return false;
    }

    pResourceFile->SetHttpServerIndex(uiHttpServerIndex);

    const SHttpServerInfo&            serverInfo = m_HttpServerList[uiHttpServerIndex];
    CNetHTTPDownloadManagerInterface* pHTTP = g_pCore->GetNetwork()->GetHTTPDownloadManager(serverInfo.downloadChannel);
    SString strHTTPDownloadURLFull("%s/%s/%s", *serverInfo.strUrl, pResourceFile->GetResource()->GetName(), pResourceFile->GetShortName());

    SHttpRequestOptions options;
    options.uiConnectionAttempts = serverInfo.uiConnectionAttempts;
    options.uiConnectTimeoutMs = serverInfo.uiConnectTimeoutMs;
    options.bCheckContents = true;
    options.bIsLocal = g_pClientGame->IsLocalGame();
    SString* pstrContext = MakeDownloadContextString(pResourceFile);
    SString  strFilename = pResourceFile->GetName();
    bool bUniqueDownload = pHTTP->QueueFile(strHTTPDownloadURLFull, strFilename, pstrContext, StaticDownloadFinished, options);
    if (!bUniqueDownload)
    {
        // TODO - If piggybacking on another matching download, then adjust progress bar
        OutputDebugLine(SString("[ResourceFileDownload] Using existing download for %s", *strHTTPDownloadURLFull));
    }
    return true;
}
예제 #2
0
void CRemoteCall::MakeCall()
{
    CNetHTTPDownloadManagerInterface * downloadManager = g_pNetServer->GetHTTPDownloadManager();
    downloadManager->QueueFile ( m_strURL, NULL, 0, m_strData.c_str (), this, ProgressCallback );
    if ( !downloadManager->IsDownloading() )
        downloadManager->StartDownloadingQueuedFiles();
}
예제 #3
0
CSerialVerification::CSerialVerification ( CPlayer* pPlayer, SERIALVERIFICATIONCALLBACK pCallBack )
{
    char buf[32] = {0};
    CLogger::LogPrintf ( "VERIFY: Querying %s\n", SERIAL_VERIFICATION_SERVER );

	m_pCallBack = pCallBack;
	m_pPlayer = pPlayer;
	m_ulStartTime = GetTickCount();
	m_bFinished = false;

	if ( pPlayer->GetSerialUser().length() > 0 && pPlayer->GetSerial().length() > 0 )
	{
        // Create the POST URL
        std::string strPostData = "[\"" + pPlayer->GetSerialUser () +
                                  "\",\"" + pPlayer->GetSerial () +
                                  "\"," + itoa ( g_pGame->GetConfig ()->GetServerPort (), buf, 10 ) + "]";

        // Use CURL to perform the POST
        CNetHTTPDownloadManagerInterface * pHTTP = g_pNetServer->GetHTTPDownloadManager ();
		pHTTP->QueueFile ( SERIAL_VERIFICATION_URL, NULL, 0, strPostData.c_str (), this, ProgressCallback );
		if ( !pHTTP->IsDownloading () )
			pHTTP->StartDownloadingQueuedFiles ();
	}
	else
	{
		m_pCallBack ( m_pPlayer, false, szSerialErrorMessages[SERIAL_ERROR_INVALID_ACCOUNT] );
		m_bFinished = true;
	}
}
예제 #4
0
void CRemoteCall::MakeCall()
{
    // Bypass net module IP check if we are allowed to access the URL
    bool bAnyHost = (g_pCore->GetWebCore()->GetDomainState(g_pCore->GetWebCore()->GetDomainFromURL(m_strURL)) == eURLState::WEBPAGE_ALLOWED);
    EDownloadModeType downloadMode = g_pClientGame->GetRemoteCalls()->GetDownloadModeForQueueName(m_strQueueName, bAnyHost);
    CNetHTTPDownloadManagerInterface* pDownloadManager = g_pNet->GetHTTPDownloadManager(downloadMode);
    pDownloadManager->QueueFile(m_strURL, NULL, this, DownloadFinishedCallback, false, m_options, false, false);
}
///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::AddDownloadSize
//
// Add byte count to transfer box
//
///////////////////////////////////////////////////////////////
void CResourceFileDownloadManager::AddDownloadSize(int iSize)
{
    if (!m_bIsTransferingFiles)
    {
        GetTransferBox()->Show();
        m_bIsTransferingFiles = true;
        for (auto serverInfo : m_HttpServerList)
        {
            CNetHTTPDownloadManagerInterface* pHTTP = g_pNet->GetHTTPDownloadManager(serverInfo.downloadChannel);
            pHTTP->ResetDownloadSize();
        }
    }
    GetTransferBox()->AddToTotalSize(iSize);
}
///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::DownloadFinished
//
// Callback when file download has finished
//
///////////////////////////////////////////////////////////////
void CResourceFileDownloadManager::DownloadFinished(const SHttpDownloadResult& result)
{
    CDownloadableResource* pResourceFile = ResolveDownloadContextString((SString*)result.pObj);
    if (!pResourceFile)
        return;

    assert(ListContains(m_ActiveFileDownloadList, pResourceFile));
    if (result.bSuccess)
    {
        CChecksum checksum = CChecksum::GenerateChecksumFromFile(pResourceFile->GetName());
        if (checksum != pResourceFile->GetServerChecksum())
        {
            // Checksum failed - Try download on next server
            if (BeginResourceFileDownload(pResourceFile, pResourceFile->GetHttpServerIndex() + 1))
            {
                // Was re-added - Add size again to total.
                AddDownloadSize(pResourceFile->GetDownloadSize());
                SString strMessage("External HTTP file mismatch (Retrying this file with internal HTTP) [%s]", *ConformResourcePath(pResourceFile->GetName()));
                g_pClientGame->TellServerSomethingImportant(1011, strMessage, 3);
                return;
            }
        }
    }
    else
    {
        // Download failed due to connection type problem
        CNetHTTPDownloadManagerInterface* pHTTP = g_pNet->GetHTTPDownloadManager(m_HttpServerList[pResourceFile->GetHttpServerIndex()].downloadChannel);
        SString                           strHTTPError = pHTTP->GetError();
        // Disable server from being used (if possible)
        if (DisableHttpServer(pResourceFile->GetHttpServerIndex()))
        {
            //  Try download on next server
            if (BeginResourceFileDownload(pResourceFile, pResourceFile->GetHttpServerIndex() + 1))
            {
                // Was re-added - Add size again to total.
                AddDownloadSize(pResourceFile->GetDownloadSize());
                SString strMessage("External HTTP file download error:[%d] %s (Disabling External HTTP) [%s]", result.iErrorCode, *strHTTPError,
                                   *ConformResourcePath(pResourceFile->GetName()));
                g_pClientGame->TellServerSomethingImportant(1012, strMessage, 3);
                return;
            }
        }
        m_strLastHTTPError = strHTTPError;
    }

    // File now done (or failed)
    ListRemove(m_ActiveFileDownloadList, pResourceFile);
    pResourceFile->SetIsWaitingForDownload(false);
}
///////////////////////////////////////////////////////////////
//
// CResourceFileDownloadManager::DoPulse
//
// Downloading initial resource files
//
///////////////////////////////////////////////////////////////
void CResourceFileDownloadManager::DoPulse()
{
    if (!g_pNet->IsConnected())
        return;

    if (!IsTransferringInitialFiles())
        return;

    // Pulse the http downloads
    uint uiDownloadSizeTotal = 0;
    for (auto serverInfo : m_HttpServerList)
    {
        CNetHTTPDownloadManagerInterface* pHTTP = g_pNet->GetHTTPDownloadManager(serverInfo.downloadChannel);
        pHTTP->ProcessQueuedFiles();
        uiDownloadSizeTotal += pHTTP->GetDownloadSizeNow();
    }

    // Handle fatal error
    if (!m_strLastHTTPError.empty())
    {
        // Throw the error and disconnect
        g_pCore->GetConsole()->Printf(_("Download error: %s"), *m_strLastHTTPError);
        AddReportLog(7106, SString("Game - HTTPError (%s)", *m_strLastHTTPError));

        g_pCore->GetModManager()->RequestUnload();
        g_pCore->ShowMessageBox(_("Error") + _E("CD20"), *m_strLastHTTPError, MB_BUTTON_OK | MB_ICON_ERROR);            // HTTP Error
        m_bIsTransferingFiles = false;
        return;
    }

    // Update progress box
    GetTransferBox()->SetInfo(uiDownloadSizeTotal);
    GetTransferBox()->DoPulse();

    // Check if completed downloading current group
    if (m_ActiveFileDownloadList.empty())
    {
        // Hide progress box if all groups done
        if (m_PendingFileDownloadList.empty())
        {
            m_bIsTransferingFiles = false;
            GetTransferBox()->Hide();
        }

        // Load our newly ready resources
        g_pClientGame->GetResourceManager()->OnDownloadGroupFinished();
        UpdatePendingDownloads();
    }
}
예제 #8
0
void CRemoteCall::MakeCall()
{
    CNetHTTPDownloadManagerInterface * downloadManager = g_pNetServer->GetHTTPDownloadManager ( EDownloadMode::CALL_REMOTE );
    downloadManager->QueueFile ( m_strURL, NULL, 0, m_strData.c_str (), m_strData.length (), m_bPostBinary, this, ProgressCallback, false, m_uiConnectionAttempts, m_uiConnectTimeoutMs );
}