]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
cvar: Check if cvar is NULL before adding callback. Implement Cvar_Callback to fire...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 54d91ac6062a5048dedf3deac811519fe9491611..268c1467ee2ba715baa6e62c900da2ec411b353b 100644 (file)
--- a/host.c
+++ b/host.c
@@ -23,12 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <time.h>
 #include "libcurl.h"
-#include "cdaudio.h"
-#include "cl_video.h"
-#include "progsvm.h"
-#include "csprogs.h"
-#include "sv_demo.h"
-#include "snd_main.h"
 #include "taskqueue.h"
 #include "utf8lib.h"
 
@@ -65,6 +59,8 @@ cvar_t timeformat = {CF_CLIENT | CF_SERVER | CF_ARCHIVE, "timeformat", "[%Y-%m-%
 cvar_t sessionid = {CF_CLIENT | CF_SERVER | CF_READONLY, "sessionid", "", "ID of the current session (use the -sessionid parameter to set it); this is always either empty or begins with a dot (.)"};
 cvar_t locksession = {CF_CLIENT | CF_SERVER, "locksession", "0", "Lock the session? 0 = no, 1 = yes and abort on failure, 2 = yes and continue on failure"};
 
+cvar_t host_isclient = {CF_SHARED | CF_READONLY, "_host_isclient", "0", "If 1, clientside is active."};
+
 /*
 ================
 Host_AbortCurrentFrame
@@ -129,7 +125,6 @@ void Host_Error (const char *error, ...)
        PRVM_Crash(MVM_prog);
 #endif
 
-       cl.csqc_loaded = false;
        Cvar_SetValueQuick(&csqc_progcrc, -1);
        Cvar_SetValueQuick(&csqc_progsize, -1);
 
@@ -148,62 +143,12 @@ void Host_Error (const char *error, ...)
        Host_AbortCurrentFrame();
 }
 
-static void Host_ServerOptions (void)
-{
-       int i;
-
-       // general default
-       svs.maxclients = 8;
-
-// 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 no client is in the executable or -dedicated is specified on
-       // commandline, start a dedicated server
-       i = Sys_CheckParm ("-dedicated");
-       if (i || !cl_available)
-       {
-               cls.state = ca_dedicated;
-               // check for -dedicated specifying how many players
-               if (i && i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
-                       svs.maxclients = atoi (sys.argv[i+1]);
-               if (Sys_CheckParm ("-listen"))
-                       Con_Printf ("Only one of -dedicated or -listen can be specified\n");
-               // default sv_public on for dedicated servers (often hosted by serious administrators), off for listen servers (often hosted by clueless users)
-               Cvar_SetValue(&cvars_all, "sv_public", 1);
-       }
-       else if (cl_available)
-       {
-               // client exists and not dedicated, check if -listen is specified
-               cls.state = ca_disconnected;
-               i = Sys_CheckParm ("-listen");
-               if (i)
-               {
-                       // default players unless specified
-                       if (i + 1 < sys.argc && atoi (sys.argv[i+1]) >= 1)
-                               svs.maxclients = atoi (sys.argv[i+1]);
-               }
-               else
-               {
-                       // default players in some games, singleplayer in most
-                       if (gamemode != GAME_GOODVSBAD2 && !IS_NEXUIZ_DERIVED(gamemode) && gamemode != GAME_BATTLEMECH)
-                               svs.maxclients = 1;
-               }
-       }
-
-       svs.maxclients = svs.maxclients_next = bound(1, svs.maxclients, MAX_SCOREBOARD);
-
-       svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
-
-       if (svs.maxclients > 1 && !deathmatch.integer && !coop.integer)
-               Cvar_SetValueQuick(&deathmatch, 1);
-}
-
 /*
 ==================
 Host_Quit_f
 ==================
 */
-void Host_Quit_f(cmd_state_t *cmd)
+static void Host_Quit_f(cmd_state_t *cmd)
 {
        if(host.state == host_shutdown)
                Con_Printf("shutting down already!\n");
@@ -222,6 +167,21 @@ static void Host_Framerate_c(cvar_t *var)
                Cvar_SetValueQuick(var, 0);
 }
 
+// TODO: Find a better home for this.
+static void SendCvar_f(cmd_state_t *cmd)
+{
+       if(cmd->source == src_local && host.hook.SV_SendCvar)
+       {
+               host.hook.SV_SendCvar(cmd);
+               return;
+       }
+       if(cmd->source == src_client && host.hook.CL_SendCvar)
+       {
+               host.hook.CL_SendCvar(cmd);
+               return;
+       }
+}
+
 /*
 =======================
 Host_InitLocal
@@ -237,11 +197,13 @@ static void Host_InitLocal (void)
        Cmd_AddCommand(CF_SHARED, "version", Host_Version_f, "print engine version");
        Cmd_AddCommand(CF_SHARED, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)");
        Cmd_AddCommand(CF_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs");
+       Cmd_AddCommand(CF_SHARED, "sendcvar", SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC");
        Cvar_RegisterVariable (&cl_maxphysicsframesperserverframe);
        Cvar_RegisterVariable (&host_framerate);
        Cvar_RegisterCallback (&host_framerate, Host_Framerate_c);
        Cvar_RegisterVariable (&host_speeds);
        Cvar_RegisterVariable (&host_maxwait);
+       Cvar_RegisterVariable (&host_isclient);
 
        Cvar_RegisterVariable (&developer);
        Cvar_RegisterVariable (&developer_extra);
@@ -519,21 +481,6 @@ void Host_Main(void)
 
 //============================================================================
 
-qbool vid_opened = false;
-void Host_StartVideo(void)
-{
-       if (!vid_opened && cls.state != ca_dedicated)
-       {
-               vid_opened = true;
-#ifdef WIN32
-               // make sure we open sockets before opening video because the Windows Firewall "unblock?" dialog can screw up the graphics context on some graphics drivers
-               NetConn_UpdateSockets();
-#endif
-               VID_Start();
-               CDAudio_Startup();
-       }
-}
-
 char engineversion[128];
 
 qbool sys_nostdout = false;
@@ -613,6 +560,12 @@ static void Host_Init (void)
        char vabuf[1024];
        cmd_state_t *cmd = &cmd_client;
 
+       host.hook.ConnectLocal = NULL;
+       host.hook.Disconnect = NULL;
+       host.hook.ToggleMenu = NULL;
+       host.hook.CL_Intermission = NULL;
+       host.hook.SV_CanSave = NULL;
+
        host.state = host_init;
 
        if (setjmp(host.abortframe)) // Huh?!
@@ -704,7 +657,6 @@ static void Host_Init (void)
        World_Init();
        SV_Init();
        Host_InitLocal();
-       Host_ServerOptions();
 
        Thread_Init();
        TaskQueue_Init();
@@ -731,7 +683,7 @@ static void Host_Init (void)
 
        host.state = host_active;
 
-       Host_StartVideo();
+       CL_StartVideo();
 
        Log_Start();