mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 18:01:39 +00:00
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>
35 lines
1.6 KiB
C++
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);
|
|
}
|