From 3d84db99ed9d8234809d237512f44cfa6d7ce1a0 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Fri, 16 Oct 2020 22:46:01 +0000 Subject: [PATCH] host: Move out some client and server code git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@13015 d7cf8633-e32d-0410-b094-e92efae38249 --- cd_shared.c | 4 +-- cl_main.c | 15 +++++++++++ cl_video.c | 4 +-- client.h | 2 ++ host.c | 69 +------------------------------------------------- host.h | 1 - menu.c | 2 +- model_shared.c | 2 +- prvm_exec.c | 3 +++ r_modules.c | 2 +- sv_main.c | 51 +++++++++++++++++++++++++++++++++++++ sys.h | 2 ++ sys_shared.c | 15 +++++++++++ vid_shared.c | 2 +- 14 files changed, 97 insertions(+), 77 deletions(-) diff --git a/cd_shared.c b/cd_shared.c index b5b52000..0f2f6fd1 100644 --- a/cd_shared.c +++ b/cd_shared.c @@ -122,7 +122,7 @@ static void CDAudio_Play_byName (const char *trackname, qbool looping, qbool try sfx_t* sfx; char filename[MAX_QPATH]; - Host_StartVideo(); + CL_StartVideo(); if (!enabled) return; @@ -275,7 +275,7 @@ static void CD_f(cmd_state_t *cmd) command = Cmd_Argv(cmd, 1); if (strcasecmp(command, "remap") != 0) - Host_StartVideo(); + CL_StartVideo(); if (strcasecmp(command, "on") == 0) { diff --git a/cl_main.c b/cl_main.c index 17c3fee2..2a2b9976 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2728,6 +2728,21 @@ void CL_UpdateEntityShading(void) CL_UpdateEntityShading_Entity(r_refdef.scene.entities[i]); } +qbool vid_opened = false; +void CL_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(); + } +} + extern cvar_t host_framerate; extern cvar_t host_speeds; diff --git a/cl_video.c b/cl_video.c index 7ecf3f19..2804661b 100644 --- a/cl_video.c +++ b/cl_video.c @@ -577,7 +577,7 @@ void CL_DrawVideo(void) void CL_VideoStart(char *filename, const char *subtitlesfile) { - Host_StartVideo(); + CL_StartVideo(); if( cl_videos->state != CLVIDEO_UNUSED ) CL_CloseVideo( cl_videos ); @@ -615,7 +615,7 @@ static void CL_PlayVideo_f(cmd_state_t *cmd) char name[MAX_QPATH], subtitlesfile[MAX_QPATH]; const char *extension; - Host_StartVideo(); + CL_StartVideo(); if (Sys_CheckParm("-benchmark")) return; diff --git a/client.h b/client.h index 7d185561..b4e8eb7a 100644 --- a/client.h +++ b/client.h @@ -1214,6 +1214,8 @@ double CL_Frame(double time); void CL_Shutdown (void); void CL_Init (void); +void CL_StartVideo(void); + void CL_EstablishConnection(const char *host, int firstarg); void CL_Disconnect (void); diff --git a/host.c b/host.c index 584b3817..72b588eb 100644 --- a/host.c +++ b/host.c @@ -131,7 +131,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); @@ -150,56 +149,6 @@ 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 @@ -522,21 +471,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; @@ -713,7 +647,6 @@ static void Host_Init (void) World_Init(); SV_Init(); Host_InitLocal(); - Host_ServerOptions(); Thread_Init(); TaskQueue_Init(); @@ -740,7 +673,7 @@ static void Host_Init (void) host.state = host_active; - Host_StartVideo(); + CL_StartVideo(); Log_Start(); diff --git a/host.h b/host.h index d4beddfd..9def0939 100644 --- a/host.h +++ b/host.h @@ -42,7 +42,6 @@ void Host_InitCommands(void); void Host_Main(void); double Host_Frame(double time); void Host_Shutdown(void); -void Host_StartVideo(void); void Host_Error(const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN; void Host_LockSession(void); void Host_UnlockSession(void); diff --git a/menu.c b/menu.c index 8dd76934..95202cac 100644 --- a/menu.c +++ b/menu.c @@ -5470,7 +5470,7 @@ static void Call_MR_ToggleMenu_f(cmd_state_t *cmd) { int m; m = ((Cmd_Argc(cmd) < 2) ? -1 : atoi(Cmd_Argv(cmd, 1))); - Host_StartVideo(); + CL_StartVideo(); if(MR_ToggleMenu) MR_ToggleMenu(m); } diff --git a/model_shared.c b/model_shared.c index 9a269a62..5c69dd23 100644 --- a/model_shared.c +++ b/model_shared.c @@ -641,7 +641,7 @@ model_t *Mod_ForName(const char *name, qbool crash, qbool checkdisk, const char // FIXME: So we don't crash if a server is started early. if(!vid_opened) - Host_StartVideo(); + CL_StartVideo(); model = Mod_FindName(name, parentname); if (!model->loaded || checkdisk) diff --git a/prvm_exec.c b/prvm_exec.c index eb4217d8..fd0ff40b 100644 --- a/prvm_exec.c +++ b/prvm_exec.c @@ -715,6 +715,9 @@ extern cvar_t prvm_errordump; void PRVM_Crash(prvm_prog_t *prog) { char vabuf[1024]; + + cl.csqc_loaded = false; + if (prog == NULL) return; if (!prog->loaded) diff --git a/r_modules.c b/r_modules.c index 4c5f9308..90497714 100644 --- a/r_modules.c +++ b/r_modules.c @@ -80,7 +80,7 @@ void R_Modules_Shutdown(void) void R_Modules_Restart_f(cmd_state_t *cmd) { - Host_StartVideo(); + CL_StartVideo(); Con_Print("restarting renderer\n"); R_Modules_Shutdown(); R_Modules_Start(); diff --git a/sv_main.c b/sv_main.c index a5fc047f..5b5b22ce 100644 --- a/sv_main.c +++ b/sv_main.c @@ -456,6 +456,56 @@ static qbool SV_CanSave(void) } +static void SV_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); +} + /* =============== SV_Init @@ -655,6 +705,7 @@ void SV_Init (void) Cvar_RegisterVariable (&sv_mapformat_is_quake2); Cvar_RegisterVariable (&sv_mapformat_is_quake3); + SV_ServerOptions(); SV_InitOperatorCommands(); host.hook.SV_CanSave = SV_CanSave; diff --git a/sys.h b/sys.h index 0852662d..df7e81ae 100644 --- a/sys.h +++ b/sys.h @@ -171,6 +171,8 @@ typedef struct dllfunction_s } dllfunction_t; +qbool Sys_LoadSelf(dllhandle_t *handle); + /*! Loads a library. * \param dllnames a NULL terminated array of possible names for the DLL you want to load. * \param handle diff --git a/sys_shared.c b/sys_shared.c index 39c50682..2149dff6 100644 --- a/sys_shared.c +++ b/sys_shared.c @@ -116,6 +116,21 @@ static qbool Sys_LoadLibraryFunctions(dllhandle_t dllhandle, const dllfunction_t return false; } +qbool Sys_LoadSelf(dllhandle_t *handle) +{ + dllhandle_t dllhandle = 0; + + if (handle == NULL) + return false; +#ifdef WIN32 + dllhandle = LoadLibrary (NULL); +#else + dllhandle = dlopen (NULL, RTLD_NOW | RTLD_GLOBAL); +#endif + *handle = dllhandle; + return true; +} + qbool Sys_LoadLibrary (const char** dllnames, dllhandle_t* handle, const dllfunction_t *fcts) { #ifdef SUPPORTDLL diff --git a/vid_shared.c b/vid_shared.c index f2813ecc..df8662d5 100644 --- a/vid_shared.c +++ b/vid_shared.c @@ -1501,7 +1501,7 @@ const char *vidfallbacks[][2] = {NULL, NULL} }; -// this is only called once by Host_StartVideo and again on each FS_GameDir_f +// this is only called once by CL_StartVideo and again on each FS_GameDir_f void VID_Start(void) { int i = 0; -- 2.39.2