Files
DarkflameServer/dDatabase/GameDatabase/MySQL/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

36 lines
1.6 KiB
C++

#include "MySQLDatabase.h"
#include "BbbAutosaveItems.h"
std::optional<IBbbAutosave::Info> MySQLDatabase::GetBbbAutosave(const LWOOBJID 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;
IBbbAutosave::Info info;
std::unique_ptr<std::istream> blob(result->getBlob("lxfml"));
std::stringstream data;
if (blob) data << blob->rdbuf();
info.lxfml = data.str();
info.sourceItems = BbbAutosaveItems::Parse(result->getString("source_items").c_str());
info.updatedAt = result->getInt64("updated_at");
info.heldAt = result->getInt64("held_at");
return info;
}
void MySQLDatabase::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 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, info.heldAt);
}
void MySQLDatabase::DeleteBbbAutosave(const LWOOBJID 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);
}