]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
Fix the +map crash once and for all. Defer stuffcmds until it's safe to run.
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 1b4f546db23d1c004660d9f9dc6748a2986ae37b..9a3d6ace0e82e46c5b88912b6933fc2be41d54d2 100644 (file)
--- a/host.c
+++ b/host.c
@@ -47,6 +47,9 @@ Memory is cleared / released when a server or client begins, not when they end.
 // how many frames have occurred
 // (checked by Host_Error and Host_SaveConfig_f)
 int host_framecount = 0;
+
+// Cloudwalk: set when Host_Init is executed
+qboolean host_init = false;
 // LadyHavoc: set when quit is executed
 qboolean host_shuttingdown = false;
 
@@ -328,6 +331,7 @@ static void Host_AddConfigText(cmd_state_t *cmd)
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
        else
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec " STARTCONFIGFILENAME "\n");
+       Cbuf_Execute(cmd);
 }
 
 /*
@@ -781,6 +785,7 @@ void Host_Main(void)
                        // process console commands
 //                     R_TimeReport("preconsole");
                        CL_VM_PreventInformationLeaks();
+                       Cbuf_Frame(&cmd_clientfromserver);
                        Cbuf_Frame(&cmd_client);
                        Cbuf_Frame(&cmd_server);
 
@@ -789,11 +794,6 @@ void Host_Main(void)
                                Cbuf_Frame(&cmd_serverfromclient);
                        }
 
-                       if(cls.netcon)
-                       {
-                               Cbuf_Frame(&cmd_clientfromserver);
-                       }
-
 //                     R_TimeReport("console");
                }
 
@@ -1166,6 +1166,8 @@ void Host_UnlockSession(void)
        }
 }
 
+extern hook_t *csqc_concmd;
+
 /*
 ====================
 Host_Init
@@ -1179,6 +1181,8 @@ static void Host_Init (void)
        qboolean dedicated_server = COM_CheckParm("-dedicated") || !cl_available;
        cmd_state_t *cmd = &cmd_client;
 
+       host_init = true;
+
        if (COM_CheckParm("-profilegameonly"))
                Sys_AllowProfiling(false);
 
@@ -1233,6 +1237,8 @@ static void Host_Init (void)
        // initialize memory subsystem cvars/commands
        Memory_Init_Commands();
 
+       Hook_Init();
+       csqc_concmd = Hook_Register(csqc_concmd,CL_VM_ConsoleCommand,1);
        // initialize console and logging and its cvars/commands
        Con_Init();
 
@@ -1289,28 +1295,7 @@ static void Host_Init (void)
        Thread_Init();
        TaskQueue_Init();
 
-       if (cls.state == ca_dedicated)
-       {
-               cmd = &cmd_server;
-               Cmd_AddCommand(&cmd_server, "disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)");
-       }
-       else
-       {
-               Con_DPrintf("Initializing client\n");
-
-               R_Modules_Init();
-               Palette_Init();
-#ifdef CONFIG_MENU
-               MR_Init_Commands();
-#endif
-               VID_Shared_Init();
-               VID_Init();
-               Render_Init();
-               S_Init();
-               CDAudio_Init();
-               Key_Init();
-               CL_Init();
-       }
+       CL_Init();
 
        // save off current state of aliases, commands and cvars for later restore if FS_GameDir_f is called
        // NOTE: menu commands are freed by Cmd_RestoreInitState
@@ -1325,15 +1310,22 @@ static void Host_Init (void)
        }
 
        Host_AddConfigText(cmd);
-       Cbuf_Execute(cmd);
 
-       // if stuffcmds wasn't run, then quake.rc is probably missing, use default
-       if (!host_stuffcmdsrun)
+       Host_StartVideo();
+
+       // if quake.rc is missing, use default
+       if (!FS_FileExists("quake.rc"))
        {
-               Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\nstuffcmds\n");
+               Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
                Cbuf_Execute(cmd);
        }
 
+       host_init = false;
+
+       // run stuffcmds now, deferred previously because it can crash if a server starts that early
+       Cbuf_AddText(cmd,"stuffcmds\n");
+       Cbuf_Execute(cmd);
+
        Log_Start();
        
        // put up the loading image so the user doesn't stare at a black screen...