]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
check for -safe
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index e04cc62292d503f1fb77381d9df95388616748e1..7b6cd76ef06ba4efe97b3e4e8af10f945040b329 100644 (file)
--- a/host.c
+++ b/host.c
@@ -56,6 +56,8 @@ cvar_t        slowmo = {0, "slowmo", "1.0"};                                  // LordHavoc: framerate independent sl
 cvar_t host_minfps = {CVAR_SAVE, "host_minfps", "10"};         // LordHavoc: game logic lower cap on framerate (if framerate is below this is, it pretends it is this, so game logic will run normally)
 cvar_t host_maxfps = {CVAR_SAVE, "host_maxfps", "1000"};               // LordHavoc: framerate upper cap
 
+cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1"};      // print broadcast messages in dedicated mode
+
 cvar_t sys_ticrate = {CVAR_SAVE, "sys_ticrate","0.05"};
 cvar_t serverprofile = {0, "serverprofile","0"};
 
@@ -141,12 +143,14 @@ void Host_Error (char *error, ...)
                Sys_Error ("Host_Error: recursively entered (original error was: %s    new error is: %s)", hosterrorstring, string);
        }
        inerror = true;
-       
+
        va_start (argptr,error);
        vsprintf (hosterrorstring,error,argptr);
        va_end (argptr);
        Con_Printf ("Host_Error: %s\n",hosterrorstring);
-       
+
+       PR_Crash();
+
        if (sv.active)
                Host_ShutdownServer (false);
 
@@ -161,29 +165,19 @@ void Host_Error (char *error, ...)
        longjmp (host_abortserver, 1);
 }
 
-static mempool_t *clients_mempool;
-
-/*
-================
-Host_FindMaxClients
-================
-*/
-void   Host_FindMaxClients (void)
+void Host_ServerOptions (void)
 {
-       int             i;
+       int i, numplayers;
 
-       svs.maxclients = 1;
+       numplayers = 1;
 
        i = COM_CheckParm ("-dedicated");
        if (i)
        {
                cls.state = ca_dedicated;
+               numplayers = 0;
                if (i != (com_argc - 1))
-               {
-                       svs.maxclients = atoi (com_argv[i+1]);
-               }
-               else
-                       svs.maxclients = 8;
+                       numplayers = atoi (com_argv[i+1]);
        }
        else
                cls.state = ca_disconnected;
@@ -193,34 +187,43 @@ void      Host_FindMaxClients (void)
        {
                if (cls.state == ca_dedicated)
                        Sys_Error ("Only one of -dedicated or -listen can be specified");
+               numplayers = 0;
                if (i != (com_argc - 1))
-                       svs.maxclients = atoi (com_argv[i+1]);
-               else
-                       svs.maxclients = 8;
+                       numplayers = atoi (com_argv[i+1]);
        }
 
+       if (numplayers < 1)
+               numplayers = 8;
+       if (numplayers > MAX_SCOREBOARD)
+               numplayers = MAX_SCOREBOARD;
+
        // Transfusion doesn't support single player games
-       if (gamemode == GAME_TRANSFUSION && svs.maxclients < 4)
-               svs.maxclients = 4;
+       if (gamemode == GAME_TRANSFUSION && numplayers < 4)
+               numplayers = 4;
+
+       if (numplayers > 1)
+               Cvar_SetValueQuick (&deathmatch, 1);
+       else
+               Cvar_SetValueQuick (&deathmatch, 0);
 
-       if (svs.maxclients < 1)
-               svs.maxclients = 8;
-       else if (svs.maxclients > MAX_SCOREBOARD)
-               svs.maxclients = MAX_SCOREBOARD;
+       svs.maxclients = 0;
+       SV_SetMaxClients(numplayers);
+}
 
-       svs.maxclientslimit = svs.maxclients;
-       if (svs.maxclientslimit < MAX_SCOREBOARD) // LordHavoc: upped listen mode limit from 4 to MAX_SCOREBOARD
-               svs.maxclientslimit = MAX_SCOREBOARD;
+static mempool_t *clients_mempool;
+void SV_SetMaxClients(int n)
+{
+       if (sv.active)
+               return;
+       n = bound(1, n, MAX_SCOREBOARD);
+       if (svs.maxclients == n)
+               return;
+       svs.maxclients = n;
        if (!clients_mempool)
                clients_mempool = Mem_AllocPool("clients");
        if (svs.clients)
                Mem_Free(svs.clients);
-       svs.clients = Mem_Alloc(clients_mempool, svs.maxclientslimit*sizeof(client_t));
-
-       if (svs.maxclients > 1)
-               Cvar_SetValue ("deathmatch", 1.0);
-       else
-               Cvar_SetValue ("deathmatch", 0.0);
+       svs.clients = Mem_Alloc(clients_mempool, svs.maxclients*sizeof(client_t));
 }
 
 
@@ -239,6 +242,8 @@ void Host_InitLocal (void)
        Cvar_RegisterVariable (&host_minfps);
        Cvar_RegisterVariable (&host_maxfps);
 
+       Cvar_RegisterVariable (&sv_echobprint);
+
        Cvar_RegisterVariable (&sys_ticrate);
        Cvar_RegisterVariable (&serverprofile);
 
@@ -261,7 +266,7 @@ void Host_InitLocal (void)
        Cvar_RegisterVariable (&timestamps);
        Cvar_RegisterVariable (&timeformat);
 
-       Host_FindMaxClients ();
+       Host_ServerOptions ();
 }
 
 
@@ -339,6 +344,9 @@ void SV_BroadcastPrintf (char *fmt, ...)
                        MSG_WriteByte (&svs.clients[i].message, svc_print);
                        MSG_WriteString (&svs.clients[i].message, string);
                }
+
+       if (sv_echobprint.integer && cls.state == ca_dedicated)
+               Sys_Printf ("%s", string);
 }
 
 /*
@@ -442,6 +450,9 @@ void Host_ShutdownServer(qboolean crash)
        if (!sv.active)
                return;
 
+       // print out where the crash happened, if it was caused by QC
+       PR_Crash();
+
        sv.active = false;
 
 // stop all client sounds immediately
@@ -490,7 +501,7 @@ void Host_ShutdownServer(qboolean crash)
 // clear structures
 //
        memset (&sv, 0, sizeof(sv));
-       memset (svs.clients, 0, svs.maxclientslimit*sizeof(client_t));
+       memset (svs.clients, 0, svs.maxclients * sizeof(client_t));
 }
 
 
@@ -618,7 +629,7 @@ void Host_ServerFrame (void)
        if (cls.state != ca_dedicated && svs.maxclients > 1 && ((realtime - lastservertime) < sys_ticrate.value))
                return;
 // run the world state
-       if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) )
+       if (!sv.paused && (svs.maxclients > 1 || (key_dest == key_game && !key_consoleactive)))
                sv.frametime = pr_global_struct->frametime = frametimetotal;
        else
                sv.frametime = 0;
@@ -636,7 +647,7 @@ void Host_ServerFrame (void)
 
 // move things around and think
 // always pause in single player if in console or menus
-       if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) )
+       if (sv.frametime)
                SV_Physics ();
 
 // send all messages to the clients