]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
server: Eliminate references to cls.state in server code
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 26 Sep 2020 04:59:56 +0000 (04:59 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 26 Sep 2020 04:59:56 +0000 (04:59 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12940 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
host.c
prvm_cmds.c
quakedef.h
server.h
sv_ccmds.c
sv_main.c
sv_save.c
sv_send.c
sv_user.c

index f877c4061e883e43464cb796d97e479d8aad4b0a..3a84e2ddfc7003f53c5e512ba3146c919c347b7b 100644 (file)
--- 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 54d91ac6062a5048dedf3deac811519fe9491611..4b192c5261f718bbb4b4475033ec979eaa7c9dd1 100644 (file)
--- 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);
index 000ab1ff573b351dc2c9228fca40d4506630e80d..4782261c86e4049239770e98f218cb37213a160e 100644 (file)
@@ -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 ");
index b0211c575809db3a498ad42b0361ad998d33690a..77a171fcb0a9ccc285ceb242fc785efe1c9cd994 100644 (file)
@@ -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);
index 52592b4bac37902545e235123290bce39b842c56..0d0346064cccd61e1bd9bd0cee774059d05ae67a 100644 (file)
--- 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);
index 27847ffb3b3948c4bc30cc4051dd4a056c7689b8..b1d2a4e79925479b351b460601d3da5cdff25c04 100644 (file)
@@ -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;
index 8aa475c94ff9e1ac5eaa6245049aa115480be4b8..3bedf60926ffa592dd6edcdc50775724d634a16c 100644 (file)
--- 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();
index f85d97f2103c559d4f261640068f26de926f952e..3c7940b8afae637524e3dfb2287eaac1fbe4a69f 100644 (file)
--- 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();
 }
index 2b5a6c346491e897d3a4ba2c4b77bd0ee3a302c6..d0205f9835dab5dd36a0f91589b24f475ce2ae87 100644 (file)
--- 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);
 }
 
index 7f14e19f8fe85242b3ddb0a6869e536f0914d6e3..16abf771dd4374f45c4721226995aa920cf12186 100644 (file)
--- 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");