Raised This Month: $32 Target: $400
 8% 

[INC] HTTP


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-21-2011 , 10:20   Re: [INC] HTTP
Reply With Quote #11

Its not a plugin, its an include file which allows users to add functionality in their plugin for downloading files from the web. This can be used for many types of things from downloading maps, sound files, data files, etc.

Look in your mod folder (cstrike, etc), that is where files are saved to if no path is specified, like in my example plugin.
__________________
Bugsy is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-21-2011 , 12:10   Re: [INC] HTTP
Reply With Quote #12

Currently if you create too many downloads it will give you a index out of bounds error on line 45 (ie. iSlot == MAX_DOWNLOAD_SLOTS).

When finding the server and remote file from szRemoteFile, you could use strtok instead of copy.

Every time you use HTTP_DownloadFile, it creates a new multiforward, which is not needed. Perhaps you could destroy it when there are no more active download slots.

Instead of setting the nextthink on line 82, you should only do it if the entity was just created. This way it does not delay downloads that have already started.

If more than one plugin uses this download method, entities will "double think". This could be avoided by searching for already created http_entity instead of auto creating one.

Instead of generating a random number for the download id, I would suggest creating a global that increments with every new download. Although the chances are low, there is a possibility that two downloads could get the same download id and that would be a problem.

Instead of using a multiforward to send the download slots to other plugins (the original plugin is the only plugin that really needs the forward sent to) you should use a oneforward.

I would also suggest that you kill the entity if there are no active slots. But remember that you'll need to put in some method to avoid calling register_think more than once.

Overall, good job; I've thought of different ways I might be able to use this.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-21-2011 , 12:47   Re: [INC] HTTP
Reply With Quote #13

Thanks for the comments Emp, I will make the appropriate changes to this include as well as the FTP include since I used the same entity/forward handling in both files.
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-21-2011 , 20:17   Re: [INC] HTTP
Reply With Quote #14

A revised copy has been posted. I made all changes pointed out by Emp except for changing CreateMultiForward() to CreateOneForward(). The latter requires the plugin_id which I don't know how to obtain without requiring the user to specify information (plugin name or filename) which I don't like. If there is no performance benefit or negative aspects I don't see the point in changing it. See changelog for changes, nothing functional except for the type of download-id's returned (was random now sequential).
__________________

Last edited by Bugsy; 09-21-2011 at 20:34.
Bugsy is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 09-21-2011 , 21:02   Re: [INC] HTTP
Reply With Quote #15

Good job
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 09-22-2011 , 15:15   Re: [INC] HTTP
Reply With Quote #16

strtok when used with trimSpaces behaves very poorly (just found this out in the last month). You should set it to 0, and if you want to trim the spaces, just use trim after strtok.

And it is actually very important that you don't use multiforwards now that you have very similar download ids. Two plugins downloading at the same time with the same download id will be sent their multiforward, and then additionally the multiforward from the other plugin.

To get the plugin id (a very poor way to do it, untested):
Code:
if ( g_PluginID == INVALID_PLUGIN_ID )
{
	new szFile[ 64 ];
	get_plugin( -1, szFile, charsmax(szFile),
		szFile, 0, szFile, 0, szFile, 0, szFile, 0 );
	g_PluginID = find_plugin_byfile( szFile, 0 );
}
I'm debating whether or not you should be using set_fail_state. I think it would be better if you just used log_amx.

Also, when you get an error creating the socket, I think you should put the error code in set_fail_state/log_amx just so it is easier to look it up.

Lastly, you should check the entity within _HTTP_EntityThink to g_HTTPEntity just to make sure you are getting the think of the entity created by the plugin and not from a similar plugin.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-23-2011 , 08:27   Re: [INC] HTTP
Reply With Quote #17

Done and new revision posted. Thanks again, Emp. The only thing that needed adjustment in your get-plugin-id function is using a separate string variable for params 2-5, I guess it was setting the previous to null instead of acting as a dummy/place-holder.

This works:
PHP Code:
if ( g_iPluginID == INVALID_PLUGIN_ID )
{
    new 
szFile64 ] , szTmp];
    
get_plugin( -szFile charsmaxszFile ) , szTmp szTmp 0szTmp szTmp );
    
g_iPluginID find_plugin_byfileszFile );

__________________
Bugsy is offline
dummy82
New Member
Join Date: Oct 2011
Location: Belgrade, Serbia
Old 10-07-2011 , 23:53   Re: [INC] HTTP
Reply With Quote #18

First off all, greetings to all members of this forum and this community, this is my first post here.

And second, if you take a loot at line 94
PHP Code:
    return ( ( HTTPiSlot ][ DownloadID ] = ++g_iDownloadID ) ); 
You'll see that g_iDownloadID always get increased no matter what value iError has.

So basically if for some reason socket doesn't open in line 60,
PHP Code:
    if ( ( HTTPiSlot ][ Socket ] = socket_openHTTPiSlot ][ Server ] , 80 SOCKET_TCP iError ) ) && !iError 
plugin will never execute the statement
PHP Code:
            if ( !g_iDownloadID )
                
register_think"http_entity" "_HTTP_EntityThink" ); 
and the calls to _HTTP_EntityThink will not occur.
dummy82 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-08-2011 , 00:00   Re: [INC] HTTP
Reply With Quote #19

Yes, I should have a return after the log_amx(), thanks for the report. In this case (error at line 60) we would not want to register_think() or make the entity think since there will be no download occurring anyway.
__________________
Bugsy is offline
dummy82
New Member
Join Date: Oct 2011
Location: Belgrade, Serbia
Old 10-08-2011 , 12:28   Re: [INC] HTTP
Reply With Quote #20

I also notices that this line (111)
PHP Code:
if ( socket_changeHTTPiSlot ][ Socket ] ) ) 
cause spikes and lag on my servers. Tested on local and public server both. Although, i have changed THINK_INTERVAL to 0.5 because the first value was to low, this behavior on other hand happens when download is about to finish, when there is no more new data in socket.

Thus, i think that changing line like this
PHP Code:
if ( socket_changeHTTPiSlot ][ Socket ] ), 
can solve this issue, where 1 is waiting timeout defined in this function for socket to wait for data change.

Code:
socket_change ( socket, [ timeout = 100000 ] )
dummy82 is offline
Reply


Thread Tools
Display Modes

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 06:54.


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