]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sv_save.c
protocol/dp8: Implement parting messages
[xonotic/darkplaces.git] / sv_save.c
index b32cd9c6f5574f686bf834785a1e3ccdf73ad4b8..814e2db13cdad1f34ce03671438b81c2618516fa 100644 (file)
--- a/sv_save.c
+++ b/sv_save.c
@@ -37,7 +37,7 @@ void SV_Savegame_to(prvm_prog_t *prog, const char *name)
        int             i, k, l, numbuffers, lightstyles = 64;
        char    comment[SAVEGAME_COMMENT_LENGTH+1];
        char    line[MAX_INPUTLINE];
-       qboolean isserver;
+       qbool isserver;
        char    *s;
 
        // first we have to figure out if this can be saved in 64 lightstyles
@@ -176,6 +176,30 @@ void SV_Savegame_to(prvm_prog_t *prog, const char *name)
        Con_Print("done.\n");
 }
 
+static qbool SV_CanSave(void)
+{
+       prvm_prog_t *prog = SVVM_prog;
+       if(SV_IsLocalServer() == 1)
+       {
+               // singleplayer checks
+               // FIXME: This only checks if the first player is dead?
+               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_Savegame_f
@@ -185,7 +209,6 @@ void SV_Savegame_f(cmd_state_t *cmd)
 {
        prvm_prog_t *prog = SVVM_prog;
        char    name[MAX_QPATH];
-       qboolean deadflag = false;
 
        if (!sv.active)
        {
@@ -193,25 +216,8 @@ 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)
-       {
-               // 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");
-                       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(!SV_CanSave())
+               return;
 
        if (Cmd_Argc(cmd) != 2)
        {
@@ -266,7 +272,7 @@ void SV_Loadgame_f(cmd_state_t *cmd)
 
        // stop playing demos
        if (cls.demoplayback)
-               CL_Disconnect ();
+               CL_Disconnect (false, NULL);
 
 #ifdef CONFIG_MENU
        // remove menu
@@ -428,7 +434,7 @@ void SV_Loadgame_f(cmd_state_t *cmd)
                                PRVM_MEM_IncreaseEdicts(prog);
                        ent = PRVM_EDICT_NUM(entnum);
                        memset(ent->fields.fp, 0, prog->entityfields * sizeof(prvm_vec_t));
-                       ent->priv.server->free = false;
+                       ent->free = false;
 
                        if(developer_entityparsing.integer)
                                Con_Printf("SV_Loadgame_f: loading edict %d\n", entnum);
@@ -436,7 +442,7 @@ void SV_Loadgame_f(cmd_state_t *cmd)
                        PRVM_ED_ParseEdict (prog, start, ent);
 
                        // link it into the bsp tree
-                       if (!ent->priv.server->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax)))
+                       if (!ent->free && !VectorCompare(PRVM_serveredictvector(ent, absmin), PRVM_serveredictvector(ent, absmax)))
                                SV_LinkEdict(ent);
                }
 
@@ -572,6 +578,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();
 }