📄 remote.cpp
字号:
str = _T("No Sources");
Add( _T("download_status"), str );
if ( pDownload->IsCompleted() )
{
if ( pDownload->m_bVerify == TS_TRUE )
str = _T("Verified");
else if ( pDownload->m_bVerify == TS_FALSE )
str = _T("Unverified");
}
else if ( pDownload->GetSourceCount() == 1 )
str = _T("(1 source)");
else if ( pDownload->GetSourceCount() > 1 )
str.Format( _T("(%i sources)"), pDownload->GetSourceCount() );
else
str = _T("(No sources)");
Add( _T("download_sources"), str );
Output( _T("downloadsDownload") );
if ( pDownload->m_bExpanded && CDownloadsCtrl::IsExpandable( pDownload ) )
{
for ( CDownloadSource* pSource = pDownload->GetFirstSource(), *pNext = NULL ; pSource != NULL ; pSource = pNext )
{
pNext = pSource->m_pNext;
str.Format( _T("%i"), pSource );
if ( GetKey( _T("modify_id") ) == str )
{
str = GetKey( _T("modify_action") );
str.MakeLower();
if ( str == _T("access") )
{
pDownload->Resume();
if ( pSource->m_bPushOnly )
pSource->PushRequest();
else if ( CDownloadTransfer* pTransfer = pSource->CreateTransfer() )
pTransfer->Initiate();
}
else if ( str == _T("forget") )
{
pSource->Remove( TRUE, TRUE );
continue;
}
str.Format( _T("%i"), pSource );
}
if ( Settings.Downloads.ShowSources || ( pSource->m_pTransfer != NULL && pSource->m_pTransfer->m_nState > dtsConnecting ) )
{
Add( _T("source_id"), str );
Add( _T("source_agent"), pSource->m_sServer );
Add( _T("source_nick"), pSource->m_sNick );
if ( pSource->m_pTransfer != NULL )
{
Add( _T("source_status"), pSource->m_pTransfer->GetStateText( FALSE ) );
Add( _T("source_volume"), Settings.SmartVolume( pSource->m_pTransfer->m_nDownloaded, FALSE ) );
if ( DWORD nSpeed = pSource->m_pTransfer->GetMeasuredSpeed() * 8 )
Add( _T("source_speed"), Settings.SmartVolume( nSpeed, FALSE, TRUE ) );
Add( _T("source_address"), pSource->m_pTransfer->m_sAddress );
Add( _T("source_caption"), pSource->m_pTransfer->m_sAddress + _T(" - ") + pSource->m_sNick );
}
else
{
Add( _T("source_address"), CString( inet_ntoa( pSource->m_pAddress ) ) );
Add( _T("source_caption"), CString( inet_ntoa( pSource->m_pAddress ) ) + _T(" - ") + pSource->m_sNick );
if ( pSource->m_tAttempt > 0 )
{
DWORD tNow = GetTickCount();
if ( pSource->m_tAttempt >= tNow )
{
tNow = ( pSource->m_tAttempt - tNow ) / 1000;
str.Format( _T("%.2u:%.2u"), tNow / 60, tNow % 60 );
Add( _T("source_status"), str );
}
}
}
Output( _T("downloadsSource") );
Prepare( _T("source_") );
}
}
}
Prepare( _T("download_") );
}
Output( _T("downloadsBottom") );
Output( _T("downloadsFooter") );
}
/////////////////////////////////////////////////////////////////////////////
// CRemote page : newDownload
void CRemote::PageNewDownload()
{
if ( CheckCookie() ) return;
CShareazaURL pURI;
if ( pURI.Parse( GetKey( _T("uri") ) ) ) Downloads.Add( &pURI );
m_sRedirect = _T("downloads?group_reveal=all");
}
/////////////////////////////////////////////////////////////////////////////
// CRemote page : uploads
void CRemote::PageUploads()
{
if ( CheckCookie() ) return;
CString str;
Prepare();
str.Format( _T("%i"), rand() );
Add( _T("random"), str );
Output( _T("uploadsHeader") );
for ( POSITION posQueue = CUploadsCtrl::GetQueueIterator() ; posQueue != NULL ; )
{
CUploadQueue* pQueue = CUploadsCtrl::GetNextQueue( posQueue );
str.Format( _T("%i"), pQueue );
if ( GetKey( _T("queue_expand") ) == str ) pQueue->m_bExpanded = TRUE;
else if ( GetKey( _T("queue_collapse") ) == str ) pQueue->m_bExpanded = FALSE;
POSITION posFile = CUploadsCtrl::GetFileIterator( pQueue );
if ( posFile == NULL ) continue;
Prepare();
Add( _T("queue_id"), str );
Add( _T("queue_caption"), pQueue->m_sName );
if ( pQueue->m_bExpanded ) Add( _T("queue_expanded"), _T("true") );
if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue )
{
str.Format( _T("%i"), pQueue->GetTransferCount() );
Add( _T("queue_transfers"), str );
str.Format( _T("%i"), pQueue->GetQueuedCount() );
Add( _T("queue_queued"), str );
Add( _T("queue_bandwidth"), Settings.SmartVolume( pQueue->GetMeasuredSpeed() * 8, FALSE, TRUE ) );
}
Output( _T("uploadsQueueStart") );
if ( pQueue->m_bExpanded )
{
while ( posFile != NULL )
{
int nPosition;
CUploadFile* pFile = CUploadsCtrl::GetNextFile( pQueue, posFile, &nPosition );
if ( pFile == NULL ) continue;
CUploadTransfer* pTransfer = pFile->GetActive();
str.Format( _T("%i"), pFile );
if ( GetKey( _T("drop") ) == str )
{
pFile->Remove();
continue;
}
Add( _T("file_id"), str );
Add( _T("file_filename"), pFile->m_sName );
Add( _T("file_size"), Settings.SmartVolume( pFile->m_nSize, FALSE ) );
if ( pTransfer != NULL )
{
Add( _T("file_address"), pTransfer->m_sAddress );
Add( _T("file_nick"), pTransfer->m_sNick );
Add( _T("file_user"), pTransfer->m_sAddress + _T(" - ") + pTransfer->m_sNick );
Add( _T("file_agent"), pTransfer->m_sUserAgent );
}
if ( pTransfer == NULL || pTransfer->m_nState == upsNull )
{
str = _T("Complete");
}
else if ( pTransfer->m_nProtocol == PROTOCOL_BT )
{
CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer;
if ( ! pBT->m_bInterested )
str = _T("Uninterested");
else if ( pBT->m_bChoked )
str = _T("Choked");
else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() * 8 )
str = Settings.SmartVolume( nSpeed, FALSE, TRUE );
}
else if ( nPosition > 0 )
str.Format( _T("Q %i"), nPosition );
else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() * 8 )
str = Settings.SmartVolume( nSpeed, FALSE, TRUE );
else
str = _T("Next");
Add( _T("file_speed"), str );
Add( _T("file_status"), str );
Output( _T("uploadsFile") );
Prepare( _T("file_") );
}
}
Output( _T("uploadsQueueEnd") );
Prepare( _T("queue_") );
}
Prepare();
Output( _T("uploadsFooter") );
}
/////////////////////////////////////////////////////////////////////////////
// CRemote page : network
void CRemote::PageNetwork()
{
if ( CheckCookie() ) return;
CSingleLock pLock( &Network.m_pSection );
if ( ! pLock.Lock( 1000 ) ) return;
DWORD nNeighbourID = 0;
_stscanf( GetKey( _T("drop") ), _T("%i"), &nNeighbourID );
if ( nNeighbourID != 0 )
{
if ( CNeighbour* pNeighbour = Neighbours.Get( nNeighbourID ) )
{
pNeighbour->Close();
}
}
CString str;
Prepare();
str.Format( _T("%i"), rand() );
Add( _T("random"), str );
Output( _T("networkHeader") );
PageNetworkNetwork( PROTOCOL_G2, &Settings.Gnutella2.EnableToday, _T("Gnutella2") );
PageNetworkNetwork( PROTOCOL_G1, &Settings.Gnutella1.EnableToday, _T("Gnutella1") );
PageNetworkNetwork( PROTOCOL_ED2K, &Settings.eDonkey.EnableToday, _T("eDonkey2000") );
Output( _T("networkFooter") );
}
void CRemote::PageNetworkNetwork(int nID, BOOL* pbConnect, LPCTSTR pszName)
{
CString str;
str.Format( _T("%i"), nID );
if ( GetKey( _T("connect") ) == str )
{
*pbConnect = TRUE;
Network.Connect( TRUE );
}
else if ( GetKey( _T("disconnect") ) == str )
{
*pbConnect = FALSE;
for ( POSITION pos = Neighbours.GetIterator() ; pos != NULL ; )
{
CNeighbour* pNeighbour = Neighbours.GetNext( pos );
if ( pNeighbour->m_nProtocol == PROTOCOL_NULL ||
pNeighbour->m_nProtocol == nID ) pNeighbour->Close();
}
}
Add( _T("network_id"), str );
Add( _T("network_caption"), pszName );
if ( *pbConnect ) Add( _T("network_connected"), _T("true") );
Output( _T("networkNetStart") );
for ( POSITION pos = Neighbours.GetIterator() ; pos != NULL ; )
{
CNeighbour* pNeighbour = Neighbours.GetNext( pos );
if ( pNeighbour->m_nProtocol != nID ) continue;
pNeighbour->Measure();
str.Format( _T("%i"), pNeighbour->m_nUnique );
Add( _T("row_id"), str );
Add( _T("row_address"), pNeighbour->m_sAddress );
Add( _T("row_agent"), pNeighbour->m_sUserAgent );
str.Format( _T("%i -/- %i"), pNeighbour->m_nInputCount, pNeighbour->m_nOutputCount );
Add( _T("row_packets"), str );
str.Format( _T("%s -/- %s"), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mInput.nMeasure * 8, FALSE, TRUE ), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mOutput.nMeasure * 8, FALSE, TRUE ) );
Add( _T("row_bandwidth"), str );
str.Format( _T("%s -/- %s"), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mInput.nTotal, FALSE ), (LPCTSTR)Settings.SmartVolume( pNeighbour->m_mOutput.nTotal, FALSE ) );
Add( _T("row_total"), str );
switch ( pNeighbour->m_nState )
{
case nrsConnecting:
str = _T("Connecting");
break;
case nrsHandshake1:
case nrsHandshake2:
case nrsHandshake3:
str = _T("Handshaking");
break;
case nrsRejected:
str = _T("Rejected");
break;
case nrsClosing:
str = _T("Closing");
break;
case nrsConnected:
{
DWORD tNow = ( GetTickCount() - pNeighbour->m_tConnected ) / 1000;
str.Format( _T("%i:%.2i:%.2i"), tNow / 3600, ( tNow % 3600 ) / 60, tNow % 60 );
}
break;
default:
str = _T("Unknown");
break;
}
Add( _T("row_time"), str );
if ( pNeighbour->m_nProtocol == PROTOCOL_G1 )
{
CG1Neighbour* pG1 = reinterpret_cast<CG1Neighbour*>(pNeighbour);
switch ( pNeighbour->m_nNodeType )
{
case ntNode:
str = _T("G1 Peer");
break;
case ntHub:
str = _T("G1 Ultrapeer");
break;
case ntLeaf:
str = _T("G1 Leaf");
break;
}
Add( _T("row_mode"), str );
str.Empty();
}
else if ( pNeighbour->m_nProtocol == PROTOCOL_G2 )
{
CG2Neighbour* pG2 = reinterpret_cast<CG2Neighbour*>(pNeighbour);
switch ( pNeighbour->m_nNodeType )
{
case ntNode:
str = _T("G2 Peer");
break;
case ntHub:
str = _T("G2 Hub");
break;
case ntLeaf:
str = _T("G2 Leaf");
break;
}
Add( _T("row_mode"), str );
if ( pG2->m_nLeafCount > 0 )
{
if ( pG2->m_nLeafLimit > 0 )
{
str.Format( _T("%i/%i"), pG2->m_nLeafCount, pG2->m_nLeafLimit );
}
else
{
str.Format( _T("%i"), pG2->m_nLeafCount );
}
Add( _T("row_leaves"), str );
}
str.Empty();
if ( pG2->m_pProfile != NULL ) str = pG2->m_pProfile->GetNick();
}
else if ( pNeighbour->m_nProtocol == PROTOCOL_ED2K )
{
CEDNeighbour* pED2K = reinterpret_cast<CEDNeighbour*>(pNeighbour);
if ( pED2K->m_nClientID > 0 )
{
if ( pED2K->m_nUserLimit > 0 )
{
str.Format( _T("%i/%i"), pED2K->m_nUserCount, pED2K->m_nUserLimit );
}
else
{
str.Format( _T("%i"), pED2K->m_nUserCount );
}
Add( _T("row_leaves"), str );
Add( _T("row_mode"), CEDPacket::IsLowID( pED2K->m_nClientID ) ? _T("eDonkey2000 (LowID)") : _T("eDonkey (HighID)") );
}
else
{
Add( _T("row_mode"), _T("eDonkey2000") );
}
str = pED2K->m_sServerName;
}
Add( _T("row_nick"), str );
str = pNeighbour->m_sAddress + _T(" - ") + str;
Add( _T("row_caption"), str );
Output( _T("networkRow") );
Prepare( _T("row_") );
}
Output( _T("networkNetEnd") );
Prepare( _T("network_") );
}
/////////////////////////////////////////////////////////////////////////////
// CRemote page : banner
void CRemote::PageBanner(CString& strPath)
{
HMODULE hModule = GetModuleHandle( NULL );
UINT nID = 0;
if ( strPath == _T("/remote/header_1.png") )
nID = IDR_HOME_HEADER_1;
else if ( strPath == _T("/remote/header_2.png") )
nID = IDR_HOME_HEADER_2;
if ( HRSRC hRes = FindResource( hModule, MAKEINTRESOURCE( nID ), _T("PNG") ) )
{
DWORD nSize = SizeofResource( hModule, hRes );
HGLOBAL hMemory = LoadResource( hModule, hRes );
LPVOID pSource = LockResource( hMemory );
m_pResponse.EnsureBuffer( nSize );
CopyMemory( m_pResponse.m_pBuffer, pSource, nSize );
m_pResponse.m_nLength = nSize;
m_sHeader = _T("Content-Type: image/png\r\n");
}
}
/////////////////////////////////////////////////////////////////////////////
// CRemote page : image server
void CRemote::PageImage(CString& strPath)
{
if ( CheckCookie() ) return;
strPath = strPath.Mid( 15 );
if ( strPath.Find( '%' ) >= 0 ) return;
if ( strPath.Find( '/' ) >= 0 ) return;
if ( strPath.Find( '\\' ) >= 0 ) return;
CFile hFile;
strPath = Settings.General.Path + _T("\\Remote\\images\\") + strPath;
if ( hFile.Open( strPath, CFile::modeRead ) )
{
m_pResponse.EnsureBuffer( (DWORD)hFile.GetLength() );
hFile.Read( m_pResponse.m_pBuffer, (UINT)hFile.GetLength() );
m_pResponse.m_nLength += (DWORD)hFile.GetLength();
hFile.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -