core, citra_qt: Allow credentials update in multiplayer announce session

Allows updating the credentials of the announce session, thus allowing credentials changes to be reflected before citra restart. To avoid race conditions and web errors (you can only update the room that you created, i.e. changing credentials halfway will make it break), now you can only use the Citra Web Services settings when not hosting a public room.
This commit is contained in:
zhupengfei 2019-04-20 10:42:20 +08:00
parent d6b168d7ed
commit 4a9ea65e49
No known key found for this signature in database
GPG key ID: DD129E108BD09378
10 changed files with 65 additions and 3 deletions

View file

@ -10,10 +10,11 @@
#include "core/settings.h" #include "core/settings.h"
#include "ui_configure.h" #include "ui_configure.h"
ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry) ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, bool enable_web_config)
: QDialog(parent), registry(registry), ui(new Ui::ConfigureDialog) { : QDialog(parent), registry(registry), ui(new Ui::ConfigureDialog) {
ui->setupUi(this); ui->setupUi(this);
ui->hotkeysTab->Populate(registry); ui->hotkeysTab->Populate(registry);
ui->webTab->SetWebServiceConfigEnabled(enable_web_config);
this->PopulateSelectionList(); this->PopulateSelectionList();
connect(ui->uiTab, &ConfigureUi::languageChanged, this, &ConfigureDialog::onLanguageChanged); connect(ui->uiTab, &ConfigureUi::languageChanged, this, &ConfigureDialog::onLanguageChanged);

View file

@ -17,7 +17,8 @@ class ConfigureDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry); explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry,
bool enable_web_config = true);
~ConfigureDialog() override; ~ConfigureDialog() override;
void applyConfiguration(); void applyConfiguration();

View file

@ -118,3 +118,8 @@ void ConfigureWeb::OnLoginVerified() {
void ConfigureWeb::retranslateUi() { void ConfigureWeb::retranslateUi() {
ui->retranslateUi(this); ui->retranslateUi(this);
} }
void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) {
ui->label_disable_info->setVisible(!enabled);
ui->groupBoxWebConfig->setEnabled(enabled);
}

View file

@ -22,6 +22,7 @@ public:
void applyConfiguration(); void applyConfiguration();
void retranslateUi(); void retranslateUi();
void setConfiguration(); void setConfiguration();
void SetWebServiceConfigEnabled(bool enabled);
private: private:
void RefreshTelemetryID(); void RefreshTelemetryID();

View file

@ -118,6 +118,16 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QLabel" name="label_disable_info">
<property name="text">
<string>Web Service configuration can only be changed when a public room isn't being hosted.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">

View file

@ -1335,7 +1335,8 @@ void GMainWindow::OnCheats() {
} }
void GMainWindow::OnConfigure() { void GMainWindow::OnConfigure() {
ConfigureDialog configureDialog(this, hotkey_registry); ConfigureDialog configureDialog(this, hotkey_registry,
!multiplayer_state->IsHostingPublicRoom());
connect(&configureDialog, &ConfigureDialog::languageChanged, this, connect(&configureDialog, &ConfigureDialog::languageChanged, this,
&GMainWindow::OnLanguageChanged); &GMainWindow::OnLanguageChanged);
auto old_theme = UISettings::values.theme; auto old_theme = UISettings::values.theme;
@ -1350,6 +1351,8 @@ void GMainWindow::OnConfigure() {
UpdateUITheme(); UpdateUITheme();
if (UISettings::values.enable_discord_presence != old_discord_presence) if (UISettings::values.enable_discord_presence != old_discord_presence)
SetDiscordEnabled(UISettings::values.enable_discord_presence); SetDiscordEnabled(UISettings::values.enable_discord_presence);
if (!multiplayer_state->IsHostingPublicRoom())
multiplayer_state->UpdateCredentials();
emit UpdateThemedIcons(); emit UpdateThemedIcons();
SyncMenuUISettings(); SyncMenuUISettings();
game_list->RefreshGameDirectory(); game_list->RefreshGameDirectory();

View file

@ -278,3 +278,11 @@ void MultiplayerState::OnDirectConnectToRoom() {
} }
BringWidgetToFront(direct_connect); BringWidgetToFront(direct_connect);
} }
bool MultiplayerState::IsHostingPublicRoom() const {
return announce_multiplayer_session->IsRunning();
}
void MultiplayerState::UpdateCredentials() {
announce_multiplayer_session->UpdateCredentials();
}

View file

@ -38,6 +38,14 @@ public:
void retranslateUi(); void retranslateUi();
/**
* Whether a public room is being hosted or not.
* When this is true, Web Services configuration should be disabled.
*/
bool IsHostingPublicRoom() const;
void UpdateCredentials();
public slots: public slots:
void OnNetworkStateChanged(const Network::RoomMember::State& state); void OnNetworkStateChanged(const Network::RoomMember::State& state);
void OnNetworkError(const Network::RoomMember::Error& error); void OnNetworkError(const Network::RoomMember::Error& error);

View file

@ -146,4 +146,18 @@ AnnounceMultiplayerRoom::RoomList AnnounceMultiplayerSession::GetRoomList() {
return backend->GetRoomList(); return backend->GetRoomList();
} }
bool AnnounceMultiplayerSession::IsRunning() const {
return announce_multiplayer_thread != nullptr;
}
void AnnounceMultiplayerSession::UpdateCredentials() {
ASSERT_MSG(!IsRunning(), "Credentials can only be updated when session is not running");
#ifdef ENABLE_WEB_SERVICE
backend = std::make_unique<WebService::RoomJson>(Settings::values.web_api_url,
Settings::values.citra_username,
Settings::values.citra_token);
#endif
}
} // namespace Core } // namespace Core

View file

@ -67,6 +67,17 @@ public:
*/ */
AnnounceMultiplayerRoom::RoomList GetRoomList(); AnnounceMultiplayerRoom::RoomList GetRoomList();
/**
* Whether the announce session is still running
*/
bool IsRunning() const;
/**
* Recreates the backend, updating the credentials.
* This can only be used when the announce session is not running.
*/
void UpdateCredentials();
private: private:
Common::Event shutdown_event; Common::Event shutdown_event;
std::mutex callback_mutex; std::mutex callback_mutex;