]> git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Automatic-map-downloads.md
Added table of contents
[xonotic/xonotic.wiki.git] / Automatic-map-downloads.md
1 # Automatic map downloads
2
3 ## Client-side configuration
4
5 Should already work without configuration. You can however use the following
6 cvars for further tuning (see xonotic.org/tools/cacs for more up-to-date information):
7
8 * `cl_curl_enabled`: download support enabled (master switch)
9 * `cl_curl_maxdownloads`: maximum number of downloads at once
10 * `cl_curl_maxspeed`: maximum total speed in KiB/s
11
12 Downloaded packages end up in `Xonotic/data/dlcache/` or
13 `~/.xonotic/data/dlcache/` and are only used till you exit Xonotic.
14  If you want to play them localy or use them to setup a server of your
15 own you can "accept" the packages by moving it one level up - right
16 next to your `config.cfg`.
17
18 You should regularly clean up your cache to save space and make the maps
19 you really want available from the menu.
20
21 ## Server-side configuration
22
23 First of all, you need a HTTP or FTP server to host your PK3s. You can either
24 use some web space provider, or set up your own. For this, use any FTP or HTTP
25 server software you want (HTTP: lighttpd, Apache, thttpd; FTP: Filezilla,
26 vsftpd). HTTP is to be preferred because it works better for firewalled
27 players.
28
29 On the server, you need to set up where to download the PK3s of the maps you
30 are running. You can either use the cvar:
31 * `sv_curl_defaulturl`           default download URL
32
33 to set it to some site, or put a file named "curl_urls.txt" in the data
34 directory of the following format:
35 ```
36    pattern        url
37    pattern        url
38    pattern        url
39    ...
40 ```
41 where always the first wildcard pattern match is taken.
42 ```
43    data*          -
44    strale*        http://stralemaps.invalid/
45    *              http://all.the.other.stuff.invalid/id/here.php?pak=
46    foo*           http://wont.get.here.invalid/
47 ```
48 The pk3 name will be appended to the URL by DarkPlaces. Note that you NEED to
49 append a trailing slash if you refer to a directory. If you specify a "-" as
50 URL, the package will not be offered for download.
51
52 **Note:** HTTP**S** downloads are not supported for Xonotic Windows Clients! It works for the Linux client but you probably want to serve all players so it is advised to use `http://` in `sv_curl_defaulturl` or `curl_urls.txt`.
53
54 Some Apache config snippet for the `<VirtualHost>` to allow for Xonotic Clients to use HTTP while all other traffic get redirected to HTTPS would be:
55 ```apache
56         RewriteEngine On
57         RewriteCond %{HTTP_USER_AGENT} ^Xonotic
58         RewriteRule ^ - [END]
59         RewriteCond %{HTTPS} !=on
60         RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R=301,L]
61 ```
62
63 More Information about the Referer:
64
65 The Referer is always set to dp://serverhost:serverport/, the User-Agent always starts with "Xonotic". Look at this sample log line:
66
67 `141.2.16.3 - - [06/Jun/2006:19:43:14 +0000] "GET /~polzer/temp/nexmaps.php?filename=o-fun.pk3 HTTP/1.1" 302 - "dp://141.2.16.3:26000/" "Xonotic Linux 21:26:17 Jun  6 2006"`
68
69
70 If you want to set up a redirection service, here is a sample PHP code for you
71 to start from:
72
73 ```php
74 <?
75
76 function findmap($filename)
77 {
78     # insert your database query or whatever you want here
79     if($filename == "foo.pk3")
80         return "http://barserver.invalid/foo.pk3";
81     return FALSE;
82 }
83
84 function bailout($code, $title, $message)
85 {
86     header("HTTP/1.1 $code $title");
87     echo "<html><title>$title</title><h1>$title</h1>$message</html>";
88     exit(0);
89 }   
90
91 $filename = $_GET['filename'];
92
93 $useragent = getenv("HTTP_USER_AGENT");
94 if(strpos($useragent, "Xonotic ") !== 0)
95     bailout(403, "Forbidden", "You're not a Xonotic client.");
96     
97 $url = findmap($filename);
98 if(!$url)
99     bailout(404, "Not Found", "Well... try another file name?");
100     
101 header("HTTP/1.1 302 Moved Temporarily");
102 header("Location: $url");
103
104 ?>
105 ```