diff --git a/src/citron/configuration/configure_profile_manager.cpp b/src/citron/configuration/configure_profile_manager.cpp index 11d35f5b8..1581ee8a0 100644 --- a/src/citron/configuration/configure_profile_manager.cpp +++ b/src/citron/configuration/configure_profile_manager.cpp @@ -177,6 +177,9 @@ void ConfigureProfileManager::UpdateCurrentUser() { scene->addPixmap( GetIcon(*current_user).scaled(48, 48, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); ui->current_user_username->setText(username); + + // Set the username for the Citron profile + Settings::values.citron_username = username.toStdString(); } void ConfigureProfileManager::ApplyConfiguration() { diff --git a/src/citron/configuration/configure_web.cpp b/src/citron/configuration/configure_web.cpp index b51e993ec..1cdf0f5a9 100644 --- a/src/citron/configuration/configure_web.cpp +++ b/src/citron/configuration/configure_web.cpp @@ -5,43 +5,15 @@ #include #include #include "common/settings.h" -#include "core/telemetry_session.h" +#include "common/uuid.h" #include "ui_configure_web.h" #include "citron/configuration/configure_web.h" #include "citron/uisettings.h" -static constexpr char token_delimiter{':'}; - -static std::string GenerateDisplayToken(const std::string& username, const std::string& token) { - if (username.empty() || token.empty()) { - return {}; - } - - const std::string unencoded_display_token{username + token_delimiter + token}; - QByteArray b{unencoded_display_token.c_str()}; - QByteArray b64 = b.toBase64(); - return b64.toStdString(); -} - -static std::string UsernameFromDisplayToken(const std::string& display_token) { - const std::string unencoded_display_token{ - QByteArray::fromBase64(display_token.c_str()).toStdString()}; - return unencoded_display_token.substr(0, unencoded_display_token.find(token_delimiter)); -} - -static std::string TokenFromDisplayToken(const std::string& display_token) { - const std::string unencoded_display_token{ - QByteArray::fromBase64(display_token.c_str()).toStdString()}; - return unencoded_display_token.substr(unencoded_display_token.find(token_delimiter) + 1); -} - ConfigureWeb::ConfigureWeb(QWidget* parent) : QWidget(parent), ui(std::make_unique()) { ui->setupUi(this); - connect(ui->button_regenerate_telemetry_id, &QPushButton::clicked, this, - &ConfigureWeb::RefreshTelemetryID); - connect(ui->button_verify_login, &QPushButton::clicked, this, &ConfigureWeb::VerifyLogin); - connect(&verify_watcher, &QFutureWatcher::finished, this, &ConfigureWeb::OnLoginVerified); + connect(ui->button_reset_token, &QPushButton::clicked, this, &ConfigureWeb::ResetToken); #ifndef USE_DISCORD_PRESENCE ui->discord_group->setVisible(false); @@ -63,115 +35,51 @@ void ConfigureWeb::changeEvent(QEvent* event) { void ConfigureWeb::RetranslateUI() { ui->retranslateUi(this); - - ui->telemetry_learn_more->setText( - tr("Learn more")); - - ui->web_signup_link->setText( - tr("Sign up")); - - ui->web_token_info_link->setText( - tr("What is my token?")); - - ui->label_telemetry_id->setText( - tr("Telemetry ID: 0x%1").arg(QString::number(Core::GetTelemetryId(), 16).toUpper())); } void ConfigureWeb::SetConfiguration() { ui->web_credentials_disclaimer->setWordWrap(true); - ui->telemetry_learn_more->setOpenExternalLinks(true); - ui->web_signup_link->setOpenExternalLinks(true); - ui->web_token_info_link->setOpenExternalLinks(true); - if (Settings::values.citron_username.GetValue().empty()) { ui->username->setText(tr("Unspecified")); } else { ui->username->setText(QString::fromStdString(Settings::values.citron_username.GetValue())); } - ui->toggle_telemetry->setChecked(Settings::values.enable_telemetry.GetValue()); - ui->edit_token->setText(QString::fromStdString(GenerateDisplayToken( - Settings::values.citron_username.GetValue(), Settings::values.citron_token.GetValue()))); - - // Connect after setting the values, to avoid calling OnLoginChanged now - connect(ui->edit_token, &QLineEdit::textChanged, this, &ConfigureWeb::OnLoginChanged); - - user_verified = true; + ui->edit_token->setText(QString::fromStdString(Settings::values.citron_token.GetValue())); ui->toggle_discordrpc->setChecked(UISettings::values.enable_discord_presence.GetValue()); } void ConfigureWeb::ApplyConfiguration() { - Settings::values.enable_telemetry = ui->toggle_telemetry->isChecked(); UISettings::values.enable_discord_presence = ui->toggle_discordrpc->isChecked(); - if (user_verified) { - Settings::values.citron_username = - UsernameFromDisplayToken(ui->edit_token->text().toStdString()); - Settings::values.citron_token = TokenFromDisplayToken(ui->edit_token->text().toStdString()); + if (Settings::values.citron_username.GetValue().empty()) { + // Backup: default name should already be set by ConfigureProfileManager::UpdateCurrentUser() + Settings::values.citron_username = "torzu"; } else { - QMessageBox::warning( - this, tr("Token not verified"), - tr("Token was not verified. The change to your token has not been saved.")); + // If a name already exist, reassign it to itself (needed for change set with a profile switch) + Settings::values.citron_username = Settings::values.citron_username.GetValue(); } -} -void ConfigureWeb::RefreshTelemetryID() { - const u64 new_telemetry_id{Core::RegenerateTelemetryId()}; - ui->label_telemetry_id->setText( - tr("Telemetry ID: 0x%1").arg(QString::number(new_telemetry_id, 16).toUpper())); -} - -void ConfigureWeb::OnLoginChanged() { if (ui->edit_token->text().isEmpty()) { - user_verified = true; - // Empty = no icon - ui->label_token_verified->setPixmap(QPixmap()); - ui->label_token_verified->setToolTip(QString()); + // If no token specified, automatically generate one + Settings::values.citron_token = Common::UUID::MakeRandom().FormattedString(); } else { - user_verified = false; - - // Show an info icon if it's been changed, clearer than showing failure - const QPixmap pixmap = QIcon::fromTheme(QStringLiteral("info")).pixmap(16); - ui->label_token_verified->setPixmap(pixmap); - ui->label_token_verified->setToolTip( - tr("Unverified, please click Verify before saving configuration", "Tooltip")); + // Otherwise use user-specified value + Settings::values.citron_token = ui->edit_token->text().toStdString(); } } -void ConfigureWeb::VerifyLogin() { - ui->button_verify_login->setDisabled(true); - ui->button_verify_login->setText(tr("Verifying...")); - ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("sync")).pixmap(16)); - ui->label_token_verified->setToolTip(tr("Verifying...")); - verify_watcher.setFuture(QtConcurrent::run( - [username = UsernameFromDisplayToken(ui->edit_token->text().toStdString()), - token = TokenFromDisplayToken(ui->edit_token->text().toStdString())] { - return Core::VerifyLogin(username, token); - })); -} - -void ConfigureWeb::OnLoginVerified() { - ui->button_verify_login->setEnabled(true); - ui->button_verify_login->setText(tr("Verify")); - if (verify_watcher.result()) { - user_verified = true; - - ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("checked")).pixmap(16)); - ui->label_token_verified->setToolTip(tr("Verified", "Tooltip")); - ui->username->setText( - QString::fromStdString(UsernameFromDisplayToken(ui->edit_token->text().toStdString()))); - } else { - ui->label_token_verified->setPixmap(QIcon::fromTheme(QStringLiteral("failed")).pixmap(16)); - ui->label_token_verified->setToolTip(tr("Verification failed", "Tooltip")); - ui->username->setText(tr("Unspecified")); - QMessageBox::critical(this, tr("Verification failed"), - tr("Verification failed. Check that you have entered your token " - "correctly, and that your internet connection is working.")); - } +void ConfigureWeb::ResetToken() { + // Generate and set token + const auto token = Common::UUID::MakeRandom().FormattedString(); + Settings::values.citron_token = token; + // Just to display the label_token_icon pic and tooltip for visual confirmation + ui->label_token_icon->setPixmap(QIcon::fromTheme(QStringLiteral("checked")).pixmap(16)); + ui->label_token_icon->setToolTip(tr("Token Changed", "Tooltip")); + ui->username->setText(QString::fromStdString(token)); + // Apply the changes + SetConfiguration(); } void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) { diff --git a/src/citron/configuration/configure_web.h b/src/citron/configuration/configure_web.h index 51cc8ebf7..92a0d1efa 100644 --- a/src/citron/configuration/configure_web.h +++ b/src/citron/configuration/configure_web.h @@ -25,15 +25,9 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void RefreshTelemetryID(); - void OnLoginChanged(); - void VerifyLogin(); - void OnLoginVerified(); + void ResetToken(); void SetConfiguration(); - bool user_verified = true; - QFutureWatcher verify_watcher; - std::unique_ptr ui; }; diff --git a/src/citron/configuration/configure_web.ui b/src/citron/configuration/configure_web.ui index 906fa77ad..c506d217f 100644 --- a/src/citron/configuration/configure_web.ui +++ b/src/citron/configuration/configure_web.ui @@ -6,7 +6,7 @@ 0 0 - 926 + 2280 561 @@ -24,18 +24,18 @@ citron Web Service - + - By providing your username and token, you agree to allow citron to collect additional usage data, which may include user identifying information. + This is your Citron Web Service token. It is used to authenticate your Citron account. - + - + 0 @@ -46,12 +46,15 @@ Qt::RightToLeft - Verify + Reset Token + + false + Sign up @@ -68,7 +71,7 @@ - + @@ -82,13 +85,13 @@ 80 - - QLineEdit::Password - + + false + What is my token? @@ -122,56 +125,6 @@ - - - - Telemetry - - - - - - Share anonymous usage data with the citron team - - - - - - - Learn more - - - - - - - - - Telemetry ID: - - - - - - - - 0 - 0 - - - - Qt::RightToLeft - - - Regenerate - - - - - - - - diff --git a/src/citron/multiplayer/host_room.cpp b/src/citron/multiplayer/host_room.cpp index 2e6a9e1f4..243244e06 100644 --- a/src/citron/multiplayer/host_room.cpp +++ b/src/citron/multiplayer/host_room.cpp @@ -183,8 +183,7 @@ void HostRoomWindow::Host() { if (result.result_code != WebService::WebResult::Code::Success) { QMessageBox::warning( this, tr("Error"), - tr("Failed to announce the room to the public lobby. In order to host a " - "room publicly, you must have a valid citron account configured in " + tr("To host a room publicly, you must have a valid citron account configured in " "Emulation -> Configure -> Web. If you do not want to publish a room in " "the public lobby, then select Unlisted instead.\nDebug Message: ") + QString::fromStdString(result.result_string),