]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sv_save: Add new hooks to reduce client code in server savegame code.
authorcloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Sep 2020 19:19:09 +0000 (19:19 +0000)
committercloudwalk <cloudwalk@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 29 Sep 2020 19:19:09 +0000 (19:19 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12974 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
host.h
server.h
sv_main.c
sv_save.c

index 69f8e6228e51f69892a80cc42cafcec18d6d24a4..3f24ce7b359094df4cc767bb0cc0d0bd89b2ddb3 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -572,6 +572,11 @@ static void CL_EstablishConnection_Local(void)
                CL_EstablishConnection("local:1", -2);
 }
 
+static qbool CL_Intermission(void)
+{
+       return cl.intermission;
+}
+
 /*
 ==============
 CL_PrintEntities_f
@@ -3055,5 +3060,6 @@ void CL_Init (void)
                CL_Video_Init();
 
                host.hook.ConnectLocal = CL_EstablishConnection_Local;
+               host.hook.CL_Intermission = CL_Intermission;
        }
 }
diff --git a/host.h b/host.h
index 4d0ee33941153041f00cb1135a4211523219ac30..5b6f51d24950617164e963f5fd6609630513d709 100644 (file)
--- a/host.h
+++ b/host.h
@@ -29,6 +29,8 @@ typedef struct host_s
        struct
        {
                void (*ConnectLocal)(void);
+               qbool (*CL_Intermission)(void); // Quake compatibility
+               qbool (*SV_CanSave)(void); // Quake compatibility
        } hook;
 } host_t;
 
index 60c5b757291a17572f43cb80acf65f6c27e565e3..0df1b40a6d49c5bdf5f6d72dc3c14f9a806d3679 100644 (file)
--- a/server.h
+++ b/server.h
@@ -515,6 +515,8 @@ void SV_Init (void);
 double SV_Frame(double time);
 void SV_Shutdown(void);
 
+int SV_IsLocalGame(void);
+
 void SV_StartParticle (vec3_t org, vec3_t dir, int color, int count);
 void SV_StartEffect (vec3_t org, int modelindex, int startframe, int framecount, int framerate);
 void SV_StartSound (prvm_edict_t *entity, int channel, const char *sample, int volume, float attenuation, qbool reliable, float speed);
index 3bedf60926ffa592dd6edcdc50775724d634a16c..867c0bdffa4035940f5ae84886782a64953d86b2 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -432,6 +432,30 @@ static void SV_AreaStats_f(cmd_state_t *cmd)
        World_PrintAreaStats(&sv.world, "server");
 }
 
+static qbool SV_CanSave(void)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       if(SV_IsLocalGame() == 1)
+       {
+               // singleplayer checks
+               if (!(svs.clients[0].active && PRVM_serveredictfloat(svs.clients[0].edict, deadflag)))
+               {
+                       Con_Print("Can't savegame with a dead player\n");
+                       return false;
+               }
+
+               if(!host.hook.CL_Intermission || !host.hook.CL_Intermission())
+               {
+                       Con_Print("Can't save in intermission.\n");
+                       return false;
+               }
+       }
+       else
+               Con_Print(CON_WARN "Warning: saving a multiplayer game may have strange results when restored (to properly resume, all players must join in the same player slots and then the game can be reloaded).\n");
+       return true;
+       
+}
+
 /*
 ===============
 SV_Init
@@ -632,6 +656,7 @@ void SV_Init (void)
        Cvar_RegisterVariable (&sv_mapformat_is_quake3);
 
        SV_InitOperatorCommands();
+       host.hook.SV_CanSave = SV_CanSave;
 
        sv_mempool = Mem_AllocPool("server", 0, NULL);
 }
@@ -1989,6 +2014,17 @@ void SV_SpawnServer (const char *map)
 //     SV_UnlockThreadMutex();
 }
 
+/*
+ * Returns number of slots if we're a listen server.
+ * Returns 0 if we're a dedicated server.
+ */
+int SV_IsLocalGame(void)
+{
+       if (sv.active && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) == LHNETADDRESSTYPE_LOOP)
+               return svs.maxclients;
+       return 0;
+}
+
 /*
 ==================
 SV_Shutdown
index 3c7940b8afae637524e3dfb2287eaac1fbe4a69f..a08e33a58b37cd965bf5ce62867ddd4f205d90bf 100644 (file)
--- a/sv_save.c
+++ b/sv_save.c
@@ -185,7 +185,6 @@ void SV_Savegame_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        char    name[MAX_QPATH];
-       qbool deadflag = false;
 
        if (!sv.active)
        {
@@ -193,25 +192,11 @@ void SV_Savegame_f(cmd_state_t *cmd)
                return;
        }
 
-       deadflag = cl.islocalgame && svs.clients[0].active && PRVM_serveredictfloat(svs.clients[0].edict, deadflag);
-
-       if (cl.islocalgame)
+       if(host.hook.SV_CanSave)
        {
-               // singleplayer checks
-               if (cl.intermission)
-               {
-                       Con_Print("Can't save in intermission.\n");
-                       return;
-               }
-
-               if (deadflag)
-               {
-                       Con_Print("Can't savegame with a dead player\n");
+               if(!host.hook.SV_CanSave())
                        return;
-               }
        }
-       else
-               Con_Print(CON_WARN "Warning: saving a multiplayer game may have strange results when restored (to properly resume, all players must join in the same player slots and then the game can be reloaded).\n");
 
        if (Cmd_Argc(cmd) != 2)
        {