Esempio n. 1
0
void EXT_FUNC MSG_WriteBitString_api(const char *p) {
	MSG_WriteBitString(p);
}
void OnSV_SendResources( sizebuf_t* buf )
{
    if( cvar_enable_debug->value > 0 )
    {
        ModuleDebug.append( "\n\tSV_SendResources - Start\n" );
    }

    byte temprguc[ 32 ];

    memset( temprguc, 0, sizeof temprguc );

    MSG_WriteByte( buf, SVC_RESOURCEREQUEST );
    MSG_WriteLong( buf, CurrentServerSpawnCount );
    MSG_WriteLong( buf, 0 );

    String url = getNextCustomUrl();

    if( cvar_enable_debug->value > 0 )
    {
        if( url.c_str() )
        {
            ModuleDebug.append( UTIL_VarArgs( "\n\t\tHTTP URL : %s (size = %d)\n\n\t\t\t-> %s\n", url.c_str(), url.size(), url.size() < MaxUrlLength ? "Valid URL ; size is < 128" :  "Invalid URL ; size >= 128" ) );
        }
        else
        {
            ModuleDebug.append( "\n\t\tNo HTTP URL found\n" );
        }
    }

    if( url.c_str() && url.size() < MaxUrlLength )
    {
        MSG_WriteByte( buf, SVC_RESOURCELOCATION );
        MSG_WriteString( buf, url.c_str() );

        if( cvar_enable_debug->value > 0 )
        {
            ModuleDebug.append( "\t\t\t-> URL has been sent.\n" );
        }
    }

    MSG_WriteByte( buf, SVC_RESOURCELIST );
    MSG_StartBitWriting( buf );
    MSG_WriteBits( sv->consistencyDataCount + CustomResourcesList.size(), 12 );

    resource_t* res = NULL;

    if( sv->consistencyDataCount > 0 )
    {
        uint32 lastIndex = 0;
        uint32 genericItemsCount = 0;

        for( uint32 i = 0; i < sv->consistencyDataCount; i++ )
        {
            res = &sv->consistencyData[ i ];

            if( !genericItemsCount )
            {
                if( lastIndex && res->nIndex == 1 )
                    genericItemsCount = lastIndex;
                else
                    lastIndex = res->nIndex;
            }

            MSG_WriteBits( res->type, 4 );
            MSG_WriteBitString( res->szFileName );
            MSG_WriteBits( res->nIndex, 12 );
            MSG_WriteBits( res->nDownloadSize, 24 );
            MSG_WriteBits( res->ucFlags & 3, 3 );

            if( res->ucFlags & 4 )
                MSG_WriteBitData( res->rgucMD5_hash, 16 );

            if( memcmp( res->rguc_reserved, temprguc, sizeof temprguc ) )
            {
                MSG_WriteBits( 1, 1 );
                MSG_WriteBitData( res->rguc_reserved, 32 );
            }
            else
            {
                MSG_WriteBits( 0, 1 );
            }
        }

        if( sv_allowdownload->value > 0 && CustomResourcesList.size() )
        {
            for( CVector< resource_s* >::iterator iter = CustomResourcesList.begin(); iter != CustomResourcesList.end(); ++iter )
            {
                res = ( *iter );

                MSG_WriteBits( res->type, 4 );
                MSG_WriteBitString( res->szFileName );
                MSG_WriteBits( genericItemsCount + res->nIndex, 12 );
                MSG_WriteBits( res->nDownloadSize, 24 );
                MSG_WriteBits( res->ucFlags & 3, 3 );
                MSG_WriteBits( 0, 1 );
            }
        }
    }

    SV_SendConsistencyList();

    MSG_EndBitWriting( buf );

    if( cvar_enable_debug->value > 0 )
    {
        ModuleDebug.append( "\n\tSV_SendResources - End\n\n" );
    }
}