Hey. First off I'm sorry if this isnt the correct section, I didnt want to put it under the PHP section though because I doubt many people this will be relevant to actually look there.
It's really annoying running servers with gamemodes/addons that require constant tweaking/improving, but being unable to commit any changes to the server because it always has people in and they will get annoyed with constant breaking/delays while you put the new cache in.
I don't have any prior PHP experience but I looked around for examples and created this script, which [B]in a nutshell will check if the .dua file being requested exists on the fastdl, and if it doesn't, it will grab it from the gameserver via FTP then archive it and give it to the player, allowing changes to be made to shared/client side lua without affecting players.[/B] If the file requested isn't a cache file, it will just be directed to the fastdl as normal. It has the potential to do this with any file, but I'm not sure how to make it viable security wise (Since technically any file could be requested from the server if someone obtained your downloadurl, unless there was a 'not allowed' list)
[B]Requirements[/B]
1. The fastdl must be hosted on a webserver with PHP installed.
2. The webserver must have the [url=http://www.php.net/manual/en/bzip2.installation.php]Bzip2[/url] PHP extension enabled. (Most if not all paid webservers that support PHP should have this activated)
3. You must have FTP access to the server (Obviously)
[B]Code[/B]
[php]
<? ob_start(); ?>
<?php
$fastdl = "http://www.mysite.co.uk/fastdl/terrortown"; // Your fastdl root folder, make sure there is no / on the end.
$ftp_server = "123.123.123.123"; // The FTP IP for your server, no port
if($_GET['dl']) {
$dlfile=$_GET['dl'];
if(!file_exists(substr($dlfile, 1)) && substr($dlfile, -8) == ".dua.bz2") {
$dldua=substr($dlfile, 1, -4);
if (file_exists("0")) {
rename("0", "1");
} elseif(file_exists("1")) {
sleep(5);
header("Location: " . $fastdl . $dlfile);
exit;
}
$conn_id = ftp_connect($ftp_server, "21"); // Default port for FTP, change if needed
$login_result = ftp_login($conn_id, "MyUser", "MyPass"); // Your server FTP user/pass here.
ftp_pasv($conn_id, true);
ftp_chdir($conn_id, "123.123.123.123 port 27015/orangebox/garrysmod"); // If your home folder when you connect to your server's FTP isnt the base garrysmod folder, navigate to it here. If it is, comment/delete this line.
ftp_get($conn_id, $dldua, $dldua, FTP_BINARY);
ftp_close($conn_id);
$data = file_get_contents($dldua);
file_put_contents("compress.bzip2://" . substr($dlfile, 1), $data);
//unlink($dldua); Deletes the .dua after it has been added to the archive, I wouldn't recommend this as sometimes players seem to ask for the .dua rather than the .dua.bz2.
rename("1", "0");
header("Location: " . $fastdl . $dlfile);
exit;
}
else {
header("Location: " . $fastdl . $dlfile);
}
} else {
// This can be modified as you please and will be displayed when someone tries to access this file from their web browser with no parameters specified.
/*echo "<html>
<head>
<title></title>
</head>
<body>
</body>
</html>";*/
header("Location: " . "http://www.google.com");
}
?>
<? ob_end_flush(); ?>
[/php]
[B]Usage[/B]
1. Copy/paste into a text document
2. Fill in the commented parts as required and save as .php
3. Upload it to your fastdl root directory (Where the cache directory is stored)
4. Have your sv_downloadurl point to the PHP file with '?dl=' on the end, e.g. [url]http://www.mysite.com/fastdl/fdl.php?dl=[/url]
5. Create a blank file alongside the PHP file called "0", no extension
[B]Disclaimer[/B]
Be warned that I am a total newbie at PHP. I have tried my best to figure out if there are any serious security flaws with this script and I'm not sure how I could apply some form of authentication, so use at your own risk. On that note if anyone could give any pointers on how to improve it I'd be grateful.
I have been running this exact version of the script on our server for a month or so now and it works fine.
looks good, nice work!
I want you inside of me <3
Excellent work! Does this also allow for the download of other files, if you have to change the download url to the php file's location?
[QUOTE=xam678;37238425]Excellent work! Does this also allow for the download of other files, if you have to change the download url to the php file's location?[/QUOTE]
if it's not the lua cache then it'll send the file as normal with its proper extension
I had to update it; I didnt anticipate that on a mapchange loads of people requesting it at once would cause it to mess up and everyone end up with a corrupt .dua file.
Easiest workaround I could think of was to rename a file to 1 or 0 depending on if it is uploading, and if it is currently uploading, anyone that tries to download is given a 5 second delay to let it finish up.
Tested it and seems to work so far with 5-6 people, no reason it should work with more.
what I did when testing this was download the .dua to .dua.tmp, then bzip it to .bz2.tmp, and then when it's done rename it to just .bz2, that seems to work
oh and you should probably strip .. so people can't put in ../../../../ (or maybe I'm thinking of this wrong)
[QUOTE=Banana Lord.;37241436]
oh and you should probably strip .. so people can't put in ../../../../ (or maybe I'm thinking of this wrong)[/QUOTE]
Yeah if it were modified to upload any requested file to the fastdl then it would need security measures like that and most likely a whitelist of allowed extensions, but because it checks for ".dua.bz2" there isnt much anyone can do. Even if they did whatever and put the extension on the end it would just throw a file not found error due to the FTP trying to download it as well as a dummy .bz2 file, but that could easily be fixed with an if statement anyway.
I might end up sorting it out to do that, but really this was for personal use and I decided to release it.
[QUOTE=Banana Lord.;37241436]what I did when testing this was download the .dua to .dua.tmp, then bzip it to .bz2.tmp, and then when it's done rename it to just .bz2, that seems to work[/QUOTE]
Wouldn't that still cause an issue with multiple people requesting it though?
If player 1 starts the download to the .tmp file, then player 2 requests the file and it checks for just the .dua existing, so it proceeds to download it again and so on until the last player was able to download it and everyone else was already connected with no cache.
If you were to then check if both files existed, people would end up entering the server without the cache and be forced to reconnect to get it.
either way it's a solid release, it's just unfortunate that it was released so close to GMod 13 (and the disappearance of lua caches)
Yeah, we actually had a completely automatic fastdl sync two years ago and it was great from a developer standpoint, but I didnt have access to it and the original creator doesnt have a backup of it now, so I decided to have a shot at making it myself while learning a bit about PHP in the process. I wouldn't have been able to do it without [url=http://forums.alliedmods.net/showthread.php?t=123802]this[/url] as a basis, because really knowing how to use $_GET and headers were the most important parts, the rest is just logic.
The cache is the main focus for me though, my issue that there always seems to be people on and its really annoying having to change the cache every time I make a tiny change.
-snip nvm-
Just a little bump. I think this could be very useful for some but not a lot of people have seen it, especially since GM13 is pushed back another month.
I updated it a bit, it will work 100% now. Though it may not be the most efficient code, its only a small script and works fine.
Looks Good.
Would of used before I setup fast download.
Sorry, you need to Log In to post a reply to this thread.