Skip to content

Commit

Permalink
Merged pull request "Sync with Q2PRO: Savegames": NVIDIA#372
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Jan 30, 2024
2 parents 92f8d91 + 323401d commit 5e2c466
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
4 changes: 3 additions & 1 deletion inc/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ bool MVD_GetDemoStatus(float *progress, bool *paused, int *framenum);
#define MVD_GetDemoStatus(progress, paused, framenum) false
#endif

#if USE_CLIENT
#if USE_SAVEGAMES
char *SV_GetSaveInfo(const char *dir);
#else
#define SV_GetSaveInfo(dir) NULL
#endif

#endif // SERVER_H
5 changes: 2 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,11 @@ ELSE()
)
ENDIF()

TARGET_COMPILE_DEFINITIONS(server PRIVATE USE_SERVER=1)
TARGET_COMPILE_DEFINITIONS(server PRIVATE USE_SERVER=1 USE_SAVEGAMES=1)
target_compile_options(server PRIVATE "${WARN_MISSING_PROTOTYPES}")

IF (TARGET client)
TARGET_COMPILE_DEFINITIONS(client PRIVATE USE_CLIENT=1 USE_FIXED_LIBAL=1 USE_SDL=1)
target_compile_options(client PRIVATE "${WARN_MISSING_PROTOTYPES}")
TARGET_COMPILE_DEFINITIONS(client PRIVATE USE_CLIENT=1 USE_SAVEGAMES=1 USE_FIXED_LIBAL=1 USE_SDL=1)

IF(CONFIG_USE_CURL)
TARGET_SOURCES(client PRIVATE ${SRC_CLIENT_HTTP})
Expand Down
2 changes: 1 addition & 1 deletion src/server/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ static void PF_dprintf(const char *fmt, ...)
char msg[MAXPRINTMSG];
va_list argptr;

#if USE_CLIENT
#if USE_SAVEGAMES
// detect YQ2 game lib by unique first two messages
if (!sv.gamedetecthack)
sv.gamedetecthack = 1 + !strcmp(fmt, "Game is starting up.\n");
Expand Down
33 changes: 11 additions & 22 deletions src/server/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ cvar_t *sv_savedir = NULL;
* Savegame logic may be less "safe", but in practice, this usually works fine.
* Still, allow it as an option for cautious people. */
cvar_t *sv_force_enhanced_savegames = NULL;
static cvar_t *sv_noreload;

static int write_server_file(bool autosave)
{
Expand Down Expand Up @@ -183,7 +184,7 @@ static int remove_file(const char *dir, const char *name)
static void **list_save_dir(const char *dir, int *count)
{
return FS_ListFiles(va("%s/%s", sv_savedir->string, dir), ".ssv;.sav;.sv2",
FS_TYPE_REAL | FS_PATH_GAME, count);
FS_TYPE_REAL | FS_PATH_GAME | FS_SEARCH_RECURSIVE, count);
}

static int wipe_save_dir(const char *dir)
Expand Down Expand Up @@ -430,18 +431,15 @@ static int read_level_file(void)
return 0;
}

int SV_NoSaveGames(void)
bool SV_NoSaveGames(void)
{
if (dedicated->integer && !Cvar_VariableInteger("coop"))
return 1;

if (sv_force_enhanced_savegames->integer && !(g_features->integer & GMF_ENHANCED_SAVEGAMES))
return 1;
return true;

if (Cvar_VariableInteger("deathmatch"))
return 1;
return true;

return 0;
return false;
}

void SV_AutoSaveBegin(mapcmd_t *cmd)
Expand Down Expand Up @@ -524,6 +522,8 @@ void SV_CheckForSavegame(mapcmd_t *cmd)
{
if (SV_NoSaveGames())
return;
if (sv_noreload->integer)
return;

if (read_level_file()) {
// only warn when loading a regular savegame. autosave without level
Expand All @@ -549,9 +549,6 @@ void SV_CheckForSavegame(mapcmd_t *cmd)

void SV_CheckForEnhancedSavegames(void)
{
if (dedicated->integer)
return;

if (Cvar_VariableInteger("deathmatch"))
return;

Expand Down Expand Up @@ -585,11 +582,6 @@ static void SV_Loadgame_f(void)
return;
}

if (dedicated->integer) {
Com_Printf("Savegames are for listen servers only.\n");
return;
}

dir = Cmd_Argv(1);
if (!COM_IsPath(dir)) {
Com_Printf("Bad savedir.\n");
Expand All @@ -599,7 +591,7 @@ static void SV_Loadgame_f(void)
// make sure the server files exist
if (!FS_FileExistsEx(va("%s/%s/server.ssv", sv_savedir->string, dir), FS_TYPE_REAL | FS_PATH_GAME) ||
!FS_FileExistsEx(va("%s/%s/game.ssv", sv_savedir->string, dir), FS_TYPE_REAL | FS_PATH_GAME)) {
Com_Printf ("No such savegame: %s\n", dir);
Com_Printf("No such savegame: %s\n", dir);
return;
}

Expand Down Expand Up @@ -631,11 +623,6 @@ static void SV_Savegame_f(void)
return;
}

if (dedicated->integer) {
Com_Printf("Savegames are for listen servers only.\n");
return;
}

// don't bother saving if we can't read them back!
if (sv_force_enhanced_savegames->integer && !(g_features->integer & GMF_ENHANCED_SAVEGAMES)) {
Com_Printf("Game does not support enhanced savegames.\n");
Expand Down Expand Up @@ -700,6 +687,8 @@ static const cmdreg_t c_savegames[] = {

void SV_RegisterSavegames(void)
{
sv_noreload = Cvar_Get("sv_noreload", "0", 0);

Cmd_Register(c_savegames);
sv_savedir = Cvar_Get("sv_savedir", "save", 0);
sv_force_enhanced_savegames = Cvar_Get("sv_force_enhanced_savegames", "0", 0);
Expand Down
4 changes: 2 additions & 2 deletions src/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ typedef struct {
server_state_t state; // precache commands are only valid during load
int spawncount; // random number generated each server spawn

#if USE_CLIENT || USE_SERVER
#if USE_SAVEGAMES
int gamedetecthack;
#endif

Expand Down Expand Up @@ -774,7 +774,7 @@ void SV_AutoSaveEnd(void);
void SV_CheckForSavegame(mapcmd_t *cmd);
void SV_CheckForEnhancedSavegames(void);
void SV_RegisterSavegames(void);
int SV_NoSaveGames(void);
bool SV_NoSaveGames(void);

//============================================================

Expand Down

0 comments on commit 5e2c466

Please sign in to comment.