bool CNetChan::CheckReceivingList(int nList)
{
dataFragments_t * data = &m_ReceiveList[nList]; // get list
if ( data->buffer == NULL )
return true;
if ( data->ackedFragments < data->numFragments )
return true;
if ( data->ackedFragments > data->numFragments )
{
ConMsg("Receiving failed: too many fragments %i/%i from %s\n", data->ackedFragments, data->numFragments, GetAddress() );
return false;
}
// got all fragments
if ( net_showfragments.GetBool() )
ConMsg("Receiving complete: %i fragments, %i bytes\n", data->numFragments, data->bytes );
if ( data->isCompressed )
{
UncompressFragments( data );
}
if ( !data->filename[0] )
{
bf_read buffer( data->buffer, data->bytes );
if ( !ProcessMessages( buffer, true ) ) // parse net message
{
return false; // stop reading any further
}
}
else
{
static ConVar *s_pAllowUpload = NULL;
if ( !s_pAllowUpload )
{
s_pAllowUpload = g_pCVar->FindVar( "sv_allowupload" );
}
if ( s_pAllowUpload && s_pAllowUpload->GetBool() )
{
// Make sure that this file is not being written to a location above the current directory, isn't in
// writing to any locations we don't want, isn't an unsupported
if ( CNetChan::IsValidFileForTransfer( data->filename ) )
{
// CSGO: FileExists will fail with an invalid write path, but writing files will default to the game dir, which
// lets servers stomp existing files. Use default write path for the below calls (this is the same as the fastdl path done in
// download.h/cpp
const char *pszPathID = NULL;
// we received a file, write it to disk and notify host
if ( !g_pFileSystem->FileExists( data->filename, pszPathID ) )
{
// Make sure path exists
char szParentDir[ MAX_PATH ];
if ( !V_ExtractFilePath( data->filename, szParentDir, sizeof(szParentDir) ) )
{
szParentDir[0] = '\0';
}
g_pFileSystem->CreateDirHierarchy( szParentDir, pszPathID );
// open new file for write binary
data->file = g_pFileSystem->Open( data->filename, "wb", pszPathID );
if ( FILESYSTEM_INVALID_HANDLE != data->file )
{
g_pFileSystem->Write( data->buffer, data->bytes, data->file );
g_pFileSystem->Close( data->file );
if ( net_showfragments.GetInt() == 2 )
{
DevMsg("FileReceived: %s, %i bytes (ID %i)\n", data->filename, data->bytes, data->transferID );
}
m_MessageHandler->FileReceived( data->filename, data->transferID, data->isReplayDemo );
}
else
{
ConMsg("Failed to write received file '%s'!\n", data->filename );
}
}
else
{
// don't overwrite existing files
ConMsg("Download file '%s' already exists!\n", data->filename );
}
}
else
{
// Something about the path or extension was unnaceptable
ConMsg("Download file '%s' has invalid path or extension!\n", data->filename );
}
}
else
{
// We won't create the file if 'sv_allowupload' is not enabled
ConMsg("Download file '%s' ignored. File uploads are disabled!\n", data->filename );
}
}
// clear receiveList
if ( data->buffer )
{
delete [] data->buffer;
data->buffer = NULL;
}
return true;
}