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

HTTP Downloader


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   General Purpose        Approver:   Hawk552 (427)
Bentski
Junior Member
Join Date: Jun 2007
Old 11-12-2007 , 08:58   HTTP Downloader
Reply With Quote #1

HTTP Downloader v1.0

Description

Allows server to download files from the web.
Useful for plugins that need auto-updater.

Requirements
  • Amx Mod X 1.76 or greater
  • Sockets module
Note: default download limit is 10. to change it open include/httpdl.inc and change the value of MAX_DOWNLOADS then recompile then plugin.

Example

PHP Code:
#include <amxmodx>
#include <httpdl>

public plugin_init() {
    
register_clcmd("say /dl""test");
}

public 
test(id) {
    new 
dlid download("http://google.com/""addons/amxmodx/data/google.txt");
}

// Called when file is downloaded
public dlcomplete(idfile[]) {
    
server_print("Downloaded (id: %d) %s"idfile);

Attached Files
File Type: sma Get Plugin or Get Source (httpdl.sma - 7857 views - 2.7 KB)
File Type: inc httpdl.inc (767 Bytes, 4411 views)
File Type: zip httpdl.zip (2.2 KB, 5311 views)

Last edited by Bentski; 11-15-2007 at 13:31.
Bentski is offline
vvg125
AMX Mod X Beta Tester
Join Date: Dec 2006
Location: Queens (Douglaston), New
Old 11-12-2007 , 09:24   Re: HTTP Downloader
Reply With Quote #2

Interesting.... And definitely unique.
__________________
vvg125 is offline
Send a message via AIM to vvg125 Send a message via MSN to vvg125 Send a message via Yahoo to vvg125
ABC3Q
Junior Member
Join Date: Mar 2007
Old 11-12-2007 , 10:37   Re: HTTP Downloader
Reply With Quote #3

sv_downloadurl does the same thing if you're missing a file.
__________________
| Account has been abandoned |
ABC3Q is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 11-12-2007 , 10:41   Re: HTTP Downloader
Reply With Quote #4

Quote:
Originally Posted by ABC3Q View Post
sv_downloadurl does the same thing if you're missing a file.
Not really, you can't download other files than ".wav/.mp3/.bsp/...", with this you can download any file ;)

WootZ! Gj
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
voice
Member
Join Date: Nov 2007
Location: Principality of Liechten
Old 12-25-2007 , 19:48   Re: HTTP Downloader
Reply With Quote #5

Quote:
Originally Posted by Alka View Post
Not really, you can't download other files than ".wav/.mp3/.bsp/...", with this you can download any file ;)

WootZ! Gj
You are lying, tell tall stories...

Quote:
Overview This tutorial is to explain the purpose of RES files. What they're for, how to create them, where to put them, etc. You only need to be concerned with RES files if you're putting a custom map on an online server (Counter-Strike, HL Deathmatch, TFC, etc.) You need to use a RES file if you want to "push" to clients a WAD file, sky textures, sounds, etc. that are required in the map. If you're making a single-player map for people to download, you needn't be concerned with RES files at all.
What is a RES file?
A RES file is simply a text file, containing a list of other files. The RES file goes along with your compiled BSP file. A RES file is used to instruct the Half-Life server to send the specified files to clients that do not have your custom art or sounds. The RES file must be named just like your BSP file, except with a .RES extension. So if your map was named cs_mymap.bsp, you would create a RES file called cs_mymap.res. The RES file must be in the same directory as your BSP... in other words, the maps directory under the mod.
It works like this:


1. The server changes to your custom map, or a client connects while your map is on
2. The server looks for a RES file that matches the name of the BSP
3. The server loads the RES file and looks for images/sounds/stuff that need to be sent to clients
4. If the client machine does not have the specified file(s) (or the file(s) are not the same date/size,) the server will send them to the client
5. Once ALL files referenced in the RES file are downloaded by the client, the client connects and is able to play


It is important to note that the client will be unable to play your map until all of the files have been received. This is because you will likely have textures and other such files that are critical to the HL engine. As such, if you've got a lot of custom files or a large WAD file, you might want to consider either trimming down the size. You can do this by removing any unused textures from your WAD so it is as small as possible. Another method would be to try and find any textures that you're only using in a couple places. Are they really necessary? Would it be possible to use some other texture and get the same effect? Clients generally do not have much patience while waiting for large numbers of big files to download, and they'll likely just cancel out. So the more clean-up you do the better off everyone else will be.
Creating your RES file
Since RES files are just text files, you can use any generic text application to create and edit it. I use notepad, but anything will do, so long as it writes a generic ASCII text file with no special formatting.
There are utility programs out there that will edit RES files specifically, but I haven't worked with any of them so I can't describe what they can be used for.
RES layout
The layout of the RES file is pretty straight-forward. You describe exactly one file per line. In order for the server to find your files in the directory structure of a mod (like cstrike,) you need to specify its path. This path relative to the "root" directory. In all cases, the "root" directory is always the mod directory that the server is playing. For a Counter-Strike server, this would be c:\hlserver\cstrike. For a TFC server, this would be c:\hlserver\tfc. So consider the "root" directory as the absolute base for where your custom files would be referenced from.
You may be thinking to yourself already, "Does that mean I can't send files that exist outside of the mod directory?" Good question! The answer is: no you cannot. In fact, if you try and specify files that reside elsewhere, the server crashes. While testing this tutorial, I did just that on a public CS server while trying to specify a file at the root of the hard drive. Not pretty. Lesson: only files that exist at or under the mod directory structure can be specified.
Now how do you actually specify the path, relative to this "root" directory? It's fairly easy: just prepend the name of your file with the folder(s) that your file is stored in. For example, let's say you're working on a map for Counter-Strike. The root directory for this mod is c:\hlserver\cstrike. You've made a cool map, and you have some sky textures that need to go with it. Sky textures are stored in the c:\hlserver\cstrike\gfx\env folder. Since c:\hlserver\cstrike is to be considered the root, you only need to specify the gfx\env part. So with those 6 sky textures, here's what your RES file would look like:
gfx\env\mysky_up.tga
gfx\env\mysky_dn.tga
gfx\env\mysky_lf.tga
gfx\env\mysky_rt.tga
gfx\env\mysky_ft.tga
gfx\env\mysky_bk.tga

Now let's say we've got some sound files that also need to go with those sky textures. The sounds are stored in the c:\hlserver\cstrike\sound\misc directory. Here, the relative path is just sound\misc. Here's the updated RES file, with our sounds added:
gfx\env\mysky_up.tga
gfx\env\mysky_dn.tga
gfx\env\mysky_lf.tga
gfx\env\mysky_rt.tga
gfx\env\mysky_ft.tga
gfx\env\mysky_bk.tga
sound\misc\metaldoor.wav
sound\misc\heavychain.wav

Is there any way to avoid a RES file?
For wall textures in your map, the answer is Yes. For sky textures, sounds, models, or anything else you might have created, the answer is No. If you've just got a WAD file to go with the map and you want to avoid having to use a RES file, you can just re-compile your map with a command-line option:



qcsg -nowadtextures mymap.map This will force the compiler to put the actual textures directly inside the compiled BSP file. This has its advantages and disadvantages. On the pro side, if you only have custom textures, you can keep everything together in one BSP file which makes it really easy to put up on servers and give to people. You won't need a RES file at all.
On the con side, if you're using lots of textures from Half-Life, or any other of the pre-existing WAD files that either came with the mod, those textures are also going to be stored inside your BSP. This, of course, makes your BSP much larger than if you kept them separate. There is no way to stop this from happening; it is either all or nothing. This could potentially be a huge waste of file space and download time since the client may already have them. The more unique textures you add, the larger your BSP grows. 5, 6, 7 meg files are not uncommon. For modem users, this is an unbearable download, and the map might even change before they get the entire BSP downloaded.
Another con for the -nowadtextures option is that if you make even a small change to the map, say for something as simple as some new spawn points, the entire BSP (all 5 megs of it) will have to be downloaded again. If you keep the WAD file separate, you can make changes to the BSP and the clients will only have to download that portion (read: smaller!)
Which way you go is up to you, and varies depending on exactly what textures you're using and where your map is going to be located. If you don't mind working with RES files, it really is the best option.
voice is offline
imindfreak
Senior Member
Join Date: Oct 2007
Location: 127.0.0.1
Old 12-25-2007 , 20:53   Re: HTTP Downloader
Reply With Quote #6

aweesome, very unique plugin!
+1 K
__________________
BeastGaming Community - Map Maker & Coder.
imindfreak is offline
Old 11-12-2007, 10:41
dangerix
This message has been deleted by dangerix. Reason: too slow
Toster v2.1
Senior Member
Join Date: Oct 2006
Location: Latvia, Riga
Old 11-12-2007 , 11:10   Re: HTTP Downloader
Reply With Quote #8

Gj! +K
__________________
I am 52% addicted to Counterstrike. What about you?
Toster v2.1 is offline
Send a message via Skype™ to Toster v2.1
hackziner
Senior Member
Join Date: Sep 2006
Location: France
Old 11-12-2007 , 13:08   Re: HTTP Downloader
Reply With Quote #9

Ah nice

Quote:
// is there a better way to write binary data to a file? :S
I don't think so ... other functions (fwrite_blocks,...) are still not working
__________________
hackziner is offline
Send a message via ICQ to hackziner Send a message via AIM to hackziner Send a message via MSN to hackziner Send a message via Yahoo to hackziner Send a message via Skype™ to hackziner
travo
Senior Member
Join Date: Aug 2006
Old 11-12-2007 , 14:18   Re: HTTP Downloader
Reply With Quote #10

ahh very nice. but what files would you want to download other than the map related files? and what uses would they hold?
travo 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 08:52.


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