fix(bbb): an autosave that can't be rebuilt is kept and not loaded again

Rebuilding a brick by brick autosave when a character loads no longer
stops the world when the save can't be read, splits into more models
than any build does, or fails to store: the save is logged and marked
held (bbb_autosave.held_at), the open models and bricks go back, and the
row stays as it is. A held autosave is not rebuilt again; the client's
next autosave replaces it. A brick by brick save that fails to store
answers with ModelGenerationFailed instead of stopping the world.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-11 06:56:49 -06:00
parent c933612e8a
commit f4241782e7
12 changed files with 109 additions and 19 deletions

View File

@@ -17,6 +17,9 @@ public:
std::string lxfml; // sd0 compressed LXFML as the client sent it std::string lxfml; // sd0 compressed LXFML as the client sent it
std::vector<LWOOBJID> sourceItems; // the models that were in the BBB inventory when it was sent std::vector<LWOOBJID> sourceItems; // the models that were in the BBB inventory when it was sent
int64_t updatedAt{}; // Unix seconds int64_t updatedAt{}; // Unix seconds
// When the server couldn't rebuild it (Unix seconds), 0 otherwise. A held autosave is kept for staff and not
// rebuilt again; the client's next autosave replaces it.
int64_t heldAt{};
}; };
virtual std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) = 0; virtual std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) = 0;
@@ -25,6 +28,9 @@ public:
virtual void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) = 0; virtual void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) = 0;
virtual void DeleteBbbAutosave(const LWOOBJID characterId) = 0; virtual void DeleteBbbAutosave(const LWOOBJID characterId) = 0;
// Marks the character's autosave as one the server couldn't rebuild, keeping its data
virtual void HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) = 0;
}; };
#endif //!__IBBBAUTOSAVE__H__ #endif //!__IBBBAUTOSAVE__H__

View File

@@ -271,6 +271,7 @@ public:
std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) override; std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) override;
void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override; void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override;
void DeleteBbbAutosave(const LWOOBJID characterId) override; void DeleteBbbAutosave(const LWOOBJID characterId) override;
void HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) override;
// IPropertyReputation // IPropertyReputation
VisitorHistory GetPropertyVisitorHistory(LWOOBJID propertyId, uint32_t accountId, uint32_t day, uint32_t days) override; VisitorHistory GetPropertyVisitorHistory(LWOOBJID propertyId, uint32_t accountId, uint32_t day, uint32_t days) override;

View File

@@ -3,7 +3,7 @@
#include "BbbAutosaveItems.h" #include "BbbAutosaveItems.h"
std::optional<IBbbAutosave::Info> MySQLDatabase::GetBbbAutosave(const LWOOBJID characterId) { std::optional<IBbbAutosave::Info> MySQLDatabase::GetBbbAutosave(const LWOOBJID characterId) {
auto result = ExecuteSelect("SELECT lxfml, source_items, updated_at FROM bbb_autosave WHERE character_id = ?;", characterId); auto result = ExecuteSelect("SELECT lxfml, source_items, updated_at, held_at FROM bbb_autosave WHERE character_id = ?;", characterId);
if (!result->next()) return std::nullopt; if (!result->next()) return std::nullopt;
IBbbAutosave::Info info; IBbbAutosave::Info info;
@@ -13,6 +13,7 @@ std::optional<IBbbAutosave::Info> MySQLDatabase::GetBbbAutosave(const LWOOBJID c
info.lxfml = data.str(); info.lxfml = data.str();
info.sourceItems = BbbAutosaveItems::Parse(result->getString("source_items").c_str()); info.sourceItems = BbbAutosaveItems::Parse(result->getString("source_items").c_str());
info.updatedAt = result->getInt64("updated_at"); info.updatedAt = result->getInt64("updated_at");
info.heldAt = result->getInt64("held_at");
return info; return info;
} }
@@ -20,11 +21,15 @@ void MySQLDatabase::SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosav
std::istringstream lxfml(info.lxfml); std::istringstream lxfml(info.lxfml);
const auto items = BbbAutosaveItems::Join(info.sourceItems); const auto items = BbbAutosaveItems::Join(info.sourceItems);
ExecuteInsert( ExecuteInsert(
"INSERT INTO bbb_autosave (character_id, lxfml, source_items, updated_at) VALUES (?, ?, ?, ?) " "INSERT INTO bbb_autosave (character_id, lxfml, source_items, updated_at, held_at) VALUES (?, ?, ?, ?, ?) "
"ON DUPLICATE KEY UPDATE lxfml = VALUES(lxfml), source_items = VALUES(source_items), updated_at = VALUES(updated_at);", "ON DUPLICATE KEY UPDATE lxfml = VALUES(lxfml), source_items = VALUES(source_items), updated_at = VALUES(updated_at), held_at = VALUES(held_at);",
characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt); characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt, info.heldAt);
} }
void MySQLDatabase::DeleteBbbAutosave(const LWOOBJID characterId) { void MySQLDatabase::DeleteBbbAutosave(const LWOOBJID characterId) {
ExecuteDelete("DELETE FROM bbb_autosave WHERE character_id = ?;", characterId); ExecuteDelete("DELETE FROM bbb_autosave WHERE character_id = ?;", characterId);
} }
void MySQLDatabase::HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) {
ExecuteUpdate("UPDATE bbb_autosave SET held_at = ? WHERE character_id = ?;", heldAt, characterId);
}

View File

@@ -255,6 +255,7 @@ public:
std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) override; std::optional<IBbbAutosave::Info> GetBbbAutosave(const LWOOBJID characterId) override;
void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override; void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override;
void DeleteBbbAutosave(const LWOOBJID characterId) override; void DeleteBbbAutosave(const LWOOBJID characterId) override;
void HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) override;
// IPropertyReputation // IPropertyReputation
VisitorHistory GetPropertyVisitorHistory(LWOOBJID propertyId, uint32_t accountId, uint32_t day, uint32_t days) override; VisitorHistory GetPropertyVisitorHistory(LWOOBJID propertyId, uint32_t accountId, uint32_t day, uint32_t days) override;

View File

@@ -3,7 +3,7 @@
#include "BbbAutosaveItems.h" #include "BbbAutosaveItems.h"
std::optional<IBbbAutosave::Info> SQLiteDatabase::GetBbbAutosave(const LWOOBJID characterId) { std::optional<IBbbAutosave::Info> SQLiteDatabase::GetBbbAutosave(const LWOOBJID characterId) {
auto [_, result] = ExecuteSelect("SELECT lxfml, source_items, updated_at FROM bbb_autosave WHERE character_id = ?;", characterId); auto [_, result] = ExecuteSelect("SELECT lxfml, source_items, updated_at, held_at FROM bbb_autosave WHERE character_id = ?;", characterId);
if (result.eof()) return std::nullopt; if (result.eof()) return std::nullopt;
IBbbAutosave::Info info; IBbbAutosave::Info info;
@@ -12,6 +12,7 @@ std::optional<IBbbAutosave::Info> SQLiteDatabase::GetBbbAutosave(const LWOOBJID
if (blob && length > 0) info.lxfml.assign(reinterpret_cast<const char*>(blob), length); if (blob && length > 0) info.lxfml.assign(reinterpret_cast<const char*>(blob), length);
info.sourceItems = BbbAutosaveItems::Parse(result.getStringField("source_items", "")); info.sourceItems = BbbAutosaveItems::Parse(result.getStringField("source_items", ""));
info.updatedAt = result.getInt64Field("updated_at"); info.updatedAt = result.getInt64Field("updated_at");
info.heldAt = result.getInt64Field("held_at");
return info; return info;
} }
@@ -19,11 +20,15 @@ void SQLiteDatabase::SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosa
std::istringstream lxfml(info.lxfml); std::istringstream lxfml(info.lxfml);
const auto items = BbbAutosaveItems::Join(info.sourceItems); const auto items = BbbAutosaveItems::Join(info.sourceItems);
ExecuteInsert( ExecuteInsert(
"INSERT INTO bbb_autosave (character_id, lxfml, source_items, updated_at) VALUES (?, ?, ?, ?) " "INSERT INTO bbb_autosave (character_id, lxfml, source_items, updated_at, held_at) VALUES (?, ?, ?, ?, ?) "
"ON CONFLICT(character_id) DO UPDATE SET lxfml = excluded.lxfml, source_items = excluded.source_items, updated_at = excluded.updated_at;", "ON CONFLICT(character_id) DO UPDATE SET lxfml = excluded.lxfml, source_items = excluded.source_items, updated_at = excluded.updated_at, held_at = excluded.held_at;",
characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt); characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt, info.heldAt);
} }
void SQLiteDatabase::DeleteBbbAutosave(const LWOOBJID characterId) { void SQLiteDatabase::DeleteBbbAutosave(const LWOOBJID characterId) {
ExecuteDelete("DELETE FROM bbb_autosave WHERE character_id = ?;", characterId); ExecuteDelete("DELETE FROM bbb_autosave WHERE character_id = ?;", characterId);
} }
void SQLiteDatabase::HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) {
ExecuteUpdate("UPDATE bbb_autosave SET held_at = ? WHERE character_id = ?;", heldAt, characterId);
}

View File

@@ -297,6 +297,10 @@ class TestSQLDatabase : public GameDatabase {
} }
void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override { m_BbbAutosaves[characterId] = info; } void SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) override { m_BbbAutosaves[characterId] = info; }
void DeleteBbbAutosave(const LWOOBJID characterId) override { m_BbbAutosaves.erase(characterId); } void DeleteBbbAutosave(const LWOOBJID characterId) override { m_BbbAutosaves.erase(characterId); }
void HoldBbbAutosave(const LWOOBJID characterId, const int64_t heldAt) override {
const auto it = m_BbbAutosaves.find(characterId);
if (it != m_BbbAutosaves.end()) it->second.heldAt = heldAt;
}
std::map<LWOOBJID, IBbbAutosave::Info> m_BbbAutosaves; std::map<LWOOBJID, IBbbAutosave::Info> m_BbbAutosaves;
// IUgcLookup // IUgcLookup

View File

@@ -98,8 +98,12 @@ namespace {
std::string sd0{}; // the model's own sd0 compressed LXFML std::string sd0{}; // the model's own sd0 compressed LXFML
}; };
// More separate models than one build is ever split into; a save that splits into more is not stored
constexpr size_t MAX_MODELS_PER_BUILD = 1000;
// Splits a build into its models and stores each as a new ugc row (is_optimized 0: the UGC server makes its mesh // Splits a build into its models and stores each as a new ugc row (is_optimized 0: the UGC server makes its mesh
// and icon). Every save makes new blueprint ids: the client caches blueprints by id. // and icon). Every save makes new blueprint ids: the client caches blueprints by id. Nothing is stored when the
// build can't be read or split; a database error is passed on.
std::vector<SavedModel> StoreModels(Entity& player, const std::string& sd0Data, const std::string& debugName) { std::vector<SavedModel> StoreModels(Entity& player, const std::string& sd0Data, const std::string& debugName) {
std::vector<SavedModel> saved; std::vector<SavedModel> saved;
auto* character = player.GetCharacter(); auto* character = player.GetCharacter();
@@ -108,7 +112,17 @@ namespace {
std::istringstream sd0Stream(sd0Data); std::istringstream sd0Stream(sd0Data);
Sd0 sd0(sd0Stream); Sd0 sd0(sd0Stream);
const auto lxfml = sd0.GetAsStringUncompressed(); const auto lxfml = sd0.GetAsStringUncompressed();
if (lxfml.empty()) return saved; if (lxfml.empty()) {
LOG("The brick by brick build %s of %llu has no LXFML that can be read", debugName.c_str(), player.GetObjectID());
return saved;
}
// Each model is placed by its bricks' boxes, from the client's brickdb (read on the first save, then kept)
const auto parts = Lxfml::Split(lxfml, NiPoint3Constant::ZERO, BrickBounds::Get(Game::assetManager));
if (parts.empty() || parts.size() > MAX_MODELS_PER_BUILD) {
LOG("The brick by brick build %s of %llu splits into %zu models, not storing it", debugName.c_str(), player.GetObjectID(), parts.size());
return saved;
}
if (Game::config && Game::config->GetValue("save_lxfmls") == "1") { if (Game::config && Game::config->GetValue("save_lxfmls") == "1") {
std::ofstream outFile("debug_lxfml_uncompressed_" + debugName + ".lxfml"); std::ofstream outFile("debug_lxfml_uncompressed_" + debugName + ".lxfml");
@@ -125,8 +139,7 @@ namespace {
// the owner keeps editing isn't made for every save (docs/UgcServer.md) // the owner keeps editing isn't made for every save (docs/UgcServer.md)
const auto debounce = Game::config ? GeneralUtils::TryParse<int64_t>(Game::config->GetValue("ugc_debounce_seconds")).value_or(120) : 120; const auto debounce = Game::config ? GeneralUtils::TryParse<int64_t>(Game::config->GetValue("ugc_debounce_seconds")).value_or(120) : 120;
const auto processAfter = UgcDebounce::ProcessAfter(std::time(nullptr), debounce); const auto processAfter = UgcDebounce::ProcessAfter(std::time(nullptr), debounce);
// Each model is placed by its bricks' boxes, from the client's brickdb (read on the first save, then kept) for (const auto& part : parts) {
for (const auto& part : Lxfml::Split(lxfml, NiPoint3Constant::ZERO, BrickBounds::Get(Game::assetManager))) {
const auto [modelId, blueprintId] = ObjectIDManager::GetNewModelIDs(); const auto [modelId, blueprintId] = ObjectIDManager::GetNewModelIDs();
Sd0 model = sd0; Sd0 model = sd0;
model.FromData(reinterpret_cast<const uint8_t*>(part.lxfml.data()), part.lxfml.size()); model.FromData(reinterpret_cast<const uint8_t*>(part.lxfml.data()), part.lxfml.size());
@@ -197,7 +210,8 @@ BrickByBrick::ModelRemoval BrickByBrick::PlanModelRemoval(const int32_t reason)
BrickByBrick::Recovery BrickByBrick::PlanRecovery(const std::vector<LWOOBJID>& modelsInBbb, const std::optional<IBbbAutosave::Info>& autosave) { BrickByBrick::Recovery BrickByBrick::PlanRecovery(const std::vector<LWOOBJID>& modelsInBbb, const std::optional<IBbbAutosave::Info>& autosave) {
Recovery recovery; Recovery recovery;
recovery.rebuild = autosave.has_value() && !IsEmptyModel(autosave->lxfml); // A held autosave (one the server couldn't rebuild before) is kept for staff and never rebuilt again
recovery.rebuild = autosave.has_value() && autosave->heldAt == 0 && !IsEmptyModel(autosave->lxfml);
if (recovery.rebuild) recovery.consume = autosave->sourceItems; if (recovery.rebuild) recovery.consume = autosave->sourceItems;
for (const auto id : modelsInBbb) { for (const auto id : modelsInBbb) {
if (std::ranges::find(recovery.consume, id) == recovery.consume.end()) recovery.giveBack.push_back(id); if (std::ranges::find(recovery.consume, id) == recovery.consume.end()) recovery.giveBack.push_back(id);
@@ -267,7 +281,13 @@ void BrickByBrick::Save(Entity& player, const LWOOBJID localId, const std::strin
return; return;
} }
const auto models = StoreModels(player, sd0Data, std::to_string(localId)); std::vector<SavedModel> models;
try {
models = StoreModels(player, sd0Data, std::to_string(localId));
} catch (const std::exception& ex) {
LOG("Couldn't store the brick by brick model %llu of %llu: %s", localId, player.GetObjectID(), ex.what());
models.clear();
}
if (models.empty()) { if (models.empty()) {
// BBB_COULD_NOT_GENERATE_MODEL; the client keeps the build // BBB_COULD_NOT_GENERATE_MODEL; the client keeps the build
response.reasonCode = eBlueprintSaveResponseType::ModelGenerationFailed; response.reasonCode = eBlueprintSaveResponseType::ModelGenerationFailed;
@@ -406,11 +426,22 @@ uint32_t BrickByBrick::RecoverUnfinishedBuild(Entity& player) {
const auto autosave = Database::Get()->GetBbbAutosave(player.GetObjectID()); const auto autosave = Database::Get()->GetBbbAutosave(player.GetObjectID());
auto recovery = PlanRecovery(IdsIn(*inventory, eInventoryType::MODELS_IN_BBB), autosave); auto recovery = PlanRecovery(IdsIn(*inventory, eInventoryType::MODELS_IN_BBB), autosave);
const bool hadBricks = !ItemsIn(*inventory, eInventoryType::BRICKS_IN_BBB).empty(); const bool hadBricks = !ItemsIn(*inventory, eInventoryType::BRICKS_IN_BBB).empty();
if (!autosave && recovery.giveBack.empty() && !hadBricks) return 0; const bool held = autosave && autosave->heldAt != 0;
if ((!autosave || held) && recovery.giveBack.empty() && !hadBricks) return 0;
uint32_t rebuilt = 0; uint32_t rebuilt = 0;
bool hold = false;
if (recovery.rebuild) { if (recovery.rebuild) {
for (const auto& model : StoreModels(player, autosave->lxfml, "autosave_" + std::to_string(player.GetObjectID()))) { std::vector<SavedModel> models;
try {
models = StoreModels(player, autosave->lxfml, "autosave_" + std::to_string(player.GetObjectID()));
} catch (const std::exception& ex) {
LOG("Couldn't store the brick by brick autosave of %llu: %s", player.GetObjectID(), ex.what());
models.clear();
}
// An autosave that makes no model is kept as it is (held) and not tried again: the build's models go back
hold = models.empty();
for (const auto& model : models) {
inventory->ReceiveItem(LWOOBJID_EMPTY, MODEL_ITEM_LOT, 1, eLootSourceType::INVENTORY, ModelItemConfig(model.blueprintId, model.modelId), model.modelId, false, inventory->ReceiveItem(LWOOBJID_EMPTY, MODEL_ITEM_LOT, 1, eLootSourceType::INVENTORY, ModelItemConfig(model.blueprintId, model.modelId), model.modelId, false,
{ .inventory = eInventoryType::MODELS, .showFlyingLoot = false }); { .inventory = eInventoryType::MODELS, .showFlyingLoot = false });
rebuilt++; rebuilt++;
@@ -436,7 +467,12 @@ uint32_t BrickByBrick::RecoverUnfinishedBuild(Entity& player) {
} }
SettleBricks(*inventory, rebuilt > 0); SettleBricks(*inventory, rebuilt > 0);
if (autosave) Database::Get()->DeleteBbbAutosave(player.GetObjectID()); if (hold) {
LOG("Holding the brick by brick autosave of %llu: it made no model, so it is kept and not rebuilt again", player.GetObjectID());
Database::Get()->HoldBbbAutosave(player.GetObjectID(), static_cast<int64_t>(std::time(nullptr)));
} else if (autosave && !held) {
Database::Get()->DeleteBbbAutosave(player.GetObjectID());
}
LOG("Recovered the brick by brick build of %llu: %u models rebuilt, %zu models given back", player.GetObjectID(), rebuilt, recovery.giveBack.size()); LOG("Recovered the brick by brick build of %llu: %u models rebuilt, %zu models given back", player.GetObjectID(), rebuilt, recovery.giveBack.size());
if (rebuilt > 0) { if (rebuilt > 0) {

View File

@@ -163,7 +163,10 @@ could be made from the LXFML and 11 (`PlacementFailed`, no message, the build st
With nothing to keep (after a save, or an emptied model) it sends the bare sd0 header (5 bytes) to clear it. (The With nothing to keep (after a save, or an emptied model) it sends the bare sd0 header (5 bytes) to clear it. (The
client also has a `BBB_SAVE` key action, 0x55; its handler was not traced.) DLU keeps the latest one per character in `bbb_autosave`, with the client also has a `BBB_SAVE` key action, 0x55; its handler was not traced.) DLU keeps the latest one per character in `bbb_autosave`, with the
ids of the models in `MODELS_IN_BBB` at the time. ids of the models in `MODELS_IN_BBB` at the time. An autosave that makes no model when it is rebuilt (it can't be
inflated or read, splits into more than 1000 models, or storing it fails) is kept with `held_at` set and is not
rebuilt again: the models that were open go back to `MODELS` and the bricks to the backpack. The client's next autosave
replaces it.
`S->C RebuildBBBAutosaveMsg(count)` tells the client the server rebuilt `count` unfinished models from an autosave; it `S->C RebuildBBBAutosaveMsg(count)` tells the client the server rebuilt `count` unfinished models from an autosave; it
shows `BBB_AUTOSAVE_REBUILDING_SINGLE` / `_MULTIPLE` ("... tried to rebuild it for you. Any leftover bricks have been shows `BBB_AUTOSAVE_REBUILDING_SINGLE` / `_MULTIPLE` ("... tried to rebuild it for you. Any leftover bricks have been

View File

@@ -0,0 +1,3 @@
/* held_at: when the server couldn't rebuild this autosave into models (Unix seconds), 0 otherwise. A held autosave is
kept as it is and not rebuilt again; the client's next autosave replaces it. */
ALTER TABLE bbb_autosave ADD COLUMN held_at BIGINT NOT NULL DEFAULT 0;

View File

@@ -0,0 +1,2 @@
/* bbb_autosave.held_at: see the MySQL migration. */
ALTER TABLE bbb_autosave ADD COLUMN held_at BIGINT NOT NULL DEFAULT 0;

View File

@@ -1922,7 +1922,7 @@ TEST_F(ParitySeeded, BbbAutosave) {
for (int i = 0; i < 256; i++) binary += static_cast<char>(i); for (int i = 0; i < 256; i++) binary += static_cast<char>(i);
const auto describe = [](const std::optional<IBbbAutosave::Info>& info) { const auto describe = [](const std::optional<IBbbAutosave::Info>& info) {
if (!info) return json(nullptr); if (!info) return json(nullptr);
return json{ info->lxfml, info->sourceItems, info->updatedAt }; return json{ info->lxfml, info->sourceItems, info->updatedAt, info->heldAt };
}; };
EXPECT_EQ(Both("GetBbbAutosave empty", [&](GameDatabase& db) { return describe(db.GetBbbAutosave(CHAR_BOB)); }), json(nullptr)); EXPECT_EQ(Both("GetBbbAutosave empty", [&](GameDatabase& db) { return describe(db.GetBbbAutosave(CHAR_BOB)); }), json(nullptr));
Both("SetBbbAutosave", [&](GameDatabase& db) { Both("SetBbbAutosave", [&](GameDatabase& db) {
@@ -1930,6 +1930,17 @@ TEST_F(ParitySeeded, BbbAutosave) {
db.SetBbbAutosave(CHAR_BOB, { binary, { 1152921510000000002LL, 1152921510000000003LL }, 1700000001 }); db.SetBbbAutosave(CHAR_BOB, { binary, { 1152921510000000002LL, 1152921510000000003LL }, 1700000001 });
return describe(db.GetBbbAutosave(CHAR_BOB)); return describe(db.GetBbbAutosave(CHAR_BOB));
}); });
// Holding keeps the data; the next autosave replaces it and the hold
const auto heldAt = Both("HoldBbbAutosave", [&](GameDatabase& db) {
db.HoldBbbAutosave(CHAR_BOB, 1700000002);
return describe(db.GetBbbAutosave(CHAR_BOB));
});
EXPECT_EQ(heldAt[0], json(binary));
EXPECT_EQ(heldAt[3], 1700000002);
EXPECT_EQ(Both("SetBbbAutosave after a hold", [&](GameDatabase& db) {
db.SetBbbAutosave(CHAR_BOB, { "second", {}, 1700000003 });
return describe(db.GetBbbAutosave(CHAR_BOB))[3];
}), json(0));
EXPECT_EQ(Both("DeleteBbbAutosave", [&](GameDatabase& db) { EXPECT_EQ(Both("DeleteBbbAutosave", [&](GameDatabase& db) {
db.DeleteBbbAutosave(CHAR_BOB); db.DeleteBbbAutosave(CHAR_BOB);
return describe(db.GetBbbAutosave(CHAR_BOB)); return describe(db.GetBbbAutosave(CHAR_BOB));

View File

@@ -69,6 +69,14 @@ TEST_F(BrickByBrickTests, AnEmptyAutosaveRebuildsNothing) {
EXPECT_EQ(recovery.giveBack, (std::vector<LWOOBJID>{ 1 })); EXPECT_EQ(recovery.giveBack, (std::vector<LWOOBJID>{ 1 }));
} }
TEST_F(BrickByBrickTests, AHeldAutosaveIsNeverRebuilt) {
IBbbAutosave::Info autosave{ ONE_CHUNK, { 2 }, 0, 1700000000 };
const auto recovery = BrickByBrick::PlanRecovery({ 1, 2 }, autosave);
EXPECT_FALSE(recovery.rebuild);
EXPECT_TRUE(recovery.consume.empty());
EXPECT_EQ(recovery.giveBack, (std::vector<LWOOBJID>{ 1, 2 }));
}
TEST_F(BrickByBrickTests, BuildInventoriesLoadIntoTheNormalOnes) { TEST_F(BrickByBrickTests, BuildInventoriesLoadIntoTheNormalOnes) {
EXPECT_EQ(BrickByBrick::InventoryToLoadInto(eInventoryType::MODELS_IN_BBB), eInventoryType::MODELS); EXPECT_EQ(BrickByBrick::InventoryToLoadInto(eInventoryType::MODELS_IN_BBB), eInventoryType::MODELS);
EXPECT_EQ(BrickByBrick::InventoryToLoadInto(eInventoryType::BRICKS_IN_BBB), eInventoryType::BRICKS); EXPECT_EQ(BrickByBrick::InventoryToLoadInto(eInventoryType::BRICKS_IN_BBB), eInventoryType::BRICKS);
@@ -109,6 +117,11 @@ TEST_F(BrickByBrickTests, QuickSaveIsKeptUntilClearedWithTheBareHeader) {
BrickByBrick::Autosave(player, HEADER_ONLY); BrickByBrick::Autosave(player, HEADER_ONLY);
EXPECT_FALSE(Database::Get()->GetBbbAutosave(player.GetObjectID()).has_value()); EXPECT_FALSE(Database::Get()->GetBbbAutosave(player.GetObjectID()).has_value());
// A new autosave replaces a held one, and the hold with it
Database::Get()->SetBbbAutosave(player.GetObjectID(), { ONE_CHUNK, {}, 1, 1700000000 });
BrickByBrick::Autosave(player, ONE_CHUNK);
EXPECT_EQ(Database::Get()->GetBbbAutosave(player.GetObjectID())->heldAt, 0);
} }
TEST_F(BrickByBrickTests, AReturnedModelIsNeverUsedUpByTheAutosave) { TEST_F(BrickByBrickTests, AReturnedModelIsNeverUsedUpByTheAutosave) {