From 31a7920ec3adbd7888621f97d3a0e1c801e78026 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 9 Jun 2006 02:03:34 +0000 Subject: [PATCH] web download patch from div0, this adds the "curl" console command, and the ability for servers to send a set of conditional curl commands which will download pk3 archives if specific files are missing git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6443 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 4 +++ cl_screen.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++---- host.c | 6 +++++ host_cmd.c | 3 +++ makefile.inc | 1 + model_shared.c | 18 +++++++++++++ model_shared.h | 1 + sv_main.c | 5 ++++ 8 files changed, 105 insertions(+), 5 deletions(-) diff --git a/cl_main.c b/cl_main.c index e77ea64a..215cea56 100644 --- a/cl_main.c +++ b/cl_main.c @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "image.h" #include "csprogs.h" #include "r_shadow.h" +#include "libcurl.h" // we need to declare some mouse variables here, because the menu system // references them even when on a unix system. @@ -395,6 +396,9 @@ void CL_EstablishConnection(const char *host) // stop demo loop in case this fails CL_Disconnect(); + // if downloads are running, cancel their finishing action + Curl_Clear_forthismap(); + // make sure the client ports are open before attempting to connect NetConn_UpdateSockets(); diff --git a/cl_screen.c b/cl_screen.c index a4069c25..c35d1139 100644 --- a/cl_screen.c +++ b/cl_screen.c @@ -4,6 +4,7 @@ #include "image.h" #include "jpeg.h" #include "cl_collision.h" +#include "libcurl.h" #include "csprogs.h" cvar_t scr_viewsize = {CVAR_SAVE, "viewsize","100", "how large the view should be, 110 disables inventory bar, 120 disables status bar"}; @@ -303,27 +304,88 @@ void SCR_DrawBrand (void) /* ============== -SCR_DrawDownload +SCR_DrawQWDownload ============== */ -static void SCR_DrawDownload(void) +static int SCR_DrawQWDownload(int offset) { int len; float x, y; float size = 8; char temp[256]; if (!cls.qw_downloadname[0]) - return; + return 0; dpsnprintf(temp, sizeof(temp), "Downloading %s ... %3i%%\n", cls.qw_downloadname, cls.qw_downloadpercent); len = (int)strlen(temp); x = (vid_conwidth.integer - len*size) / 2; - y = vid_conheight.integer - size; + y = vid_conheight.integer - size - offset; DrawQ_Pic(0, y, NULL, vid_conwidth.integer, size, 0, 0, 0, 0.5, 0); DrawQ_String(x, y, temp, len, size, size, 1, 1, 1, 1, 0); + return 8; } -//============================================================================= +/* +============== +SCR_DrawCurlDownload +============== +*/ +static int SCR_DrawCurlDownload(int offset) +{ + int len; + int nDownloads; + int i; + float x, y; + float size = 8; + Curl_downloadinfo_t *downinfo; + char temp[256]; + const char *addinfo; + + downinfo = Curl_GetDownloadInfo(&nDownloads, &addinfo); + if(!downinfo) + return 0; + + y = vid_conheight.integer - size * nDownloads - offset; + + if(addinfo) + { + len = (int)strlen(addinfo); + x = (vid_conwidth.integer - len*size) / 2; + DrawQ_Pic(0, y - size, NULL, vid_conwidth.integer, size, 1, 1, 1, 0.8, 0); + DrawQ_String(x, y - size, addinfo, len, size, size, 0, 0, 0, 1, 0); + } + + for(i = 0; i != nDownloads; ++i) + { + if(downinfo[i].queued) + dpsnprintf(temp, sizeof(temp), "Still in queue: %s\n", downinfo[i].filename); + else if(downinfo[i].progress <= 0) + dpsnprintf(temp, sizeof(temp), "Downloading %s ... ???.?%% @ %.1f KiB/s\n", downinfo[i].filename, downinfo[i].speed / 1024.0); + else + dpsnprintf(temp, sizeof(temp), "Downloading %s ... %5.1f%% @ %.1f KiB/s\n", downinfo[i].filename, 100.0 * downinfo[i].progress, downinfo[i].speed / 1024.0); + len = (int)strlen(temp); + x = (vid_conwidth.integer - len*size) / 2; + DrawQ_Pic(0, y + i * size, NULL, vid_conwidth.integer, size, 0, 0, 0, 0.8, 0); + DrawQ_String(x, y + i * size, temp, len, size, size, 1, 1, 1, 1, 0); + } + Z_Free(downinfo); + + return 8 * (nDownloads + (addinfo ? 1 : 0)); +} + +/* +============== +SCR_DrawDownload +============== +*/ +static void SCR_DrawDownload() +{ + int offset = 0; + offset += SCR_DrawQWDownload(offset); + offset += SCR_DrawCurlDownload(offset); +} + +//============================================================================= /* ================== diff --git a/host.c b/host.c index 84ff2d42..23f1a5ec 100644 --- a/host.c +++ b/host.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "quakedef.h" +#include "libcurl.h" #include "cdaudio.h" #include "cl_video.h" #include "progsvm.h" @@ -619,6 +620,8 @@ void Host_Main(void) NetConn_UpdateSockets(); + Curl_Run(); + //------------------- // // server operations @@ -922,6 +925,7 @@ static void Host_Init (void) // initialize various cvars that could not be initialized earlier Memory_Init_Commands(); Con_Init_Commands(); + Curl_Init_Commands(); Cmd_Init_Commands(); Sys_Init_Commands(); COM_Init_Commands(); @@ -932,6 +936,7 @@ static void Host_Init (void) Mathlib_Init(); NetConn_Init(); + Curl_Init(); //PR_Init(); //PR_Cmd_Init(); PRVM_Init(); @@ -1086,6 +1091,7 @@ void Host_Shutdown(void) CDAudio_Shutdown (); S_Terminate (); + Curl_Shutdown (); NetConn_Shutdown (); //PR_Shutdown (); diff --git a/host_cmd.c b/host_cmd.c index bf993d67..56864d05 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "quakedef.h" +#include "libcurl.h" int current_skill; cvar_t sv_cheats = {0, "sv_cheats", "0", "enables cheat commands in any game, and cheat impulses in dpmod"}; @@ -1513,6 +1514,8 @@ void Host_Begin_f (void) return; } + Curl_SendRequirements(); + host_client->spawned = true; } diff --git a/makefile.inc b/makefile.inc index bcb9764d..8a455a2e 100644 --- a/makefile.inc +++ b/makefile.inc @@ -54,6 +54,7 @@ OBJ_NOCD=cd_null.o # Common objects OBJ_COMMON= \ + libcurl.o \ cd_shared.o \ cl_collision.o \ cl_demo.o \ diff --git a/model_shared.c b/model_shared.c index 8b2333f4..4e411648 100644 --- a/model_shared.c +++ b/model_shared.c @@ -344,6 +344,24 @@ model_t *Mod_ForName(const char *name, qboolean crash, qboolean checkdisk, qbool return model; } +/* +================== +Mod_Reload + +Reloads all models if they have changed +================== +*/ +void Mod_Reload() +{ + int i; + model_t *mod; + + for (i = 0, mod = mod_known;i < mod_numknown;i++, mod++) + if (mod->name[0]) + if (mod->used) + Mod_LoadModel(mod, true, true, mod->isworldmodel); +} + unsigned char *mod_base; diff --git a/model_shared.h b/model_shared.h index e12da96b..4b539e23 100644 --- a/model_shared.h +++ b/model_shared.h @@ -603,6 +603,7 @@ extern unsigned char *mod_base; extern cvar_t r_fullbrights; void Mod_Init (void); +void Mod_Reload (void); model_t *Mod_LoadModel(model_t *mod, qboolean crash, qboolean checkdisk, qboolean isworldmodel); model_t *Mod_FindName (const char *name); model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel); diff --git a/sv_main.c b/sv_main.c index 2efbb889..2e45d00f 100644 --- a/sv_main.c +++ b/sv_main.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // sv_main.c -- server main program #include "quakedef.h" +#include "libcurl.h" void SV_VM_Init(); void SV_VM_Setup(); @@ -1677,6 +1678,10 @@ void SV_SpawnServer (const char *server) svs.changelevel_issued = false; // now safe to issue another + // make the map a required file for clients + Curl_ClearRequirements(); + Curl_RequireFile(modelname); + // // tell all connected clients that we are going to a new level // -- 2.39.2