]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
host: Implement a hook struct in host_t. Use a hook to connect to local server
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Aug 2020 14:54:10 +0000 (14:54 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 12 Aug 2020 14:54:10 +0000 (14:54 +0000)
This eliminates some client-specific code in the server.

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12899 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
quakedef.h
sv_ccmds.c

index 6ba4bd0c69a52c374ae1312a667d22fc7923c6a7..de454ffe22369a9ab33d10d30ea1f41724665793 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -569,6 +569,11 @@ void CL_EstablishConnection(const char *address, int firstarg)
        }
 }
 
+static void CL_EstablishConnection_Local(void)
+{
+       CL_EstablishConnection("local:1", -2);
+}
+
 /*
 ==============
 CL_PrintEntities_f
@@ -3049,6 +3054,8 @@ void CL_Init (void)
 
                CL_Video_Init();
 
+               host.hook.ConnectLocal = CL_EstablishConnection_Local;
+
                #ifdef CONFIG_MENU
                Cbuf_InsertText(&cmd_client,"menu_start\n");
                #endif
index 8c0ba38c60c230aed1f1cd0be0fbe3a6ff776c32..41c91c9644a1c5fde554db33c3c8d42fff4a1f7a 100644 (file)
@@ -549,6 +549,11 @@ typedef struct host_s
        qboolean restless; // don't sleep
        qboolean paused; // global paused state, pauses both client and server
        cbuf_t *cbuf;
+
+       struct
+       {
+               void (*ConnectLocal)(void);
+       } hook;
 } host_t;
 
 extern host_t host;
index e4fd309deb6c3202c37aadc0a9800b896720fbfd..b5b55bf38d129f2fd7a33e80ad130cfc8de6a525 100644 (file)
@@ -84,8 +84,9 @@ static void SV_Map_f(cmd_state_t *cmd)
        svs.serverflags = 0;                    // haven't completed an episode yet
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
        SV_SpawnServer(level);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 /*
@@ -121,8 +122,9 @@ static void SV_Changelevel_f(cmd_state_t *cmd)
        SV_SaveSpawnparms ();
        strlcpy(level, Cmd_Argv(cmd, 1), sizeof(level));
        SV_SpawnServer(level);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+       
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 /*
@@ -156,8 +158,9 @@ static void SV_Restart_f(cmd_state_t *cmd)
 
        strlcpy(mapname, sv.name, sizeof(mapname));
        SV_SpawnServer(mapname);
-       if (sv.active && cls.state == ca_disconnected)
-               CL_EstablishConnection("local:1", -2);
+       
+       if(sv.active && host.hook.ConnectLocal != NULL)
+               host.hook.ConnectLocal();
 }
 
 //===========================================================================