From 0f5a25025dd174e111b345da96b733b695eeaab0 Mon Sep 17 00:00:00 2001 From: Spoike Date: Sun, 25 Jul 2010 15:06:38 +0000 Subject: [PATCH] Fixes saved games. git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3563 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/server/savegame.c | 41 ++++++++++++++++++++++++++-------------- engine/server/server.h | 4 ++-- engine/server/sv_ccmds.c | 6 +++--- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/engine/server/savegame.c b/engine/server/savegame.c index 80ce64bea..81f679452 100644 --- a/engine/server/savegame.c +++ b/engine/server/savegame.c @@ -502,7 +502,7 @@ void LoadModelsAndSounds(vfsfile_t *f) *sv.strings.sound_precache[i] = 0; } -qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers) +qboolean SV_LoadLevelCache(char *savename, char *level, char *startspot, qboolean ignoreplayers) { eval_t *eval, *e2; @@ -542,7 +542,10 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers) gametype = cache->gametype; - sprintf (name, "saves/%s", level); + if (savename) + sprintf (name, "saves/%s/%s", savename, level); + else + sprintf (name, "saves/%s", level); COM_DefaultExtension (name, ".lvc", sizeof(name)); // Con_TPrintf (STL_LOADGAMEFROM, name); @@ -743,7 +746,7 @@ qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers) return true; //yay } -void SV_SaveLevelCache(qboolean dontharmgame) +void SV_SaveLevelCache(char *savedir, qboolean dontharmgame) { int len; char *s; @@ -779,7 +782,10 @@ void SV_SaveLevelCache(qboolean dontharmgame) } - sprintf (name, "saves/%s", cache->mapname); + if (savedir) + sprintf (name, "saves/%s/%s", savedir, cache->mapname); + else + sprintf (name, "saves/%s", cache->mapname); COM_DefaultExtension (name, ".lvc", sizeof(name)); FS_CreatePath(name, FS_GAMEONLY); @@ -795,6 +801,7 @@ void SV_SaveLevelCache(qboolean dontharmgame) if (!FS_NativePath(name, FS_GAMEONLY, syspath, sizeof(syspath))) return; ge->WriteLevel(syspath); + FS_FlushFSHash(); return; } #endif @@ -875,10 +882,13 @@ void SV_SaveLevelCache(qboolean dontharmgame) VFS_PRINTF (f,"\n"); s = PR_SaveEnts(svprogfuncs, NULL, &len, 1); - VFS_PRINTF(f, "%s\n", s); + VFS_PUTS(f, s); + VFS_PUTS(f, "\n"); svprogfuncs->parms->memfree(s); VFS_CLOSE (f); + + FS_FlushFSHash(); } #ifdef NEWSAVEFORMAT @@ -927,7 +937,7 @@ void SV_Savegame_f (void) savefilename = va("saves/%s/info.fsv", savename); FS_CreatePath(savefilename, FS_GAMEONLY); - f = FS_OpenVFS(savefilename, "wt", FS_GAMEONLY); + f = FS_OpenVFS(savefilename, "wb", FS_GAMEONLY); if (!f) { Con_Printf("Couldn't open file saves/%s/info.fsv\n", savename); @@ -955,7 +965,7 @@ void SV_Savegame_f (void) Q_strncpyz(str, svs.info, sizeof(str)); Info_RemovePrefixedKeys(str, '*'); - VFS_PRINTF (f, "%s\"\n", str); + VFS_PRINTF (f, "%s\n", str); Q_strncpyz(str, localinfo, sizeof(str)); Info_RemovePrefixedKeys(str, '*'); @@ -985,23 +995,26 @@ void SV_Savegame_f (void) VFS_PRINTF (f, "set nextserver \"%s\"\n", Cvar_Get("nextserver", "", 0, "")->string); VFS_PRINTF (f, "}\n"); - SV_SaveLevelCache(true); //add the current level. Note that this can cause reentry problems. - cache = svs.levcache; //state from previous levels - just copy it all accross. VFS_PRINTF(f, "{\n"); while(cache) { VFS_PRINTF(f, "%s\n", cache->mapname); - - FS_Copy(va("saves/%s.lvc", cache->mapname), va("saves/%s/%s.lvc", savename, cache->mapname), FS_GAME, FS_GAME); - + if (strcmp(cache->mapname, sv.name)) + { + FS_Copy(va("saves/%s.lvc", cache->mapname), va("saves/%s/%s.lvc", savename, cache->mapname), FS_GAME, FS_GAME); + } cache = cache->next; } VFS_PRINTF(f, "}\n"); + SV_SaveLevelCache(savename, true); //add the current level. + VFS_PRINTF (f, "%s\n", sv.name); VFS_CLOSE(f); + + FS_FlushFSHash(); } void SV_Loadgame_f (void) @@ -1025,7 +1038,7 @@ void SV_Loadgame_f (void) strcpy(savename, "quicksav"); sprintf (filename, "saves/%s/info.fsv", savename); - f = FS_OpenVFS (filename, "rt", FS_GAME); + f = FS_OpenVFS (filename, "rb", FS_GAME); if (!f) { Con_TPrintf (STL_ERRORCOULDNTOPEN); @@ -1189,7 +1202,7 @@ void SV_Loadgame_f (void) VFS_CLOSE(f); - SV_LoadLevelCache(str, "", true); + SV_LoadLevelCache(savename, str, "", true); sv.allocated_client_slots = slots; } #endif diff --git a/engine/server/server.h b/engine/server/server.h index 13960d3d9..48100577d 100644 --- a/engine/server/server.h +++ b/engine/server/server.h @@ -933,8 +933,8 @@ void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg); void SV_WriteDelta (entity_state_t *from, entity_state_t *to, sizebuf_t *msg, qboolean force, unsigned int protext); void SV_SaveSpawnparms (qboolean); -void SV_SaveLevelCache(qboolean dontharmgame); -qboolean SV_LoadLevelCache(char *level, char *startspot, qboolean ignoreplayers); +void SV_SaveLevelCache(char *savename, qboolean dontharmgame); +qboolean SV_LoadLevelCache(char *savename, char *level, char *startspot, qboolean ignoreplayers); void SV_Physics_Client (edict_t *ent, int num); diff --git a/engine/server/sv_ccmds.c b/engine/server/sv_ccmds.c index e86696bc1..014e503c1 100644 --- a/engine/server/sv_ccmds.c +++ b/engine/server/sv_ccmds.c @@ -560,7 +560,7 @@ void SV_Map_f (void) savedinuse[i] = svs.clients[i].q2edict->inuse; svs.clients[i].q2edict->inuse = false; } - SV_SaveLevelCache(false); + SV_SaveLevelCache(NULL, false); for (i=0 ; iinuse = savedinuse[i]; @@ -568,7 +568,7 @@ void SV_Map_f (void) } else #endif - SV_SaveLevelCache(false); + SV_SaveLevelCache(NULL, false); } #ifdef Q3SERVER @@ -603,7 +603,7 @@ void SV_Map_f (void) SV_BroadcastCommand ("changing \"%s\"\n", level); SV_SendMessagesToAll (); - if (newunit || !startspot || !SV_LoadLevelCache(level, startspot, false)) + if (newunit || !startspot || !SV_LoadLevelCache(NULL, level, startspot, false)) { if (waschangelevel && !startspot) startspot = "";