]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
added -demo and -demolooponly options. -demo starts the wanted demo and then shuts...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 608f9c2b5b9ae2b5b5fa3c5ba55d62a1f8138528..c6b493c9bed114b7f2b71c90771d0642201c818f 100644 (file)
--- a/host.c
+++ b/host.c
@@ -56,7 +56,7 @@ int forcedeveloper;
 // current client
 client_t *host_client;
 
-jmp_buf host_abortserver;
+jmp_buf host_abortframe;
 
 // pretend frames take this amount of time (in seconds), 0 = realtime
 cvar_t host_framerate = {0, "host_framerate","0"};
@@ -102,7 +102,7 @@ aborts the current host frame and goes on with the next one
 */
 void Host_AbortCurrentFrame(void)
 {
-       longjmp (host_abortserver, 1);
+       longjmp (host_abortframe, 1);
 }
 
 /*
@@ -166,49 +166,38 @@ void Host_ServerOptions (void)
 
 // COMMANDLINEOPTION: Server: -dedicated [playerlimit] starts a dedicated server (with a command console), default playerlimit is 8
 // COMMANDLINEOPTION: Server: -listen [playerlimit] starts a multiplayer server with graphical client, like singleplayer but other players can connect, default playerlimit is 8
-       if (cl_available)
+       // if no client is in the executable or -dedicated is specified on
+       // commandline, start a dedicated server
+       i = COM_CheckParm ("-dedicated");
+       if (i || !cl_available)
        {
-               // client exists, check what mode the user wants
-               i = COM_CheckParm ("-dedicated");
+               cls.state = ca_dedicated;
+               // check for -dedicated specifying how many players
+               if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
+                       svs.maxclients = atoi (com_argv[i+1]);
+               if (COM_CheckParm ("-listen"))
+                       Sys_Error ("Only one of -dedicated or -listen can be specified");
+               // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
+               Cvar_SetValue("sv_public", 1);
+       }
+       else if (cl_available)
+       {
+               // client exists and not dedicated, check if -listen is specified
+               cls.state = ca_disconnected;
+               i = COM_CheckParm ("-listen");
                if (i)
                {
-                       cls.state = ca_dedicated;
                        // default players unless specified
                        if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
                                svs.maxclients = atoi (com_argv[i+1]);
-                       if (COM_CheckParm ("-listen"))
-                               Sys_Error ("Only one of -dedicated or -listen can be specified");
                }
                else
                {
-                       cls.state = ca_disconnected;
-                       i = COM_CheckParm ("-listen");
-                       if (i)
-                       {
-                               // default players unless specified
-                               if (i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
-                                       svs.maxclients = atoi (com_argv[i+1]);
-                       }
-                       else
-                       {
-                               // default players in some games, singleplayer in most
-                               if (gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
-                                       svs.maxclients = 1;
-                       }
+                       // default players in some games, singleplayer in most
+                       if (gamemode != GAME_GOODVSBAD2 && gamemode != GAME_NEXUIZ && gamemode != GAME_BATTLEMECH)
+                               svs.maxclients = 1;
                }
        }
-       else
-       {
-               // no client in the executable, always start dedicated server
-               if (COM_CheckParm ("-listen"))
-                       Sys_Error ("-listen not available in a dedicated server executable");
-               cls.state = ca_dedicated;
-               // check for -dedicated specifying how many players
-               i = COM_CheckParm ("-dedicated");
-               // default players unless specified
-               if (i && i + 1 < com_argc && atoi (com_argv[i+1]) >= 1)
-                       svs.maxclients = atoi (com_argv[i+1]);
-       }
 
        svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD);
 
@@ -681,7 +670,7 @@ void Host_ServerFrame (void)
        }
        sv.timer += host_realframetime;
 
-    
+
        // run the world state
        // don't allow simulation to run too fast or too slow or logic glitches can occur
        for (framecount = 0;framecount < framelimit && sv.timer > 0;framecount++)
@@ -745,7 +734,7 @@ void _Host_Frame (float time)
        static double time3 = 0;
        int pass1, pass2, pass3;
 
-       if (setjmp(host_abortserver))
+       if (setjmp(host_abortframe))
                return;                 // something bad happened, or the server disconnected
 
        // decide the simulation time
@@ -880,7 +869,6 @@ void Host_StartVideo(void)
                VID_Start();
                CDAudio_Startup();
                CL_InitTEnts();  // We must wait after sound startup to load tent sounds
-               MR_Init();
        }
 }
 
@@ -1028,6 +1016,20 @@ void Host_Init (void)
        // save console log up to this point to log_file if it was set by configs
        Log_Start();
 
+       // FIXME: put this into some neat design, but the menu should be allowed to crash
+       // without crashing the whole game, so this should just be a short-time solution
+       Host_StartVideo();
+
+       // here comes the not so critical stuff
+       if (setjmp(host_abortframe)) {
+               return;
+       }
+
+       if (cls.state != ca_dedicated)
+       {
+               MR_Init();
+       }
+
        // check for special benchmark mode
 // COMMANDLINEOPTION: Client: -benchmark <demoname> runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log)
        i = COM_CheckParm("-benchmark");
@@ -1038,6 +1040,26 @@ void Host_Init (void)
                Cbuf_Execute();
        }
 
+       // check for special demo mode
+// COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits
+       i = COM_CheckParm("-demo");
+       if (i && i + 1 < com_argc)
+       if (!sv.active && !cls.demoplayback && !cls.connect_trying)
+       {
+               Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
+               Cbuf_Execute();
+       }
+
+       // check for special demolooponly mode
+// COMMANDLINEOPTION: Client: -demolooponly <demoname> runs a playdemo and quits
+       i = COM_CheckParm("-demolooponly");
+       if (i && i + 1 < com_argc)
+       if (!sv.active && !cls.demoplayback && !cls.connect_trying)
+       {
+               Cbuf_AddText(va("playdemo %s\n", com_argv[i + 1]));
+               Cbuf_Execute();
+       }
+
        if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {