Create an account

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I made a PHP script to auto manage download locations for multiple servers

I have made this script it allows you to set your server's sv_curl_defaulturl setting to a web server and call this script like this
http://[Your Server IP Address Here]/xonoticdl.php?file=
on a Debian system you would need to install libapache2-mod-php, php-curl, and apache2

sudo apt-get install libapache2-mod-php apache2 php-curl
You can then place this below script in /var/www/html/xonoticdl.php and now when your server's client needs to get a map file it will ask your web server where to get the file, the web server will tell it which server to get it from, and if no server has it it will send it from itself, now you can use maps from multiple servers and not only one, of-course if you have a 100Mbit fiber link you could just host every map yourself anyway, but if you are like me and have a 5Mbps or worse upload speed, this can really help if you need/want maps stored on different servers
Script last updated 11/7/17 (add missing period;prevent downloading server.cfg to protect the rcon_password)
PHP Code:
="/home/evilkittie/.xonotic/urlcache.serial";// create this file and be make sure www-data has write access (you can place this in /var/cache if you prefer)
$data="/home/evilkittie/.xonotic/data";// Path to Xonotic's data folder
$servers=(object)array(// Game server is used as last resort (pay attention to commas at the end of lines in here)
  // true means use a HTTPS connection
  // false means use a HTTP connection
  // based on answer here
  if(isset($cache->{$path}) && isset($cache->{$path}->{$file})){// Is this cached?
     return $cache->{$path}->{$file};// looks like it
  else{// not cached, lets cache it!
     /* Caching method is not perfect, there is a chance we could 
       * delete a small amount of cache doing this (no file lock)
       * however it is only a cache we will get it sooner or later.
     // don't download content
     if($GLOBALS["cacheTime"]!=filemtime($GLOBALS["CACHE_FILE"]))// did the cache change on us?
        $cache=loadCache();// refresh it
     $GLOBALS["cache"]=$cache;//export cache
     return $cache->{$path}->{$file};// is the file there?
  if(filesize($CACHE_FILE)==0)// Assume file exist (*points at line 2*)
     $ct=0;// safety
        if($cache===false){// did it work?
              usleep(10000);// wait 0.01 seconds
           $cache=file_get_contents($CACHE_FILE);// must have opened while data was being written
        $cache=@unserialize($cache);// vastly faster than json_parse
           // cache appears to be broken
  return $cache;
  $f=fopen($GLOBALS["CACHE_FILE"],"w");// open cache
  fwrite($fserialize($cache));//write cache
  fclose($f);//save cache
$argv)){// cli management
  foreach($argv as $key => $val){
           echo "--delete requires a file name";
           foreach($cache as $s => $f){
           echo "--drop requires a path name";
        echo "Options:\n\t".
           "--dump\n\t\tDump cache in a readable format\n\t".
           "--truncate\n\t\tDelete cache file content\n\t".
           "--delete\n\t\tDelete a file from cache\n\t".
           "--drop\n\t\tRemove a entire server's folder from cache\n\t".
           "--help\n\t\tShow this help info";
  die("file parameter is required!");
$file=substr($file,strrpos($file,'/'));// SECURITY MEASURE: DO NOT DELETE!
$servers as $key => $val){
     exit(header("Location: http".($val?'s':'')."://$key/$file"));
file_exists("$data/$file")){// guess we better send them our local copy
   if(strtolower(substr(strrpos($file,".")))!='.pk3'){// are you trying to get server.cfg?
      header('HTTP/1.0 403 Forbidden');// denied
      header("Content-Type: text/plain");
      die("Where did you get that file name anyway?");
  header("Content-Type: application/zip");
  header("Content-Disposition: attachment; filename=$file");
  header("Content-Length: ".filesize($file));
  header("HTTP/1.0 404 Not Found");
  header("Content-Type: text/plain");
  echo "Xonotic Server: You need to download $file\n".
     "Client: Web server I need you to give me $file\n".
     "Web Server: $file does not even exist on this server\n".
     "Client: Why would you tell me I need a file you don't have?\n".
     "Web Server: The Xonotic Server must be experiencing an ID10T error.";

This script also has a command line interface so you can manage the cached metadata, run (your systems current user must have write access to edit the cache)
~$ php /var/www/html/xonoticdl.php --help
        Dump cache in a readable format
        Delete cache file content
        Delete a file from cache
        Remove a entire server's folder from cache
        Show this help info
for the .serial file i use permissions set to 664 and have www-data as the group while i am the owner
You will need to forward port 80 to the server from your router, some crappy ISP prevent you from receiving port 80, you can bypass this by using port 81 (or any other port for that matter), see /etc/apache/ports.conf and /etc/apache/sites-available/000-default.conf

Possibly Related Threads…
Thread Author Replies Views Last Post
  Let's make our servers community-like! xord86_64 3 1,111 02-03-2023, 05:36 PM
Last Post: xord86_64
  [META] Deploying Xonotic using GKE Game Servers? FAF 4 1,962 09-14-2022, 08:32 AM
Last Post: cushinga
  [NEED HELP] Getting rid of Auto Balancing Teams DoomTheEpic 1 1,793 04-18-2022, 03:43 PM
Last Post: Mario
  [ MoFo ] Servers Master Thread end user 5 5,093 11-27-2020, 09:33 PM
Last Post: end user
  Game servers in Kazakhstan. Mysyk 4 3,829 07-17-2020, 09:38 AM
Last Post: Mysyk | Quality Xonotic Servers djinn- 0 1,618 04-17-2020, 10:18 AM
Last Post: djinn-
  My Xonotic servers - more wanted? MarisaG 2 2,701 02-20-2019, 05:36 AM
Last Post: MarisaG
  Deploying a server across multiple machines ar5n1c 1 2,019 11-21-2018, 11:08 AM
Last Post: martin-t
  New servers, interested to see what times people get to them... MarisaG 0 2,466 10-06-2018, 04:06 AM
Last Post: MarisaG
  Free hosting for Xonotic servers MarisaG 8 6,504 09-18-2018, 07:06 PM
Last Post: MarisaG

Forum Jump:

Users browsing this thread:
1 Guest(s)

Forum software by © MyBB original theme © iAndrew 2016, remixed by -z-