AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Multiple Fast Download URLs (https://forums.alliedmods.net/showthread.php?t=123802)

CrimsonGT 04-09-2010 05:32

[SNIPPET] Multiple Fast Download URLs
 
I do not take credit for this, I found it on srcds.com forums and was impressed so I decided to post it here. Full credit for the work goes to gussy over at srcds forums. It basically allows you to run a php script that will let you use different fast download URLs for different files. It was posted 2 years ago, but despite my endless hours of forum browsing I had never seen it.

Original thread can be found here...
http://forums.srcds.com/viewtopic/4464

PHP 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>"
;
}
?>


DontWannaName 04-12-2010 18:35

Re: [SNIPPET] Multiple Fast Download URLs
 
If you had 2 websites in different locations you could add geoip and choose the closest website to the person downloading the files. Sort of like CDN? But I dont see who would need that...

Inflikted 04-13-2010 15:02

Re: [SNIPPET] Multiple Fast Download URLs
 
kinda useful :) a lot of our europe players download pretty slow off our US based servers. would be nice to setup fast downloads in asia/europe for them. thanks

Sammy-ROCK! 04-13-2010 21:44

Re: [SNIPPET] Multiple Fast Download URLs
 
Quote:

Originally Posted by DontWannaName (Post 1148452)
If you had 2 websites in different locations you could add geoip and choose the closest website to the person downloading the files. Sort of like CDN? But I dont see who would need that...

You would make it easier for someone who want to use your FastDL on their server besides it's lame that a player far enought to have a decreased download rate would play on the server, in this case he surely would have a high ping decreasing the server quality. Who likes to miss a shot because the player walks teleporting?

Quote:

Originally Posted by Inflikted (Post 1149303)
kinda useful :) a lot of our europe players download pretty slow off our US based servers. would be nice to setup fast downloads in asia/europe for them. thanks

You don't need something so complex to change the FastDL of the servers in asia/europe.

DontWannaName 04-14-2010 02:14

Re: [SNIPPET] Multiple Fast Download URLs
 
Ya I know, just a though though if that wasnt the case.

Alguemnn 04-17-2010 16:05

Re: [SNIPPET] Multiple Fast Download URLs
 
What directory should I upload it?

D-Skript 04-17-2010 20:40

Re: [SNIPPET] Multiple Fast Download URLs
 
Interesting indeed.

KawMAN 04-25-2010 08:56

Re: [SNIPPET] Multiple Fast Download URLs
 
I have made similar script
Feature:
- Switching mirror every download request (simple bandwidth balancer)
- Checking if file exist on mirror and if not, checking another mirror. If file cant be found on any mirror sends to client "404 Not Found".
PHP Code:

<?
//Written by KawMAN
ini_set('display_errors''1');
//set_time_limit  ("10"); //Optional timeout
$mirrors = array();

//Mirrors here
$mirrors[] = "http://mirror1.wsciekle.pl/cstrike";
$mirrors[] = "http://mirror2.wsciekle.pl/fd";
$mirrors[] = "http://mirror3.wsciekle.pl/cstrike";


$mircount count($mirrors);

$fn=$_GET["fn"]; //Filename

// Get first mirror to check
$clnr GetNextMir();
if(
$clnr == -1) exit("cant read from fd_redir_c.txt");
//Change 'first mirror' to next mirror on list
if($clnr>=$mircount-1) {
    
SetNextMir(0);
} else {
    
SetNextMir($clnr+1);
}

$loop=0;
while(!
redir($clnr)) {
    if(
$clnr>=$mircount-1) {
        
$clnr=0;
    } else {
        
$clnr++;
    }
    if(
$loop>$mircount) { //When all mirrors return Not Found, script return Not Found
        
header("HTTP/1.0 404 Not Found");
        exit(
'Not Found');
    }
    
$loop++;
}

function 
GetNextMir() {
    
$uchwyt=fopen("fd_redir_c.txt""r");
    if (
$uchwyt === false) {
        return -
1;
    }
    
$fdc fread($uchwytfilesize("fd_redir_c.txt"));
    
fclose($uchwyt);
    return (int)
$fdc;
}
function 
SetNextMir($clnr) {
    
$uchwyt=fopen("fd_redir_c.txt""w");
    
fwrite($uchwyt$clnr);
    
fclose($uchwyt);
}
function 
redir($nr)
{
    global 
$fn$mirrors;
    
$uchwyt = @fopen($mirrors[$nr].$fn,"r");
    if (
$uchwyt === false
    {
        return 
false;
    }
    else
    {
        
header("location: ".$mirrors[$nr].$fn);
        return 
true;
    }
}
?>

in folder with that script must be file called fd_redir_c.txt with chmod 777
now sv_downloadurl should looks like this:
sv_downloadurl "http://main.wsciekle.pl/fd_redir.php?fn="

also you can create folder for example "fastdownload" and put to it file .htaccess with something like this:
PHP Code:

RewriteEngine On
RewriteRule 
^(.*) http://main.wsciekle.pl/fd_redir.php?fn=/$1 [R,NC] 

and now sv_downloadurl can looks like :
sv_downloadurl "http://main.wsciekle.pl/fastdownload"

Working example:
http://fastdownload.wsciekle.pl/maps...ood_rm.bsp.bz2 download, check source, download, check source

DontWannaName 04-25-2010 23:43

Re: [SNIPPET] Multiple Fast Download URLs
 
If fpsbanana was smart, they could create a system to make everything bziped and offer a service to let server ops use their mirrors and files to download from.

KawMAN 04-28-2010 06:38

Re: [SNIPPET] Multiple Fast Download URLs
 
i published mirror script so i must publish this too
PHP Code:

RewriteEngine on
#Only HL2/Valve servers
RewriteCond %{HTTP_REFERER} ^hl2://(.*) [NC]
#Allowed servers
RewriteCond %{HTTP_REFERER} !^hl2://91\.91\.91\.91:27015 [NC]
RewriteCond %{HTTP_REFERER} !^hl2://91\.204\.162\.240:(.*) [NC]
#if not allowed, send 403 Forbidden
RewriteRule .* - [F

this is example of .htaccess mod_rewrite rule that block requests from servers not defined in this file. This blocks only another servers. Browser or other things will stil be able to download files.

This example allow donwload files for clients on servers: 91.91.91.91 port 27015 and 91.204.162.240 on any port

You can test this with FireFox and RefControl Addon. Exactly same file is on http://fastdownload.strefa-source.pl try to reach this site using referer hl2://91.91.91.91:27015 and some other hl2://

Darkthrone 07-01-2010 16:15

Re: [SNIPPET] Multiple Fast Download URLs
 
Quote:

Originally Posted by KawMAN (Post 1163147)
This blocks only another servers. Browser or other things will stil be able to download files.

how to block browser?

KawMAN 07-01-2010 16:30

Re: [SNIPPET] Multiple Fast Download URLs
 
remove
PHP Code:

RewriteCond %{HTTP_REFERER} ^hl2://(.*) [NC] 


Darkthrone 07-01-2010 18:02

Re: [SNIPPET] Multiple Fast Download URLs
 
i have already tried it, but it breaks all downloads, also from gameserver
apache2 log:
Code:

xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /fastdownload/sound/ambient/zombiemod/zombie_ambient.mp3.bz2 HTTP/1.1" 302 689 "hl2://xx.xx.xx.xx:27015" "Half-Life 2"
xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /cstrike/sound/ambient/zombiemod/zombie_ambient.mp3.bz2 HTTP/1.0" 403 552 "-" "-"
xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /fd_redir.php?fn=/sound/ambient/zombiemod/zombie_ambient.mp3.bz2 HTTP/1.1" 404 210 "hl2://xx.xx.xx.xx:27015" "Half-Life 2"
xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /fastdownload/sound/ambient/zombiemod/zombie_ambient.mp3 HTTP/1.1" 302 681 "hl2://xx.xx.xx.xx:27015" "Half-Life 2"
xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /cstrike/sound/ambient/zombiemod/zombie_ambient.mp3 HTTP/1.0" 404 544 "-" "-"
xx.xx.xx.xx - - [02/Jul/2010:04:55:32 +0700] "GET /fd_redir.php?fn=/sound/ambient/zombiemod/zombie_ambient.mp3 HTTP/1.1" 404 210 "hl2://xx.xx.xx.xx:27015" "Half-Life 2"



All times are GMT -4. The time now is 18:26.

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