Skip to content

Commit

Permalink
Changes to "fromNewerVersion" code
Browse files Browse the repository at this point in the history
Standardizes the code to run on all mods and betas, not just snapshots and debug builds
Ensures mods and betas can load their own saves
Blocks publishing saves from all non-release versions if they use features not present in the previous release (currently only GoL elements)
  • Loading branch information
jacob1 committed Nov 30, 2020
1 parent a631ef7 commit a3c2a0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define MOD_ID 0
#endif

#if defined(SNAPSHOT) || defined(DEBUG)
#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG) || MOD_ID > 0
#define FUTURE_SAVE_VERSION 96
#define FUTURE_MINOR_VERSION 0
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,10 @@ RequestStatus Client::UploadSave(SaveInfo & save)
lastError = "Cannot serialize game save";
return RequestFailure;
}
#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG)
else if (save.gameSave->fromNewerVersion)
#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG) || MOD_ID > 0
else if (save.gameSave->fromNewerVersion && save.GetPublished())
{
lastError = "Cannot upload save, incompatible with latest release version";
lastError = "Cannot publish save, incompatible with latest release version.";
return RequestFailure;
}
#endif
Expand Down
10 changes: 8 additions & 2 deletions src/client/GameSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ void GameSave::readOPS(char * data, int dataLength)
minor = bson_iterator_int(&subiter);
}
}
#if defined(SNAPSHOT) || defined(DEBUG)
#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG) || MOD_ID > 0
if (major > FUTURE_SAVE_VERSION || (major == FUTURE_SAVE_VERSION && minor > FUTURE_MINOR_VERSION))
#else
if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION))
Expand All @@ -828,7 +828,7 @@ void GameSave::readOPS(char * data, int dataLength)
String errorMessage = String::Build("Save from a newer version: Requires version ", major, ".", minor);
throw ParseException(ParseException::WrongVersion, errorMessage);
}
#if defined(SNAPSHOT) || defined(DEBUG)
#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG) || MOD_ID > 0
else if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION))
fakeNewerVersion = true;
#endif
Expand Down Expand Up @@ -2498,6 +2498,12 @@ char * GameSave::serialiseOPS(unsigned int & dataLength)
}
}

#if defined(SNAPSHOT) || defined(BETA) || defined(DEBUG) || MOD_ID > 0
// Mark save as incompatible with latest release
if (minimumMajorVersion > SAVE_VERSION || (minimumMajorVersion == SAVE_VERSION && minimumMinorVersion > MINOR_VERSION))
fromNewerVersion = true;
#endif

bson b;
b.data = NULL;
auto bson_deleter = [](bson * b) { bson_destroy(b); };
Expand Down

0 comments on commit a3c2a0d

Please sign in to comment.