From 962759ddd16628af50c4f13fb1a463c545f9b473 Mon Sep 17 00:00:00 2001 From: cloudwalk Date: Sat, 26 Sep 2020 04:59:56 +0000 Subject: [PATCH] server: Eliminate references to cls.state in server code git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12940 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_main.c | 2 ++ host.c | 3 +++ prvm_cmds.c | 2 +- quakedef.h | 1 + server.h | 2 ++ sv_ccmds.c | 18 ++++++------------ sv_main.c | 18 ++++++++++++------ sv_save.c | 4 ++-- sv_send.c | 2 +- sv_user.c | 3 +-- 10 files changed, 31 insertions(+), 24 deletions(-) diff --git a/cl_main.c b/cl_main.c index f877c406..3a84e2dd 100644 --- a/cl_main.c +++ b/cl_main.c @@ -2922,6 +2922,8 @@ void CL_Init (void) { Con_Printf("Initializing client\n"); + Cvar_SetValueQuick(&host_isclient, 1); + R_Modules_Init(); Palette_Init(); #ifdef CONFIG_MENU diff --git a/host.c b/host.c index 54d91ac6..4b192c52 100644 --- a/host.c +++ b/host.c @@ -65,6 +65,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 @@ -242,6 +244,7 @@ static void Host_InitLocal (void) 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); diff --git a/prvm_cmds.c b/prvm_cmds.c index 000ab1ff..4782261c 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -1335,7 +1335,7 @@ coredump() */ void VM_coredump(prvm_prog_t *prog) { - cmd_state_t *cmd = cls.state == ca_dedicated ? &cmd_server : &cmd_client; + cmd_state_t *cmd = !host_isclient.integer ? &cmd_server : &cmd_client; VM_SAFEPARMCOUNT(0,VM_coredump); Cbuf_AddText(cmd, "prvm_edicts "); diff --git a/quakedef.h b/quakedef.h index b0211c57..77a171fc 100644 --- a/quakedef.h +++ b/quakedef.h @@ -559,6 +559,7 @@ typedef struct host_s } host_t; extern host_t host; +extern cvar_t host_isclient; void Host_InitCommands(void); void Host_Main(void); diff --git a/server.h b/server.h index 52592b4b..0d034606 100644 --- a/server.h +++ b/server.h @@ -598,6 +598,8 @@ void VM_SV_MoveToGoal(prvm_prog_t *prog); void SV_ApplyClientMove (void); void SV_SaveSpawnparms (void); + +qbool SV_IsLocalServer(void); void SV_SpawnServer (const char *map); void SV_CheckVelocity (prvm_edict_t *ent); diff --git a/sv_ccmds.c b/sv_ccmds.c index 27847ffb..b1d2a4e7 100644 --- a/sv_ccmds.c +++ b/sv_ccmds.c @@ -416,16 +416,10 @@ static void SV_Pause_f(cmd_state_t *cmd) else print = SV_ClientPrintf; - if (!pausable.integer) + if (!pausable.integer && cmd->source == src_client && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP) { - if (cmd->source == src_client) - { - if(cls.state == ca_dedicated || host_client != &svs.clients[0]) // non-admin - { - print("Pause not allowed.\n"); - return; - } - } + print("Pause not allowed.\n"); + return; } sv.paused ^= 1; @@ -496,7 +490,7 @@ static void SV_Say(cmd_state_t *cmd, qbool teamonly) SV_ClientPrint(text); host_client = save; - if (cls.state == ca_dedicated) + if(!host_isclient.integer) Con_Print(&text[1]); } @@ -1137,7 +1131,7 @@ static void SV_Kick_f(cmd_state_t *cmd) { if (cmd->source == src_local) { - if (cls.state == ca_dedicated) + if(!host_isclient.integer) who = "Console"; else who = cl_name.string; @@ -1470,7 +1464,7 @@ static void SV_SendCvar_f(cmd_state_t *cmd) cvarname = Cmd_Argv(cmd, 1); old = host_client; - if (cls.state != ca_dedicated) + if(host_isclient.integer) i = 1; else i = 0; diff --git a/sv_main.c b/sv_main.c index 8aa475c9..3bedf609 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1669,6 +1669,13 @@ void SV_SaveSpawnparms (void) } } +qbool SV_IsLocalServer(void) +{ + if(host_isclient.integer && host_client && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) == LHNETADDRESSTYPE_LOOP) + return true; + return false; +} + /* ================ SV_SpawnServer @@ -1703,10 +1710,9 @@ void SV_SpawnServer (const char *map) // SV_LockThreadMutex(); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessNice(); - - if (cls.state != ca_dedicated) + else { SCR_BeginLoadingPlaque(false); S_StopAllSounds(); @@ -1741,7 +1747,7 @@ void SV_SpawnServer (const char *map) { Con_Printf("Couldn't load map %s\n", modelname); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessMean(); // SV_UnlockThreadMutex(); @@ -1933,7 +1939,7 @@ void SV_SpawnServer (const char *map) // Once all init frames have been run, we consider svqc code fully initialized. prog->inittime = host.realtime; - if (cls.state == ca_dedicated) + if(!host_isclient.integer) Mod_PurgeUnused(); // create a baseline for more efficient communications @@ -1977,7 +1983,7 @@ void SV_SpawnServer (const char *map) Con_Printf("Server spawned.\n"); NetConn_Heartbeat (2); - if(cls.state == ca_dedicated) + if(!host_isclient.integer) Sys_MakeProcessMean(); // SV_UnlockThreadMutex(); diff --git a/sv_save.c b/sv_save.c index f85d97f2..3c7940b8 100644 --- a/sv_save.c +++ b/sv_save.c @@ -572,6 +572,6 @@ void SV_Loadgame_f(cmd_state_t *cmd) Con_Printf("SV_Loadgame_f: finished\n"); // make sure we're connected to loopback - if (sv.active && cls.state == ca_disconnected) - CL_EstablishConnection("local:1", -2); + if(sv.active && host.hook.ConnectLocal) + host.hook.ConnectLocal(); } diff --git a/sv_send.c b/sv_send.c index 2b5a6c34..d0205f98 100644 --- a/sv_send.c +++ b/sv_send.c @@ -101,7 +101,7 @@ void SV_BroadcastPrint(const char *msg) } } - if (sv_echobprint.integer && cls.state == ca_dedicated) + if (sv_echobprint.integer && !host_isclient.integer) Con_Print(msg); } diff --git a/sv_user.c b/sv_user.c index 7f14e19f..16abf771 100644 --- a/sv_user.c +++ b/sv_user.c @@ -113,8 +113,7 @@ void SV_Spawn_f(cmd_state_t *cmd) PRVM_serverglobaledict(self) = PRVM_EDICT_TO_PROG(host_client->edict); prog->ExecuteProgram(prog, PRVM_serverfunction(ClientConnect), "QC function ClientConnect is missing"); - if (cls.state == ca_dedicated) - Con_Printf("%s connected\n", host_client->name); + Con_Printf("%s connected\n", host_client->name); PRVM_serverglobalfloat(time) = sv.time; prog->ExecuteProgram(prog, PRVM_serverfunction(PutClientInServer), "QC function PutClientInServer is missing"); -- 2.39.2