05-11-2007, 10:52 AM
i had a large trouble with my server, because i had two smallish servers that i could use (each was the free webspace given to me and a friend by our isps) but the files i wanted to serve for the server were too numerous for a single sv_downloadurl. Srcds, to my knowledge, has no way of allowing more than one file server and thus i had run into a bit of a sticking point.
However i devised this little PHP script for myself, which i have now commented up and made usable (i hope) for anyone with a little knowledge about PHP (or computers).
everything you need to know is explained in the code, so here it is:
and remember, though my title says hack, its not a hack in the bad way
However i devised this little PHP script for myself, which i have now commented up and made usable (i hope) for anyone with a little knowledge about PHP (or computers).
everything you need to know is explained in the code, so here it is:
Code:
<?php
/*
#################################################################################
-gµssy sv_downloadurl multi server hack script
-version 1.0a
-this is not a hack in the bad sense, its a hack in that it makes srcds do things it doesnt normally want to.
-this is really only a proof of concept ATM. That said i've given it a quick test run and it seemed to work okay
-if you don't have experience with sv_downloadurl, dont even ATTEMPT to get this to run, familiarse yourself with srcds first.
-in order to use this, place this file in the directory below your files (or even in your base file directory, it shouldnt matter) and call it whatever you want.
-next point your sv_downloadurl variable in your server.cfg to <path><filename>.php?dl=
-that last bit is vitally important
-this essentially works, for those interested in PHP jediness, by accepting the file that srcdsis looking for as a GET argument, and then forwarding the page, via headers, to the file in questions. this allows files to be defined for different servers so that you arent stuck with a single sv_downloadurl location
-READ ALL NOTES, they are useful and contain some important information
-send any feedback (ie IF IT DONT WORK) via the srcds forums, or at angus dot moore at internode dot on dot net
*/
####################################
/* SERVER DEFINITIONS. SHOULD BE IN THE SAME FORMAT AS SV_DOWNLOADURL WOULD BE*/
####################################
//you can have as many different servers as you like
//this must be the default server. Any file on this server does not need its own file definition.
$location[1]="http://www.example.com/hl2mp";
//other server numbers.
$location[2]="http://www.example2.net/files";
$location[3]="http://www.example3.net/wtfeva";
####################################
/* FILE DEFINITIONS. ANY FILE THAT IS NOT ON THE DEFAULT SERVER MUST BE DEFINED HERE AS TO WHICH SERVER IT IS ON */
####################################
//these files must be in the form that srcds will search for them, ie /maps/map_name.bsp.bz2 orthe like
//VERY IMPORTANT - you MUST use bz2 for these files, as srcds will search for these first, and im pretty sure this script will break if you dont use bz2.
//that said im sure you could set it up to not use bz2, but why wouldnt you want to use bz2. its quicker.
//this is in the form $files["<file name and path>"]=<server number>
$files["/maps/aim_arena_b7.bsp.bz2"]=2;
$files["/sounds/quake/headshot.mp3.bz2"]=3;
//etc. you get the idea
###################################
//actual code - dont alter this unless you know what your doing
###################################
if($_GET['dl']) {
if(!isset($files[$_GET['dl']])) {
//defualt it to the main server
header("Location: " . $location[1] . $_GET['dl']);
} else {
//send it the new place
header("Location: " . $location[$files[$_GET['dl']]] . $_GET['dl']);
}
} else {
//feel free to alter the below code to whatever. this is just what i use if someone gets there by accident.
echo "<html>
<head>
<title>gµssy sv_downloadurl hack</title>
</head>
<body>
This is our file server. You shouldn't probably be here. Try <A href=\"http://www.mysite.com\">here</a> instead.<br><br>
Have a nice day!
</body>
</html>";
}
?>
and remember, though my title says hack, its not a hack in the bad way