]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
made darkplaces compile successfully with g++ to test for errors C doesn't care about...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index abbbff181452e2ca4f75ac0e64ec951210196ddd..97b51e240bf6fd5e8c9ca56f24f974abcd99e304 100644 (file)
--- a/host.c
+++ b/host.c
@@ -166,53 +166,42 @@ 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"))
+                       Con_Printf ("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);
 
-       svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
+       svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
 
        if (svs.maxclients > 1 && !deathmatch.integer)
                Cvar_SetValueQuick(&deathmatch, 1);
@@ -488,7 +477,7 @@ void Host_ShutdownServer(qboolean crash)
 {
        int i, count;
        sizebuf_t buf;
-       char message[4];
+       qbyte message[4];
 
        Con_DPrintf("Host_ShutdownServer\n");
 
@@ -523,8 +512,6 @@ void Host_ShutdownServer(qboolean crash)
        memset(&sv, 0, sizeof(sv));
        memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
 
-       PRVM_ResetProg();
-
        SV_VM_End();
 }
 
@@ -681,7 +668,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++)
@@ -879,7 +866,6 @@ void Host_StartVideo(void)
                vid_opened = true;
                VID_Start();
                CDAudio_Startup();
-               CL_InitTEnts();  // We must wait after sound startup to load tent sounds
        }
 }
 
@@ -1027,6 +1013,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");
@@ -1037,6 +1037,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)
        {
@@ -1056,19 +1076,6 @@ void Host_Init (void)
        Con_DPrint("========Initialized=========\n");
 
        Host_StartVideo();
-
-       // 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
-
-       // here comes the not so critical stuff
-       if (setjmp(host_abortframe)) {
-               return;
-       }
-
-       if (vid_opened && cls.state != ca_dedicated)
-       {
-               MR_Init();
-       }
 }