From f8d50b3ab7f7c5f9540bd917092a6ada0c6d3d57 Mon Sep 17 00:00:00 2001 From: James Osborne Date: Mon, 8 Jun 2026 03:56:50 -0400 Subject: [PATCH] Add log-only account sync save hooks --- src/Account.cc | 3 +++ src/AccountSync.hh | 38 ++++++++++++++++++++++++++++++++++++++ src/ChatCommands.cc | 13 +++++++++++++ src/Client.cc | 29 +++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 src/AccountSync.hh diff --git a/src/Account.cc b/src/Account.cc index 7df886a8..a3fc939c 100644 --- a/src/Account.cc +++ b/src/Account.cc @@ -9,6 +9,7 @@ #include #include "Account.hh" +#include "AccountSync.hh" std::shared_ptr DCNTELicense::from_json(const phosg::JSON& json) { auto ret = std::make_shared(); @@ -400,6 +401,8 @@ void Account::save() const { phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS); std::string filename = std::format("system/licenses/{:010}.json", this->account_id); phosg::save_file(filename, json_data); + + AccountSync::notify_account_saved(this->account_id, filename); } } diff --git a/src/AccountSync.hh b/src/AccountSync.hh new file mode 100644 index 00000000..3662caf5 --- /dev/null +++ b/src/AccountSync.hh @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include +#include + +namespace AccountSync { + +inline void notify_account_saved(uint32_t account_id, const std::string& filename) { + std::fprintf(stderr, + "[AccountSync] event=account_saved account_id=%010u filename=%s\n", + static_cast(account_id), + filename.c_str()); +} + +inline void notify_backup_saved(uint32_t account_id, size_t slot, const std::string& filename) { + std::fprintf(stderr, + "[AccountSync] event=backup_saved account_id=%010u slot=%zu filename=%s\n", + static_cast(account_id), + slot, + filename.c_str()); +} + +inline void notify_player_state_saved( + const char* reason, + uint32_t account_id, + const std::string& bb_username, + const std::string& filename) { + std::fprintf(stderr, + "[AccountSync] event=player_state_saved reason=%s account_id=%010u bb_username=%s filename=%s\n", + reason, + static_cast(account_id), + bb_username.c_str(), + filename.c_str()); +} + +} // namespace AccountSync diff --git a/src/ChatCommands.cc b/src/ChatCommands.cc index 2a911c20..7ca6f917 100644 --- a/src/ChatCommands.cc +++ b/src/ChatCommands.cc @@ -22,6 +22,7 @@ #include "Server.hh" #include "StaticGameData.hh" #include "Text.hh" +#include "AccountSync.hh" /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Tools @@ -491,12 +492,22 @@ static asio::awaitable server_command_bbchar_savechar(const Args& a, bool ? Client::character_filename(dest_bb_license->username, dest_character_index) : Client::backup_character_filename(dest_account->account_id, dest_character_index, is_ep3(a.c->version())); + auto log_account_sync_backup_saved = [&]() -> void { + if (!is_bb_conversion) { + AccountSync::notify_backup_saved( + dest_account->account_id, + dest_character_index, + filename); + } + }; + if (ch.is_full_info) { // Client sent 30; ch contains the verbatim save file from the client if (ch.ep3_character) { try { Client::save_ep3_character_file(filename, *ch.ep3_character); send_text_message(a.c, "$C7Character data saved\n(full save file)"); + log_account_sync_backup_saved(); } catch (const std::exception& e) { send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what()); } @@ -505,6 +516,7 @@ static asio::awaitable server_command_bbchar_savechar(const Args& a, bool try { Client::save_character_file(filename, a.c->system_file(), ch.character); send_text_message(a.c, "$C7Character data saved\n(full save file)"); + log_account_sync_backup_saved(); } catch (const std::exception& e) { send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what()); } @@ -546,6 +558,7 @@ static asio::awaitable server_command_bbchar_savechar(const Args& a, bool try { Client::save_character_file(filename, a.c->system_file(), bb_player); send_text_message(a.c, "$C7Character data saved\n(basic only)"); + log_account_sync_backup_saved(); } catch (const std::exception& e) { send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what()); } diff --git a/src/Client.cc b/src/Client.cc index a27c682c..cca299f4 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -15,6 +15,7 @@ #include "SendCommands.hh" #include "Server.hh" #include "Version.hh" +#include "AccountSync.hh" const uint64_t CLIENT_CONFIG_MAGIC = 0x8399AC32; @@ -503,6 +504,13 @@ void Client::save_system_file() const { std::string filename = this->system_filename(); phosg::save_object_file(filename, *this->system_data); this->log.info_f("Saved system file {}", filename); + if (this->login && this->login->account && this->login->bb_license) { + AccountSync::notify_player_state_saved( + "system_saved", + this->login->account->account_id, + this->login->bb_license->username, + filename); + } } // Guild Card file @@ -542,6 +550,13 @@ void Client::save_guild_card_file() const { std::string filename = this->guild_card_filename(); phosg::save_object_file(filename, *this->guild_card_data); this->log.info_f("Saved Guild Card file {}", filename); + if (this->login && this->login->account && this->login->bb_license) { + AccountSync::notify_player_state_saved( + "guild_card_saved", + this->login->account->account_id, + this->login->bb_license->username, + filename); + } } // Character file @@ -634,6 +649,13 @@ void Client::save_character_file() { auto filename = this->character_filename(); this->save_character_file(filename, this->system_data, this->character_data); this->log.info_f("Saved character file {}", filename); + if (this->login && this->login->account && this->login->bb_license) { + AccountSync::notify_player_state_saved( + "character_saved", + this->login->account->account_id, + this->login->bb_license->username, + filename); + } } void Client::create_character_file( @@ -834,6 +856,13 @@ void Client::save_bank_file() const { auto filename = this->bank_filename(); this->save_bank_file(filename, *this->bank_data); this->log.info_f("Saved bank file {}", filename); + if (this->login && this->login->account && this->login->bb_license) { + AccountSync::notify_player_state_saved( + "bank_saved", + this->login->account->account_id, + this->login->bb_license->username, + filename); + } } void Client::change_bank(ssize_t index) {