Cockatrice/cockatrice/src/interface/intents/intent_join_server_game.cpp
Lukas Brübach 7faa2fca13
[DeckShare] Open shared decks via links with a gated preview flow
- Serialized url-chain dispatcher in IntentUrlParser; queue-drained
  urlChainFinished(bool) drives the startup auto-connect fallback
- Open-shared-deck intent with sequential download state machine,
  15s per-item timeout, partial-success offer, livable Cancel via
  ApplicationModal dlg_login_prompt interactive fallback
- Preview dialog: download progress label, share vocab sweep,
  palette-highlight selection frame, Space/Enter keyboard toggle,
  NoFocus checkbox, double-click tile opens immediately
- Confirm-before-server-migration with one-shot restore to the
  previous server on failed/cancelled chains (statusChanged settle
  deferral), hostname-only identity comparisons
- Skip credential link when already connected; arrow-key navigation
  in FlowWidget; card glows use palette highlight
- Address code-review M1-M4 and UI/UX QA blockers 1-2
2026-09-06 16:14:55 +02:00

73 lines
2.2 KiB
C++

#include "intent_join_server_game.h"
#include "../widgets/server/game_selector.h"
#include "../widgets/tabs/tab_room.h"
#include "../widgets/tabs/tab_supervisor.h"
#include "intent_join_server_room.h"
#include <QTimer>
IntentJoinServerGame::IntentJoinServerGame(TabSupervisor *_tabSupervisor,
RemoteClient *_remoteClient,
std::unique_ptr<ContextJoinGame> _context)
: Intent(), tabSupervisor(_tabSupervisor), remoteClient(_remoteClient), context(_context.release())
{
}
bool IntentJoinServerGame::checkPrecondition() const
{
if (remoteClient->getStatus() != ClientStatus::StatusLoggedIn) {
return false;
}
// serverName() reflects the server the client was configured to connect to,
// which may differ from the actual TCP peer (e.g. when connecting through a
// proxy), so only the hostname is compared here.
if (remoteClient->serverName().compare(context->roomContext.serverContext.hostname, Qt::CaseInsensitive) != 0) {
return false;
}
if (!tabSupervisor->getRoomTabs().contains(context->roomContext.roomId)) {
return false;
}
return true;
}
void IntentJoinServerGame::onPreconditionSatisfied()
{
TabRoom *room = tabSupervisor->getRoomTabs().value(context->roomContext.roomId);
if (!tryJoinGame(room)) {
waitForGame(room);
}
}
void IntentJoinServerGame::onPreconditionNotSatisfied()
{
runDependency(new IntentJoinServerRoom(tabSupervisor, remoteClient, &context->roomContext));
}
bool IntentJoinServerGame::tryJoinGame(TabRoom *room)
{
if (!room) {
return false;
}
if (room->getGameSelector()->joinGameById(context->gameId, context->asSpectator)) {
emitFinished();
return true;
}
return false;
}
void IntentJoinServerGame::waitForGame(TabRoom *room)
{
connect(room, &TabRoom::gameListUpdated, this, [this]() {
TabRoom *updatedRoom = tabSupervisor->getRoomTabs().value(context->roomContext.roomId);
if (updatedRoom) {
tryJoinGame(updatedRoom);
}
});
QTimer::singleShot(15000, this, [this]() { emitFailed(tr("Game %1 not found in the room").arg(context->gameId)); });
}