From: cloudwalk Date: Wed, 12 Aug 2020 14:54:10 +0000 (+0000) Subject: host: Implement a hook struct in host_t. Use a hook to connect to local server X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=4ae651988f406a5ea7c4e609410b0c408f555cd9 host: Implement a hook struct in host_t. Use a hook to connect to local server 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 --- diff --git a/cl_main.c b/cl_main.c index 6ba4bd0c..de454ffe 100644 --- 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 diff --git a/quakedef.h b/quakedef.h index 8c0ba38c..41c91c96 100644 --- a/quakedef.h +++ b/quakedef.h @@ -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; diff --git a/sv_ccmds.c b/sv_ccmds.c index e4fd309d..b5b55bf3 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -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(); } //===========================================================================