From 6dacf2c152e93d478dea64033c94ca6a49e9e2b5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 14 Jun 2026 00:15:23 -0400 Subject: [PATCH] Gate BB login lock before character select --- src/ReceiveCommands.cc | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/ReceiveCommands.cc b/src/ReceiveCommands.cc index e1264e22..a2859420 100644 --- a/src/ReceiveCommands.cc +++ b/src/ReceiveCommands.cc @@ -500,6 +500,45 @@ static asio::awaitable send_auto_patches_if_needed(std::shared_ptr } } +static asio::awaitable acquire_early_bb_account_sync_lock_if_needed(std::shared_ptr c) { + if ((c->version() != Version::BB_PATCH) && (c->version() != Version::BB_V4)) { + co_return true; + } + if (c->bb_connection_phase >= 0x04) { + co_return true; + } + if (!c->login || !c->login->account) { + co_return true; + } + if (c->account_sync_lock_acquired) { + co_return true; + } + + auto lock_res = co_await AccountSync::acquire_login_lock( + c->login->account->account_id, + phosg::name_for_enum(c->version()), + c->account_sync_session_nonce); + + if (!lock_res.allowed) { + std::string message = lock_res.message.empty() + ? "$C6Account is already active\non another ship." + : lock_res.message; + c->log.info_f("Early BB login lock denied before character select: {}", message); + send_message_box(c, message); + c->channel->disconnect(); + co_return false; + } + + if (!lock_res.session_nonce.empty()) { + c->account_sync_lock_acquired = true; + c->account_sync_lock_account_id = c->login->account->account_id; + c->account_sync_session_nonce = lock_res.session_nonce; + c->log.info_f("Early BB login lock acquired before character select: nonce={}", c->account_sync_session_nonce); + } + + co_return true; +} + asio::awaitable start_login_server_procedure(std::shared_ptr c) { auto s = c->require_server_state(); @@ -1700,6 +1739,10 @@ static asio::awaitable on_93_BB(std::shared_ptr c, Channel::Messag } if (c->login->account && c->login->bb_license) { + if (!co_await acquire_early_bb_account_sync_lock_if_needed(c)) { + co_return; + } + AccountSync::notify_bb_login_start( c->login->account->account_id, c->login->bb_license->username,