X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=host.c;h=268c1467ee2ba715baa6e62c900da2ec411b353b;hb=e2d2b5a9942f6c2d4e963c37771e84ffa50aa862;hp=fbab532d00bf6a58f920aa6ca43aafc3befcbc8a;hpb=f13419f00e3f8335e9a25498560a433597f28f50;p=xonotic%2Fdarkplaces.git diff --git a/host.c b/host.c index fbab532d..268c1467 100644 --- a/host.c +++ b/host.c @@ -23,14 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #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); @@ -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; @@ -614,8 +560,17 @@ static void Host_Init (void) 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 +657,6 @@ static void Host_Init (void) World_Init(); SV_Init(); Host_InitLocal(); - Host_ServerOptions(); Thread_Init(); TaskQueue_Init(); @@ -717,32 +671,28 @@ 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_StartVideo(); Host_AddConfigText(cmd); // if quake.rc is missing, use default if (!FS_FileExists("quake.rc")) { - Cbuf_InsertText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n"); + Cbuf_AddText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n"); Cbuf_Execute(cmd->cbuf); } host.state = host_active; - // run stuffcmds now, deferred previously because it can crash if a server starts that early - Cbuf_AddText(cmd,"stuffcmds\n"); - Cbuf_Execute(cmd->cbuf); + CL_StartVideo(); Log_Start(); // put up the loading image so the user doesn't stare at a black screen... SCR_BeginLoadingPlaque(true); - +#ifdef CONFIG_MENU + if (cls.state != ca_dedicated) + MR_Init(); +#endif // check for special benchmark mode // COMMANDLINEOPTION: Client: -benchmark runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log) i = Sys_CheckParm("-benchmark");