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

HTTP Downloader Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
devicenull
Veteran Member
Join Date: Mar 2004
Location: CT
Old 08-15-2008 , 01:15   HTTP Downloader Plugin
Reply With Quote #1

This (mostly) replaces my downloader plugin. It uses the sockets module to download a file via HTTP.

This works right now, I wouldn't exactly call it well tested. I'm posting it here rather then in the plugins area as it needs some cleanup before it goes there.

You can get it from http://devicenull.org/files/downloader.0.0.0.1.zip

It only adds one function:
Code:
functag DownloadFile_Sucess public(any:arg);
functag DownloadFile_Error public(type,num,any:arg);

native DownloadFile(const String:destname[],const String:host[],const String:path[],DownloadFile_Sucess:suc,DownloadFile_Error:err,any:arg);
Example:
Code:
#include <sourcemod>
#include <downloader>

public DownloadFile_Sucess:sucess(arg)
{
	PrintToServer("sucess %i",arg);
}

public DownloadFile_Error:error(type,num,arg)
{
	PrintToServer("error %i %i %i",type,num,arg);
}

public OnPluginStart()
{
DownloadFile("devicenull.org.txt","www.devicenull.org","",DownloadFile_Sucess:sucess,DownloadFile_Error:error,1337);
}
__________________
Various bits of semi-useful code in a bunch of languages: http://code.devicenull.org/
devicenull is offline
SirLamer
Senior Member
Join Date: Oct 2008
Old 12-22-2008 , 16:25   Re: HTTP Downloader Plugin
Reply With Quote #2

There are a couple issues with the code, one of which is critical.

1. The library name of the downloader.sp plugin is not defined. This needs to occur in OnPluginStart() of downloader.sp. The library name doesn't have to match the file name but it DOES have to match the "name" field as defined in the include file.

In downloader.sp:
Code:
public OnPluginStart()
{
	RegPluginLibrary("downloader");
	...
}
Reference: http://wiki.alliedmods.net/Optional_...Mod_Scripting)

2. An array looks for "MAX_URL_LEN" for the string length when being created. I put #define MAX_URL_LEN 298 in to make it work.


3. Spelling of the word "success" is consistently mispelt as "sucess". The code compiles and works, but since users of this plug-in have to insert "DownloadFile_Sucess" in their code, I can imagine people missing the spelling error, spelling it correctly in their own code and causing errors.


I have not yet tested this plug-in to see if it works beyond running and hooking with my own plug-in, but I have spent a couple of days trying to figure out why my plug-in wasn't able to hook with Downloader when it was successfully running. I'll report if I find more issues and how I was able to resolve them.

Last edited by SirLamer; 12-23-2008 at 19:39.
SirLamer is offline
MulleDK19
New Member
Join Date: Jan 2009
Old 01-13-2009 , 18:33   Re: HTTP Downloader Plugin
Reply With Quote #3

Quote:
Originally Posted by SirLamer View Post
There are a couple issues with the code, one of which is critical.

1. The library name of the downloader.sp plugin is not defined. This needs to occur in OnPluginStart() of downloader.sp. The library name doesn't have to match the file name but it DOES have to match the "name" field as defined in the include file.

In downloader.sp:
Code:
public OnPluginStart()
{
	RegPluginLibrary("downloader");
	...
}
Reference: http://wiki.alliedmods.net/Optional_...Mod_Scripting)

2. An array looks for "MAX_URL_LEN" for the string length when being created. I put #define MAX_URL_LEN 298 in to make it work.


3. Spelling of the word "success" is consistently mispelt as "sucess". The code compiles and works, but since users of this plug-in have to insert "DownloadFile_Sucess" in their code, I can imagine people missing the spelling error, spelling it correctly in their own code and causing errors.


I have not yet tested this plug-in to see if it works beyond running and hooking with my own plug-in, but I have spent a couple of days trying to figure out why my plug-in wasn't able to hook with Downloader when it was successfully running. I'll report if I find more issues and how I was able to resolve them.
That, and it downloads 1 byte too little!!!
If I upload a 300 byte file, the downloaded is only 299 bytes.

Other than that, awesome plugin, thx

Edit: I just found out that it completely corrupts the files it downloads. The first part of the downloaded file is fine. But like 10% into the file, it misses a character, starts putting the rest where that char should have been, resulting in all bytes being placed one position less than they should.

Last edited by MulleDK19; 01-14-2009 at 06:41.
MulleDK19 is offline
SirLamer
Senior Member
Join Date: Oct 2008
Old 01-14-2009 , 10:54   Re: HTTP Downloader Plugin
Reply With Quote #4

Yeah, I was going to use this script for a large plug-in I am developing but gave up on it and found another way to do what I need.
SirLamer is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 01-14-2009 , 14:18   Re: HTTP Downloader Plugin
Reply With Quote #5

Quote:
Originally Posted by SirLamer View Post
Yeah, I was going to use this script for a large plug-in I am developing but gave up on it and found another way to do what I need.
Just use Sockets Extension.
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
SirLamer
Senior Member
Join Date: Oct 2008
Old 01-14-2009 , 19:14   Re: HTTP Downloader Plugin
Reply With Quote #6

Nah it's not like that, I'm making a large database-driven script that loads in MOTD. I was having a PHP script do a database search then upload the results to the server, just to keep the load off of the game server machine, but I just bit the bullet and SourcePawn is handling the database search instead... though it also forced me to rearrange the relationships between my game server and remote server.
SirLamer 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 15:06.


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