summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2013-02-18 15:48:35 +0400
committerAndrey Nazarov <skuller@skuller.net>2013-02-18 16:27:42 +0400
commit5a1ece6a2775a7c589f82b4979da210bc1168e4a (patch)
tree8ade1712ed3589794fba137b14d433b6feebda43 /src
parent45fba018d464879cd6216d55212b7ce9b5b61613 (diff)
Add ‘cl_http_default_url’ variable.
Allow default repository URL to be defined for servers that don't specify one. Any 404 from default repository is treated as fatal error, permitting the client to revert to UDP downloading from the game server.
Diffstat (limited to 'src')
-rw-r--r--src/client/http.c30
-rw-r--r--src/client/main.c10
2 files changed, 33 insertions, 7 deletions
diff --git a/src/client/http.c b/src/client/http.c
index 041e759..f63b070 100644
--- a/src/client/http.c
+++ b/src/client/http.c
@@ -23,6 +23,7 @@ static cvar_t *cl_http_downloads;
static cvar_t *cl_http_filelists;
static cvar_t *cl_http_max_connections;
static cvar_t *cl_http_proxy;
+static cvar_t *cl_http_default_url;
#ifdef _DEBUG
static cvar_t *cl_http_debug;
#endif
@@ -45,6 +46,7 @@ typedef struct {
static dlhandle_t download_handles[4]; //actual download handles, don't raise this!
static char download_server[512]; //base url prefix to download from
static char download_referer[32]; //libcurl requires a static string :(
+static qboolean download_default_repo;
static qboolean curl_initialized;
static CURLM *curl_multi;
@@ -380,6 +382,8 @@ void HTTP_CleanupDownloads(void)
download_server[0] = 0;
download_referer[0] = 0;
+ download_default_repo = qfalse;
+
curl_handles = 0;
for (i = 0; i < 4; i++) {
@@ -427,6 +431,7 @@ void HTTP_Init(void)
cl_http_max_connections = Cvar_Get("cl_http_max_connections", "2", 0);
//cl_http_max_connections->changed = _cl_http_max_connections_changed;
cl_http_proxy = Cvar_Get("cl_http_proxy", "", 0);
+ cl_http_default_url = Cvar_Get("cl_http_default_url", "", 0);
#ifdef _DEBUG
cl_http_debug = Cvar_Get("cl_http_debug", "0", 0);
#endif
@@ -462,7 +467,8 @@ void HTTP_SetServer(const char *url)
return;
}
- if (!*url)
+ // ignore on the local server
+ if (NET_IsLocalAddress(&cls.serverAddress))
return;
// ignore if downloads are permanently disabled
@@ -473,6 +479,18 @@ void HTTP_SetServer(const char *url)
if (cl_http_downloads->integer == 0)
return;
+ // use default URL for servers that don't specify one. treat 404 from
+ // default repository as fatal error and revert to UDP downloading.
+ if (!url) {
+ url = cl_http_default_url->string;
+ download_default_repo = qtrue;
+ } else {
+ download_default_repo = qfalse;
+ }
+
+ if (!*url)
+ return;
+
if (strncmp(url, "http://", 7)) {
Com_Printf("[HTTP] Ignoring download server URL with non-HTTP schema.\n");
return;
@@ -510,9 +528,8 @@ qerror_t HTTP_QueueDownload(const char *path, dltype_t type)
need_list = LIST_EMPTY(&cls.download.queue);
ret = CL_QueueDownload(path, type);
- if (ret) {
+ if (ret)
return ret;
- }
if (!cl_http_filelists->integer)
return Q_ERR_SUCCESS;
@@ -527,7 +544,8 @@ qerror_t HTTP_QueueDownload(const char *path, dltype_t type)
//get confused by a ton of people stuck in CNCT state. it's assumed the server
//is running r1q2 if we're even able to do http downloading so hopefully this
//won't spew an error msg.
- CL_ClientCommand("download http\n");
+ if (!download_default_repo)
+ CL_ClientCommand("download http\n");
}
//special case for map file lists, i really wanted a server-push mechanism for this, but oh well
@@ -755,8 +773,8 @@ static qboolean finish_download(void)
err = http_strerror(response);
- //404 is non-fatal
- if (response == 404) {
+ //404 is non-fatal unless accessing default repository
+ if (response == 404 && (!download_default_repo || !dl->path[0])) {
level = PRINT_ALL;
goto fail1;
}
diff --git a/src/client/main.c b/src/client/main.c
index 3bac2e2..23261f0 100644
--- a/src/client/main.c
+++ b/src/client/main.c
@@ -1392,6 +1392,7 @@ static void CL_ConnectionlessPacket(void)
netchan_type_t type;
int anticheat = 0;
char mapname[MAX_QPATH];
+ qboolean got_server = qfalse;
if (cls.state < ca_connecting) {
Com_DPrintf("Connect received while not connecting. Ignored.\n");
@@ -1435,10 +1436,17 @@ static void CL_ConnectionlessPacket(void)
} else if (!strncmp(s, "map=", 4)) {
Q_strlcpy(mapname, s + 4, sizeof(mapname));
} else if (!strncmp(s, "dlserver=", 9)) {
- HTTP_SetServer(s + 9);
+ if (!got_server) {
+ HTTP_SetServer(s + 9);
+ got_server = qtrue;
+ }
}
}
+ if (!got_server) {
+ HTTP_SetServer(NULL);
+ }
+
Com_Printf("Connected to %s (protocol %d).\n",
NET_AdrToString(&cls.serverAddress), cls.serverProtocol);
if (cls.netchan) {