Raised This Month: $51 Target: $400
 12% 

[EXTENSION] Web downloader


Post New Thread Reply   
 
Thread Tools Display Modes
)v(aster
Junior Member
Join Date: Feb 2008
Old 07-13-2008 , 16:38   Re: [EXTENSION] Web downloader
Reply With Quote #21

Hi

Not too sure what i've done wrong. When I use the sample plugin, I cant find a file created. And when I run the following, I see this in the sm log:
L 07/14/2008 - 05:07:59: [m_downloadtest.smx] $$$$

EDIT: Worked it out, need to read the string in the DownloadComplete callback, as it's threadded.

Code:
public DownloadComplete(const sucess, const status, Handle:arg)
{
    PrintToServer("DownloadComplete: %i %i",sucess, status);
    CloseHandle(down);
}
public Progress(const recvSize, const totalSize, Handle:arg)
...
 
public OnPluginStart()
{
    down = CreateDownloader();
 
    SetURL(down,"http://domain/file.php/");
 
    SetCallback(down,DownloadComplete);
    SetProgressCallback(down,Progress);
 
    new String:response[1000];
 
    SetOutputString(down,response,sizeof(response));
 
    Download(down);
 
    LogMessage("$$$$%s", response); 
}

Last edited by )v(aster; 07-14-2008 at 14:36.
)v(aster is offline
sskillz
Member
Join Date: Apr 2005
Old 07-19-2008 , 09:23   Re: [EXTENSION] Web downloader
Reply With Quote #22

Reading the source code, I don't see it can handle cases that it may recieve the header in sevral calls to recv. Its possible that the first select and recv will get: "HTTP/" and the next call will get "/1.0 100 OK\r\nContent-Length:"
and the extension will ignore it.

And where do you check if the socket has been closed by the remote side? you should check if recv returns 0 to know if that happens.
sskillz is offline
Agret
Member
Join Date: Jan 2005
Location: Melbourne, Victoria
Old 09-16-2008 , 22:14   Re: [EXTENSION] Web downloader
Reply With Quote #23

Can this extension be used to simply check if a file exists and get the file size of it? It would be nice to be able to verify a map exists on the downloadurl and if not then clear the url
__________________

(¯`·._¤²°°²Agret²°°²¤_.·´¯)
¸.-~·*'˜¨¯Ï”m_†hê_ôñë_åñd_õñl¥_Åg®ê†¨˜'*·~-.¸
Agret is offline
Send a message via ICQ to Agret Send a message via AIM to Agret Send a message via MSN to Agret Send a message via Yahoo to Agret
MikeJS
Senior Member
Join Date: Nov 2008
Old 05-04-2009 , 07:55   Re: [EXTENSION] Web downloader
Reply With Quote #24

"[SM] Unable to load extension "downloader.ext.dll": Metamod attach failed"

If you could get this working again it would be great.
__________________
MikeJS is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 05-04-2009 , 09:43   Re: [EXTENSION] Web downloader
Reply With Quote #25

MikeJS, you can just use Sockets extension. You can find an example of how to download a file inside the sockets' package.
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
MikeJS
Senior Member
Join Date: Nov 2008
Old 05-04-2009 , 09:59   Re: [EXTENSION] Web downloader
Reply With Quote #26

I've tried using sockets but sometimes it doesn't strip the header from the file and sometimes adds characters to the end. (http://pastebin.com/d2e33dfd9 - from line 136)
__________________
MikeJS is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 05-04-2009 , 18:15   Re: [EXTENSION] Web downloader
Reply With Quote #27

Quote:
Originally Posted by MikeJS View Post
I've tried using sockets but sometimes it doesn't strip the header from the file and sometimes adds characters to the end. (http://pastebin.com/d2e33dfd9 - from line 136)
The header should be included only in the first packet.

On lines 158-159, pos will never be -1.
Code:
new pos = StrContains(receiveData, "\r\n\r\n")+4; if(pos!=-1) {

Also, whats up with lines 161-163?
Code:
WriteFile(file, receiveData[pos], (dataSize-pos)/4, 4); for(new i=((dataSize-pos)/4)*4;i<dataSize;i++)     WriteFile(file, receiveData[i], 1, 1); //I'd just do for(new i=pos;i<dataSize;i++)     WriteFile(file, receiveData[i], 1, 1);
__________________
plop
p3tsin is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 05-05-2009 , 12:03   Re: [EXTENSION] Web downloader
Reply With Quote #28

Quote:
Originally Posted by p3tsin View Post
The header should be included only in the first packet.
Ah, thanks.
Quote:
Originally Posted by p3tsin View Post
On lines 158-159, pos will never be -1.



Quote:
Originally Posted by p3tsin View Post
Also, whats up with lines 161-163?
Code:
WriteFile(file, receiveData[pos], (dataSize-pos)/4, 4); for(new i=((dataSize-pos)/4)*4;i<dataSize;i++)     WriteFile(file, receiveData[i], 1, 1); //I'd just do for(new i=pos;i<dataSize;i++)     WriteFile(file, receiveData[i], 1, 1);
Copy pasta from the socket thread. (http://forums.alliedmods.net/showpos...0&postcount=95)

edit: Now I'm using
PHP Code:
new pos StrContains(receiveData"\r\n\r\n")+4Handle:file OpenFile(path"ab");
for(new 
i=pos;i<dataSize;i++)
    
WriteFile(filereceiveData[i], 11); 
Now it misses a few characters from the beginning of some files. If I set it to be less than +4, it starts adding the line breaks.
__________________

Last edited by MikeJS; 05-05-2009 at 12:47.
MikeJS is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 05-05-2009 , 13:11   Re: [EXTENSION] Web downloader
Reply With Quote #29

Quote:
Originally Posted by MikeJS View Post
edit: Now I'm using
PHP Code:
new pos StrContains(receiveData"\r\n\r\n")+4Handle:file OpenFile(path"ab");
for(new 
i=pos;i<dataSize;i++)
    
WriteFile(filereceiveData[i], 11); 
Now it misses a few characters from the beginning of some files. If I set it to be less than +4, it starts adding the line breaks.
Well yeah, if StrContains returns -1, the loop will start from 3 ignoring the first few chars.

I'm using something like this:

Code:
new pos; if(g_bFirstPacket) {    //g_bFirstPacket is obviously a global var that gets set to true when a new download is started     g_bFirstPacket = false     pos = StrContains(receiveData, "\r\n\r\n") + 4; } new Handle:file = OpenFile(path, "ab"); for(new i = pos; i < dataSize; i++) {     WriteFile(file, receiveData[i], 1, 1); }
__________________
plop
p3tsin is offline
MikeJS
Senior Member
Join Date: Nov 2008
Old 05-05-2009 , 13:43   Re: [EXTENSION] Web downloader
Reply With Quote #30

Quote:
Originally Posted by p3tsin View Post
Well yeah, if StrContains returns -1, the loop will start from 3 ignoring the first few chars.
My bad. It seems to be working now, thanks.

edit: Will I have to use an adt_array rather than a single g_bFirstPacket? (if the plugin tries to download more than one plugin at the same time)
__________________

Last edited by MikeJS; 05-05-2009 at 13:52.
MikeJS is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode