Thread: [INC] HTTP
View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-29-2011 , 12:19   Re: [INC] HTTP
Reply With Quote #27

New version is up:

v0.4
  • Changed socket_change() timeout from default of 100000 to 0 to avoid blocking.
  • Added file size to download progress forward.
  • Added FTP_AbortTransfer() function to stop a current file transfer.
  • Fixed bug where if an error occurred opening\creating the local file the download would still proceed. Reported by dummy82.

For what you're trying to do drekes, I did not want to add a function that solely retrieved file-size because it would be a lot of redundant code. What you can do instead is start a transfer and on the first forward call you can compare existing size to new size and abort transfer if same, like in the example below. I have not thoroughly tested a lot of files to see if 'Content-Size' is always included in the http header, if it's not included then file-size will just be 0 in the forward.
PHP Code:
#include <amxmodx>
#include <http>

new const Version[] = "0.1";

new 
g_CurrentSize 5242880;

public 
plugin_init()
{
    
register_plugin"HTTP Test" Version "bugsy" );
    
    
register_concmd"test" "DownloadFile" );
}

public 
DownloadFile()
{
    
HTTP_DownloadFile"http://download.thinkbroadband.com/5MB.zip" "ZIP.ZIP" );
}

public 
HTTP_Download( const szFile[] , iDownloadID iBytesRecv iFileSize bool:TransferComplete )
{
    if ( 
iFileSize == g_CurrentSize )
    {
        
server_print"No change in file size" );
        
HTTP_AbortTransferiDownloadID );
        return;
    }
    
    if ( 
TransferComplete )
    {
        
server_print"%s download complete!" szFile );
    }
    else
    {
        
server_print"File=[%s] DownloadID=%d BytesTransferred=%d Size=%d" szFile iDownloadID iBytesRecv iFileSize );
    }

__________________

Last edited by Bugsy; 10-29-2011 at 12:21.
Bugsy is offline