]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
the record command now disconnects you if starting a new map, this fixes a crash...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index e0883aeb5716e1be59056d202cd2b120f56a79de..6a8c0352b55b85dfc3085ebe8cf4e504fde0f813 100644 (file)
--- a/host.c
+++ b/host.c
@@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <time.h>
 #include "quakedef.h"
+#include "libcurl.h"
 #include "cdaudio.h"
 #include "cl_video.h"
 #include "progsvm.h"
@@ -51,6 +52,9 @@ client_t *host_client;
 
 jmp_buf host_abortframe;
 
+// random seed
+cvar_t sv_random_seed = {0, "sv_random_seed", "", "random seed; when set, on every map start this random seed is used to initialize the random number generator. Don't touch it unless for benchmarking or debugging"};
+
 // pretend frames take this amount of time (in seconds), 0 = realtime
 cvar_t host_framerate = {0, "host_framerate","0", "locks frame timing to this value in seconds, 0.05 is 20fps for example, note that this can easily run too fast, use host_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"};
 // shows time used by certain subsystems
@@ -85,7 +89,7 @@ cvar_t pausable = {0, "pausable","1", "allow players to pause or not"};
 cvar_t temp1 = {0, "temp1","0", "general cvar for mods to use, in stock id1 this selects which death animation to use on players (0 = random death, other values select specific death scenes)"};
 
 cvar_t timestamps = {CVAR_SAVE, "timestamps", "0", "prints timestamps on console messages"};
-cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%b %e %X] ", "time format to use on timestamped console messages"};
+cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%Y-%m-%d %H:%M:%S] ", "time format to use on timestamped console messages"};
 
 /*
 ================
@@ -131,7 +135,7 @@ void Host_Error (const char *error, ...)
                Sys_Error ("Host_Error: recursively entered (original error was: %s    new error is: %s)", hosterrorstring2, hosterrorstring1);
        hosterror = true;
 
-       strcpy(hosterrorstring2, hosterrorstring1);
+       strlcpy(hosterrorstring2, hosterrorstring1, sizeof(hosterrorstring2));
 
        CL_Parse_DumpPacket();
 
@@ -212,10 +216,13 @@ Host_InitLocal
 ======================
 */
 void Host_SaveConfig_f(void);
+void Host_LoadConfig_f(void);
 static void Host_InitLocal (void)
 {
        Cmd_AddCommand("saveconfig", Host_SaveConfig_f, "save settings to config.cfg immediately (also automatic when quitting)");
+       Cmd_AddCommand("loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
 
+       Cvar_RegisterVariable (&sv_random_seed);
        Cvar_RegisterVariable (&host_framerate);
        Cvar_RegisterVariable (&host_speeds);
        Cvar_RegisterVariable (&slowmo);
@@ -260,7 +267,7 @@ void Host_SaveConfig_f(void)
 // dedicated servers initialize the host but don't parse and set the
 // config.cfg cvars
        // LordHavoc: don't save a config if it crashed in startup
-       if (host_framecount >= 3 && cls.state != ca_dedicated)
+       if (host_framecount >= 3 && cls.state != ca_dedicated && !COM_CheckParm("-benchmark"))
        {
                f = FS_Open ("config.cfg", "wb", false, false);
                if (!f)
@@ -277,6 +284,21 @@ void Host_SaveConfig_f(void)
 }
 
 
+/*
+===============
+Host_LoadConfig_f
+
+Resets key bindings and cvars to defaults and then reloads scripts
+===============
+*/
+void Host_LoadConfig_f(void)
+{
+       // unlock the cvar default strings so they can be updated by the new default.cfg
+       Cvar_UnlockDefaults();
+       // reset cvars to their defaults, and then exec startup scripts again
+       Cbuf_InsertText("cvar_resettodefaults_all;exec quake.rc\n");
+}
+
 /*
 =================
 SV_ClientPrint
@@ -328,7 +350,7 @@ void SV_BroadcastPrint(const char *msg)
 
        for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
        {
-               if (client->spawned && client->netconnection)
+               if (client->active && client->netconnection)
                {
                        MSG_WriteByte(&client->netconnection->message, svc_print);
                        MSG_WriteString(&client->netconnection->message, msg);
@@ -432,11 +454,18 @@ void SV_DropClient(qboolean crash)
                prog->globals.server->self = saveSelf;
        }
 
+       // if a download is active, close it
+       if (host_client->download_file)
+       {
+               Con_DPrintf("Download of %s aborted when %s dropped\n", host_client->download_name, host_client->name);
+               FS_Close(host_client->download_file);
+               host_client->download_file = NULL;
+               host_client->download_name[0] = 0;
+               host_client->download_expectedposition = 0;
+               host_client->download_started = false;
+       }
+
        // remove leaving player from scoreboard
-       //host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
-       //if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
-       //      val->_float = 0;
-       //host_client->edict->fields.server->frags = 0;
        host_client->name[0] = 0;
        host_client->colors = 0;
        host_client->frags = 0;
@@ -601,7 +630,8 @@ void Host_Main(void)
                }
 
                // keep the random time dependent
-               rand();
+               if(!*sv_random_seed.string)
+                       rand();
 
                cl.islocalgame = NetConn_IsLocalGame();
 
@@ -619,12 +649,17 @@ void Host_Main(void)
 
                NetConn_UpdateSockets();
 
+               Curl_Run();
+
        //-------------------
        //
        // server operations
        //
        //-------------------
 
+               // check for commands typed to the host
+               Host_GetConsoleCommands();
+
                if (sv_timer > 0)
                {
                        if (!sv.active)
@@ -646,15 +681,19 @@ void Host_Main(void)
                                // the middle of Host_Frame
                                NetConn_ServerFrame();
 
-                               // check for commands typed to the host
-                               Host_GetConsoleCommands();
-
                                // run the world state
                                // don't allow simulation to run too fast or too slow or logic glitches can occur
 
                                // stop running server frames if the wall time reaches this value
-                               if (sys_ticrate.value <= 0 || (cl.islocalgame && !sv_fixedframeratesingleplayer.integer))
+                               if (sys_ticrate.value <= 0)
                                        advancetime = sv_timer;
+                               else if (cl.islocalgame && !sv_fixedframeratesingleplayer.integer)
+                               {
+                                       // synchronize to the client frametime, but no less than 10ms and no more than sys_ticrate
+                                       advancetime = bound(0.01, cl_timer, sys_ticrate.value);
+                                       framelimit = 10;
+                                       aborttime = Sys_DoubleTime() + 0.1;
+                               }
                                else
                                {
                                        advancetime = sys_ticrate.value;
@@ -728,10 +767,15 @@ void Host_Main(void)
                                // decide the simulation time
                                if (!cls.timedemo)
                                {
-                                       if (cls.capturevideo_active && !cls.capturevideo_soundfile)
+                                       if (cls.capturevideo.active)
                                        {
-                                               frametime = 1.0 / cls.capturevideo_framerate;
-                                               cl.realframetime = max(cl.realframetime, frametime);
+                                               if (cls.capturevideo.realtime)
+                                                       frametime = cl.realframetime = max(cl.realframetime, 1.0 / cls.capturevideo.framerate);
+                                               else
+                                               {
+                                                       frametime = 1.0 / cls.capturevideo.framerate;
+                                                       cl.realframetime = max(cl.realframetime, frametime);
+                                               }
                                        }
                                        else if (vid_activewindow)
                                                frametime = cl.realframetime = max(cl.realframetime, 1.0 / cl_maxfps.value);
@@ -786,7 +830,7 @@ void Host_Main(void)
                                        csqc_usecsqclistener = false;
                                }
                                else
-                                       S_Update(&r_refdef.viewentitymatrix);
+                                       S_Update(&r_view.matrix);
 
                                CDAudio_Update();
                        }
@@ -831,7 +875,6 @@ extern void FS_Shutdown(void);
 extern void PR_Cmd_Init(void);
 extern void COM_Init_Commands(void);
 extern void FS_Init_Commands(void);
-extern void COM_CheckRegistered(void);
 extern qboolean host_stuffcmdsrun;
 
 /*
@@ -844,6 +887,9 @@ static void Host_Init (void)
        int i;
        const char* os;
 
+       // LordHavoc: quake never seeded the random number generator before... heh
+       srand(time(NULL));
+
        // FIXME: this is evil, but possibly temporary
 // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers)
        if (COM_CheckParm("-developer"))
@@ -862,20 +908,28 @@ static void Host_Init (void)
                developer_memorydebug.string = "100";
        }
 
-       // LordHavoc: quake never seeded the random number generator before... heh
-       srand(time(NULL));
+// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
+       if (COM_CheckParm("-nostdout"))
+               sys_nostdout = 1;
 
        // used by everything
        Memory_Init();
 
-       // initialize console and logging
-       Con_Init();
-
        // initialize console command/cvar/alias/command execution systems
        Cmd_Init();
 
-       // parse commandline
-       COM_InitArgv();
+       // initialize memory subsystem cvars/commands
+       Memory_Init_Commands();
+
+       // initialize console and logging and its cvars/commands
+       Con_Init();
+
+       // initialize various cvars that could not be initialized earlier
+       Curl_Init_Commands();
+       Cmd_Init_Commands();
+       Sys_Init_Commands();
+       COM_Init_Commands();
+       FS_Init_Commands();
 
        // initialize console window (only used by sys_win.c)
        Sys_InitConsole();
@@ -902,33 +956,21 @@ static void Host_Init (void)
        os = "Unknown";
 #endif
        dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
+       Con_Printf("%s\n", engineversion);
 
-// COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from
-       if (COM_CheckParm("-nostdout"))
-               sys_nostdout = 1;
-       else
-               Con_Printf("%s\n", engineversion);
+       // initialize ixtable
+       Mathlib_Init();
 
        // initialize filesystem (including fs_basedir, fs_gamedir, -path, -game, scr_screenshot_name)
        FS_Init();
 
-       // initialize various cvars that could not be initialized earlier
-       Memory_Init_Commands();
-       Con_Init_Commands();
-       Cmd_Init_Commands();
-       Sys_Init_Commands();
-       COM_Init_Commands();
-       FS_Init_Commands();
-       COM_CheckRegistered();
-
-       // initialize ixtable
-       Mathlib_Init();
-
        NetConn_Init();
+       Curl_Init();
        //PR_Init();
        //PR_Cmd_Init();
        PRVM_Init();
        Mod_Init();
+       World_Init();
        SV_Init();
        Host_InitCommands();
        Host_InitLocal();
@@ -1079,6 +1121,7 @@ void Host_Shutdown(void)
 
        CDAudio_Shutdown ();
        S_Terminate ();
+       Curl_Shutdown ();
        NetConn_Shutdown ();
        //PR_Shutdown ();