Add log-only account sync save hooks
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <phosg/Time.hh>
|
#include <phosg/Time.hh>
|
||||||
|
|
||||||
#include "Account.hh"
|
#include "Account.hh"
|
||||||
|
#include "AccountSync.hh"
|
||||||
|
|
||||||
std::shared_ptr<DCNTELicense> DCNTELicense::from_json(const phosg::JSON& json) {
|
std::shared_ptr<DCNTELicense> DCNTELicense::from_json(const phosg::JSON& json) {
|
||||||
auto ret = std::make_shared<DCNTELicense>();
|
auto ret = std::make_shared<DCNTELicense>();
|
||||||
@@ -400,6 +401,8 @@ void Account::save() const {
|
|||||||
phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS);
|
phosg::JSON::SerializeOption::FORMAT | phosg::JSON::SerializeOption::HEX_INTEGERS);
|
||||||
std::string filename = std::format("system/licenses/{:010}.json", this->account_id);
|
std::string filename = std::format("system/licenses/{:010}.json", this->account_id);
|
||||||
phosg::save_file(filename, json_data);
|
phosg::save_file(filename, json_data);
|
||||||
|
|
||||||
|
AccountSync::notify_account_saved(this->account_id, filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<unsigned int>(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<unsigned int>(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<unsigned int>(account_id),
|
||||||
|
bb_username.c_str(),
|
||||||
|
filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace AccountSync
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "Server.hh"
|
#include "Server.hh"
|
||||||
#include "StaticGameData.hh"
|
#include "StaticGameData.hh"
|
||||||
#include "Text.hh"
|
#include "Text.hh"
|
||||||
|
#include "AccountSync.hh"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Tools
|
// Tools
|
||||||
@@ -491,12 +492,22 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
|||||||
? Client::character_filename(dest_bb_license->username, dest_character_index)
|
? 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()));
|
: 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) {
|
if (ch.is_full_info) {
|
||||||
// Client sent 30; ch contains the verbatim save file from the client
|
// Client sent 30; ch contains the verbatim save file from the client
|
||||||
if (ch.ep3_character) {
|
if (ch.ep3_character) {
|
||||||
try {
|
try {
|
||||||
Client::save_ep3_character_file(filename, *ch.ep3_character);
|
Client::save_ep3_character_file(filename, *ch.ep3_character);
|
||||||
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
||||||
|
log_account_sync_backup_saved();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||||
}
|
}
|
||||||
@@ -505,6 +516,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
|||||||
try {
|
try {
|
||||||
Client::save_character_file(filename, a.c->system_file(), ch.character);
|
Client::save_character_file(filename, a.c->system_file(), ch.character);
|
||||||
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
send_text_message(a.c, "$C7Character data saved\n(full save file)");
|
||||||
|
log_account_sync_backup_saved();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||||
}
|
}
|
||||||
@@ -546,6 +558,7 @@ static asio::awaitable<void> server_command_bbchar_savechar(const Args& a, bool
|
|||||||
try {
|
try {
|
||||||
Client::save_character_file(filename, a.c->system_file(), bb_player);
|
Client::save_character_file(filename, a.c->system_file(), bb_player);
|
||||||
send_text_message(a.c, "$C7Character data saved\n(basic only)");
|
send_text_message(a.c, "$C7Character data saved\n(basic only)");
|
||||||
|
log_account_sync_backup_saved();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
send_text_message_fmt(a.c, "$C6Character data could\nnot be saved:\n{}", e.what());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "SendCommands.hh"
|
#include "SendCommands.hh"
|
||||||
#include "Server.hh"
|
#include "Server.hh"
|
||||||
#include "Version.hh"
|
#include "Version.hh"
|
||||||
|
#include "AccountSync.hh"
|
||||||
|
|
||||||
const uint64_t CLIENT_CONFIG_MAGIC = 0x8399AC32;
|
const uint64_t CLIENT_CONFIG_MAGIC = 0x8399AC32;
|
||||||
|
|
||||||
@@ -503,6 +504,13 @@ void Client::save_system_file() const {
|
|||||||
std::string filename = this->system_filename();
|
std::string filename = this->system_filename();
|
||||||
phosg::save_object_file(filename, *this->system_data);
|
phosg::save_object_file(filename, *this->system_data);
|
||||||
this->log.info_f("Saved system file {}", filename);
|
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
|
// Guild Card file
|
||||||
@@ -542,6 +550,13 @@ void Client::save_guild_card_file() const {
|
|||||||
std::string filename = this->guild_card_filename();
|
std::string filename = this->guild_card_filename();
|
||||||
phosg::save_object_file(filename, *this->guild_card_data);
|
phosg::save_object_file(filename, *this->guild_card_data);
|
||||||
this->log.info_f("Saved Guild Card file {}", filename);
|
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
|
// Character file
|
||||||
@@ -634,6 +649,13 @@ void Client::save_character_file() {
|
|||||||
auto filename = this->character_filename();
|
auto filename = this->character_filename();
|
||||||
this->save_character_file(filename, this->system_data, this->character_data);
|
this->save_character_file(filename, this->system_data, this->character_data);
|
||||||
this->log.info_f("Saved character file {}", filename);
|
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(
|
void Client::create_character_file(
|
||||||
@@ -834,6 +856,13 @@ void Client::save_bank_file() const {
|
|||||||
auto filename = this->bank_filename();
|
auto filename = this->bank_filename();
|
||||||
this->save_bank_file(filename, *this->bank_data);
|
this->save_bank_file(filename, *this->bank_data);
|
||||||
this->log.info_f("Saved bank file {}", filename);
|
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) {
|
void Client::change_bank(ssize_t index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user