#include "fs.h"
#include "libcurl.h"
-static cvar_t cl_curl_maxdownloads = {1, "cl_curl_maxdownloads","1", "maximum number of concurrent HTTP/FTP downloads"};
-static cvar_t cl_curl_maxspeed = {1, "cl_curl_maxspeed","100", "maximum download speed (KiB/s)"};
-static cvar_t sv_curl_defaulturl = {1, "sv_curl_defaulturl","", "default autodownload source URL"};
-static cvar_t sv_curl_serverpackages = {1, "sv_curl_serverpackages","", "list of required files for the clients, separated by spaces"};
-static cvar_t cl_curl_enabled = {1, "cl_curl_enabled","0", "whether client's download support is enabled"};
+static cvar_t cl_curl_maxdownloads = {CVAR_SAVE, "cl_curl_maxdownloads","1", "maximum number of concurrent HTTP/FTP downloads"};
+static cvar_t cl_curl_maxspeed = {CVAR_SAVE, "cl_curl_maxspeed","100", "maximum download speed (KiB/s)"};
+static cvar_t sv_curl_defaulturl = {CVAR_SAVE, "sv_curl_defaulturl","", "default autodownload source URL"};
+static cvar_t sv_curl_serverpackages = {CVAR_SAVE, "sv_curl_serverpackages","", "list of required files for the clients, separated by spaces"};
+static cvar_t cl_curl_enabled = {CVAR_SAVE, "cl_curl_enabled","0", "whether client's download support is enabled"};
/*
=================================================================
static downloadinfo *downloads = NULL;
static int numdownloads = 0;
+static qboolean noclear = FALSE;
+
static int numdownloads_fail = 0;
static int numdownloads_success = 0;
static int numdownloads_added = 0;
void Curl_Clear_forthismap()
{
downloadinfo *di;
+ if(noclear)
+ return;
for(di = downloads; di; di = di->next)
di->forthismap = false;
Curl_CommandWhenError(NULL);
numdownloads_added = 0;
}
-/* obsolete: numdownloads_added contains the same
-static qboolean Curl_Have_forthismap()
+/*
+====================
+Curl_Have_forthismap
+
+Returns true if a download needed for the current game is running.
+====================
+*/
+qboolean Curl_Have_forthismap()
+{
+ return numdownloads_added;
+}
+
+void Curl_Register_predownload()
{
- downloadinfo *di;
- for(di = downloads; di; di = di->next)
- if(di->forthismap)
- return true;
- return false;
+ Curl_CommandWhenDone("cl_begindownloads");
+ Curl_CommandWhenError("cl_begindownloads");
}
-*/
/*
====================
++numdownloads_fail;
}
Z_Free(di);
-
- Curl_CheckCommandWhenDone();
}
/*
*/
void Curl_Run()
{
+ noclear = FALSE;
+
if(!cl_curl_enabled.integer)
return;
if(!curl_dll)
return;
+ Curl_CheckCommandWhenDone();
+
if(!downloads)
return;
else
{
downloadinfo *di = Curl_Find(url);
- Curl_EndDownload(di, CURL_DOWNLOAD_ABORTED, CURLE_OK);
+ if(di)
+ Curl_EndDownload(di, CURL_DOWNLOAD_ABORTED, CURLE_OK);
+ else
+ Con_Print("download not found\n");
}
return;
}
char donecommand[256];
if(cls.netcon)
{
- dpsnprintf(donecommand, sizeof(donecommand), "connect %s", cls.netcon->address);
- Curl_CommandWhenDone(donecommand);
+ if(cls.signon >= 3)
+ {
+ dpsnprintf(donecommand, sizeof(donecommand), "connect %s", cls.netcon->address);
+ Curl_CommandWhenDone(donecommand);
+ noclear = TRUE;
+ CL_Disconnect();
+ noclear = FALSE;
+ Curl_CheckCommandWhenDone();
+ }
+ else
+ Curl_Register_predownload();
}
- CL_Disconnect();
-
- Curl_CheckCommandWhenDone();
}
return;
}
// TODO: can I clear command_when_done as soon as the first download fails?
if(*command_when_done && !numdownloads_fail && numdownloads_added)
{
- if(strncmp(command_when_done, "connect ", 8))
- dpsnprintf(addinfo, sizeof(addinfo), "(will do '%s' when done)", command_when_done);
- else
+ if(!strncmp(command_when_done, "connect ", 8))
dpsnprintf(addinfo, sizeof(addinfo), "(will join %s when done)", command_when_done + 8);
+ else if(!strcmp(command_when_done, "cl_begindownloads"))
+ dpsnprintf(addinfo, sizeof(addinfo), "(will enter the game when done)");
+ else
+ dpsnprintf(addinfo, sizeof(addinfo), "(will do '%s' when done)", command_when_done);
*additional_info = addinfo;
}
else