mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-08 22:03:43 +00:00
feat(db): bbb_autosave table for the client's BBB autosave
The client sends SetBBBAutosave (996) with the model being built every five minutes, before an AFK kick and before quitting, and expects the server to rebuild an unfinished model later (RebuildBBBAutosaveMsg). This keeps the last one per character with the model items that were in the BBB inventory at the time. MySQL 82 / SQLite 65; parity test included. Refs #1632 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
30
dDatabase/GameDatabase/MySQL/Tables/BbbAutosave.cpp
Normal file
30
dDatabase/GameDatabase/MySQL/Tables/BbbAutosave.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "MySQLDatabase.h"
|
||||
|
||||
#include "BbbAutosaveItems.h"
|
||||
|
||||
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);
|
||||
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");
|
||||
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) VALUES (?, ?, ?, ?) "
|
||||
"ON DUPLICATE KEY UPDATE lxfml = VALUES(lxfml), source_items = VALUES(source_items), updated_at = VALUES(updated_at);",
|
||||
characterId, static_cast<const std::istream*>(&lxfml), items, info.updatedAt);
|
||||
}
|
||||
|
||||
void MySQLDatabase::DeleteBbbAutosave(const LWOOBJID characterId) {
|
||||
ExecuteDelete("DELETE FROM bbb_autosave WHERE character_id = ?;", characterId);
|
||||
}
|
||||
Reference in New Issue
Block a user