mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-25 11:56:11 -07:00
[DeckShare] Confirm the share link's target server before opening a deck
This commit is contained in:
parent
3c68f4dc40
commit
9448014834
1 changed files with 37 additions and 18 deletions
|
|
@ -204,26 +204,45 @@ Intent *IntentUrlParser::createOpenDeckIntent(const QUrlQuery &query, PendingInt
|
||||||
|
|
||||||
RemoteClient *client = mainWindow->getRemoteClient();
|
RemoteClient *client = mainWindow->getRemoteClient();
|
||||||
|
|
||||||
// When the link would move us away from a live session, ask first — the
|
// The open deck download needs a connection to the link's server. Ask before
|
||||||
// open deck download needs the connection the user already has. Remember
|
// taking the session anywhere it isn't already, naming the host we would
|
||||||
// the link's target so a failed or cancelled chain can restore the session
|
// connect to. Remember the link's target when it moves us away from a live
|
||||||
// this chain moved away from.
|
// session so a failed or cancelled chain can restore the session it left.
|
||||||
const bool migrating =
|
const bool alreadyConnected = isConnectedTo(ctx->serverContext.hostname, ctx->serverContext.port);
|
||||||
client->getStatus() == StatusLoggedIn && !isConnectedTo(ctx->serverContext.hostname, ctx->serverContext.port);
|
if (!alreadyConnected) {
|
||||||
if (migrating) {
|
|
||||||
const QString target = QStringLiteral("%1:%2").arg(ctx->serverContext.hostname, ctx->serverContext.port);
|
const QString target = QStringLiteral("%1:%2").arg(ctx->serverContext.hostname, ctx->serverContext.port);
|
||||||
const QString current =
|
|
||||||
QStringLiteral("%1:%2").arg(client->serverName(), QString::number(client->serverPort()));
|
if (client->getStatus() == StatusLoggedIn) {
|
||||||
const QMessageBox::StandardButton answer = QMessageBox::question(
|
const QString current =
|
||||||
mainWindow, tr("Open shared deck"),
|
QStringLiteral("%1:%2").arg(client->serverName(), QString::number(client->serverPort()));
|
||||||
tr("Opening this share link connects you to %1 instead of %2.\n\nContinue?").arg(target, current),
|
const QMessageBox::StandardButton answer = QMessageBox::question(
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
mainWindow, tr("Open shared deck"),
|
||||||
if (answer != QMessageBox::Yes) {
|
tr("Opening this share link connects you to %1 instead of %2.\n\nContinue?").arg(target, current),
|
||||||
return nullptr;
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
|
||||||
|
if (answer != QMessageBox::Yes) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
chain.migrationTargetHost = ctx->serverContext.hostname;
|
||||||
|
chain.migrationTargetPort = ctx->serverContext.port;
|
||||||
|
chain.pendingRestore = true;
|
||||||
|
} else {
|
||||||
|
// Fresh connection is harmless to wander away from, but a server the
|
||||||
|
// client has never been configured for deserves a harder warning (no
|
||||||
|
// by default) so a stray link cannot silently steer the client there.
|
||||||
|
const bool knownHost = SettingsCache::instance().servers().findHostIndex(ctx->serverContext.hostname) >= 0;
|
||||||
|
const QMessageBox::StandardButton answer =
|
||||||
|
knownHost
|
||||||
|
? QMessageBox::question(mainWindow, tr("Open shared deck"),
|
||||||
|
tr("Opening this share link connects you to %1.\n\nContinue?").arg(target))
|
||||||
|
: QMessageBox::warning(mainWindow, tr("Open shared deck"),
|
||||||
|
tr("Opening this share link connects you to %1, a server you have "
|
||||||
|
"never connected to before.\n\nContinue?")
|
||||||
|
.arg(target),
|
||||||
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
|
||||||
|
if (answer != QMessageBox::Yes) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
chain.migrationTargetHost = ctx->serverContext.hostname;
|
|
||||||
chain.migrationTargetPort = ctx->serverContext.port;
|
|
||||||
chain.pendingRestore = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ContextConnectToServer *serverContext = &ctx->serverContext;
|
ContextConnectToServer *serverContext = &ctx->serverContext;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue