]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
Improve windows manifest indenting
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 65c22bc856d48fe9b7beca1dcb60946890cac924..1dc4b0d5b8d2c65dd569bad28d0f6d1b302e98bf 100644 (file)
--- a/host.c
+++ b/host.c
@@ -23,14 +23,7 @@ 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 "thread.h"
 #include "utf8lib.h"
 
 /*
@@ -66,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
@@ -130,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);
 
@@ -149,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");
@@ -223,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
@@ -238,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);
@@ -332,10 +293,10 @@ void Host_LoadConfig_f(cmd_state_t *cmd)
        Cmd_RestoreInitState();
 #ifdef CONFIG_MENU
        // prepend a menu restart command to execute after the config
-       Cbuf_InsertText(&cmd_client, "\nmenu_restart\n");
+       Cbuf_InsertText(cmd_client, "\nmenu_restart\n");
 #endif
        // reset cvars to their defaults, and then exec startup scripts again
-       Host_AddConfigText(&cmd_client);
+       Host_AddConfigText(cmd_client);
 }
 
 //============================================================================
@@ -354,9 +315,9 @@ static void Host_GetConsoleCommands (void)
        while ((line = Sys_ConsoleInput()))
        {
                if (cls.state == ca_dedicated)
-                       Cbuf_AddText(&cmd_server, line);
+                       Cbuf_AddText(cmd_server, line);
                else
-                       Cbuf_AddText(&cmd_client, line);
+                       Cbuf_AddText(cmd_client, line);
        }
 }
 
@@ -520,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;
@@ -612,10 +558,18 @@ static void Host_Init (void)
        int i;
        const char* os;
        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?!
+               Sys_Error("Engine initialization failed. Check the console (if available) for additional information.\n");
+
        if (Sys_CheckParm("-profilegameonly"))
                Sys_AllowProfiling(false);
 
@@ -702,7 +656,6 @@ static void Host_Init (void)
        World_Init();
        SV_Init();
        Host_InitLocal();
-       Host_ServerOptions();
 
        Thread_Init();
        TaskQueue_Init();
@@ -717,22 +670,19 @@ static void Host_Init (void)
        // 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;
-       }
 
-       Host_AddConfigText(cmd);
+       Host_AddConfigText(cmd_client);
 
        // if quake.rc is missing, use default
        if (!FS_FileExists("quake.rc"))
        {
-               Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
-               Cbuf_Execute(cmd->cbuf);
+               Cbuf_AddText(cmd_client, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
+               Cbuf_Execute(cmd_client->cbuf);
        }
 
        host.state = host_active;
 
-       Host_StartVideo();
+       CL_StartVideo();
 
        Log_Start();
 
@@ -748,8 +698,8 @@ static void Host_Init (void)
        if (i && i + 1 < sys.argc)
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {
-               Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "timedemo %s\n", sys.argv[i + 1]));
-               Cbuf_Execute((&cmd_client)->cbuf);
+               Cbuf_AddText(cmd_client, va(vabuf, sizeof(vabuf), "timedemo %s\n", sys.argv[i + 1]));
+               Cbuf_Execute(cmd_client->cbuf);
        }
 
        // check for special demo mode
@@ -758,8 +708,8 @@ static void Host_Init (void)
        if (i && i + 1 < sys.argc)
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {
-               Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\n", sys.argv[i + 1]));
-               Cbuf_Execute((&cmd_client)->cbuf);
+               Cbuf_AddText(cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\n", sys.argv[i + 1]));
+               Cbuf_Execute(cmd_client->cbuf);
        }
 
 #ifdef CONFIG_VIDEO_CAPTURE
@@ -768,24 +718,24 @@ static void Host_Init (void)
        if (i && i + 1 < sys.argc)
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {
-               Cbuf_AddText(&cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", sys.argv[i + 1]));
-               Cbuf_Execute((&cmd_client)->cbuf);
+               Cbuf_AddText(cmd_client, va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", sys.argv[i + 1]));
+               Cbuf_Execute((cmd_client)->cbuf);
        }
 #endif
 
        if (cls.state == ca_dedicated || Sys_CheckParm("-listen"))
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {
-               Cbuf_AddText(&cmd_client, "startmap_dm\n");
-               Cbuf_Execute((&cmd_client)->cbuf);
+               Cbuf_AddText(cmd_client, "startmap_dm\n");
+               Cbuf_Execute(cmd_client->cbuf);
        }
 
        if (!sv.active && !cls.demoplayback && !cls.connect_trying)
        {
 #ifdef CONFIG_MENU
-               Cbuf_AddText(&cmd_client, "togglemenu 1\n");
+               Cbuf_AddText(cmd_client, "togglemenu 1\n");
 #endif
-               Cbuf_Execute((&cmd_client)->cbuf);
+               Cbuf_Execute(cmd_client->cbuf);
        }
 
        Con_DPrint("========Initialized=========\n");