Files
DarkflameServer/dDatabase/GameDatabase/SQLite/Tables/BbbAutosave.cpp
Aaron Kimbrell f4241782e7 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>
2026-11-11 06:56:49 -06:00

35 lines
1.6 KiB
C++

#include "SQLiteDatabase.h"
#include "BbbAutosaveItems.h"
std::optional<IBbbAutosave::Info> SQLiteDatabase::GetBbbAutosave(const LWOOBJID 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;
IBbbAutosave::Info info;
int length{};
const auto* blob = result.getBlobField("lxfml", length);
if (blob && length > 0) info.lxfml.assign(reinterpret_cast<const char*>(blob), length);
info.sourceItems = BbbAutosaveItems::Parse(result.getStringField("source_items", ""));
info.updatedAt = result.getInt64Field("updated_at");
info.heldAt = result.getInt64Field("held_at");
return info;
}
void SQLiteDatabase::SetBbbAutosave(const LWOOBJID characterId, const IBbbAutosave::Info& info) {
std::istringstream lxfml(info.lxfml);
const auto items = BbbAutosaveItems::Join(info.sourceItems);
ExecuteInsert(
"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, held_at = excluded.held_at;",
characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt, info.heldAt);
}
void SQLiteDatabase::DeleteBbbAutosave(const LWOOBJID 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);
}