From ff393b899041fde2ad08f4efc1f99e07a855e823 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Sun, 1 Nov 2026 12:49:35 +0100 Subject: [PATCH] [Game] Connect zone dump response before sending the request (#7711) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ZoneViewZone::initializeCards() connected PendingCommand::finished only after ZoneViewZoneLogic::requestZoneDump() had already sent the command. Local games process the dump synchronously, so finished was emitted before the view connected and the library/sideboard view stayed empty. Split requestZoneDump() into prepareZoneDump() and sendZoneDump(), and connect before sending, matching the TabRoom prepare/send convention. Co-authored-by: Lukas BrĂ¼bach --- cockatrice/src/game_graphics/zones/view_zone.cpp | 6 +++++- .../libcockatrice/game/zones/view_zone_logic.cpp | 16 +++++++++------- .../libcockatrice/game/zones/view_zone_logic.h | 15 +++++++++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/cockatrice/src/game_graphics/zones/view_zone.cpp b/cockatrice/src/game_graphics/zones/view_zone.cpp index 83c13d467..be2e471d4 100644 --- a/cockatrice/src/game_graphics/zones/view_zone.cpp +++ b/cockatrice/src/game_graphics/zones/view_zone.cpp @@ -99,9 +99,13 @@ void ZoneViewZone::initializeCards(const QList &cardLis } reorganizeCards(); } else if (!qobject_cast(getLogic())->getOriginalZone()->contentsKnown()) { - PendingCommand *pend = qobject_cast(getLogic())->requestZoneDump(); + auto *viewLogic = qobject_cast(getLogic()); + PendingCommand *pend = viewLogic->prepareZoneDump(); if (pend != nullptr) { + // A local game answers synchronously, so the handler has to be connected before the + // command is sent or the response would be delivered to nobody. connect(pend, &PendingCommand::finished, this, &ZoneViewZone::zoneDumpReceived); + viewLogic->sendZoneDump(pend); } } else { const CardList &c = qobject_cast(getLogic())->getOriginalZone()->getCards(); diff --git a/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.cpp b/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.cpp index 88941f12b..db1fa32c3 100644 --- a/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.cpp +++ b/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.cpp @@ -192,12 +192,14 @@ void ZoneViewZoneLogic::setWriteableRevealZone(bool _writeableRevealZone) writeableRevealZone = _writeableRevealZone; } -PendingCommand *ZoneViewZoneLogic::requestZoneDump() +PendingCommand *ZoneViewZoneLogic::prepareZoneDump() { - PlayerActions *actions = getPlayer()->getPlayerActions(); - PendingCommand *pend = actions->prepareZoneDump(this, numberCards); - if (pend != nullptr) { - actions->sendGameCommand(pend); - } - return pend; + return getPlayer()->getPlayerActions()->prepareZoneDump(this, numberCards); +} + +void ZoneViewZoneLogic::sendZoneDump(PendingCommand *pendingCommand) +{ + if (pendingCommand != nullptr) { + getPlayer()->getPlayerActions()->sendGameCommand(pendingCommand); + } } diff --git a/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.h b/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.h index 3592db780..a29e543a3 100644 --- a/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.h +++ b/libcockatrice_game/libcockatrice/game/zones/view_zone_logic.h @@ -88,14 +88,21 @@ public: } /** - * @brief Prepares and sends the zone-dump command for this view. + * @brief Builds the zone-dump command for this view without sending it. * @return The pending command, or nullptr when there is no zone to dump. * * Keeps command construction in game/ so graphics views don't reach - * through the player into PlayerActions to set it up. The command is sent - * asynchronously, so callers connect to finished() after calling this. + * through the player into PlayerActions to set it up. The response can + * arrive synchronously (local games), so callers must connect to + * PendingCommand::finished before calling sendZoneDump(). */ - PendingCommand *requestZoneDump(); + PendingCommand *prepareZoneDump(); + + /** + * @brief Sends a command returned by prepareZoneDump(). + * @param pendingCommand The prepared command; nullptr is ignored. + */ + void sendZoneDump(PendingCommand *pendingCommand); protected: void addCardImpl(CardState *card, int x, int y) override;