mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Merge pull request #4749 from zhaowenlan1779/webfix
web_service: Misc fixes
This commit is contained in:
		
						commit
						e0a0bca13a
					
				
					 23 changed files with 220 additions and 63 deletions
				
			
		|  | @ -10,10 +10,11 @@ | |||
| #include "core/settings.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) { | ||||
|     ui->setupUi(this); | ||||
|     ui->hotkeysTab->Populate(registry); | ||||
|     ui->webTab->SetWebServiceConfigEnabled(enable_web_config); | ||||
| 
 | ||||
|     this->PopulateSelectionList(); | ||||
|     connect(ui->uiTab, &ConfigureUi::languageChanged, this, &ConfigureDialog::onLanguageChanged); | ||||
|  |  | |||
|  | @ -17,7 +17,8 @@ class ConfigureDialog : public QDialog { | |||
|     Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|     explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry); | ||||
|     explicit ConfigureDialog(QWidget* parent, HotkeyRegistry& registry, | ||||
|                              bool enable_web_config = true); | ||||
|     ~ConfigureDialog() override; | ||||
| 
 | ||||
|     void applyConfiguration(); | ||||
|  |  | |||
|  | @ -118,3 +118,8 @@ void ConfigureWeb::OnLoginVerified() { | |||
| void ConfigureWeb::retranslateUi() { | ||||
|     ui->retranslateUi(this); | ||||
| } | ||||
| 
 | ||||
| void ConfigureWeb::SetWebServiceConfigEnabled(bool enabled) { | ||||
|     ui->label_disable_info->setVisible(!enabled); | ||||
|     ui->groupBoxWebConfig->setEnabled(enabled); | ||||
| } | ||||
|  |  | |||
|  | @ -22,6 +22,7 @@ public: | |||
|     void applyConfiguration(); | ||||
|     void retranslateUi(); | ||||
|     void setConfiguration(); | ||||
|     void SetWebServiceConfigEnabled(bool enabled); | ||||
| 
 | ||||
| private: | ||||
|     void RefreshTelemetryID(); | ||||
|  |  | |||
|  | @ -118,6 +118,16 @@ | |||
|        </layout> | ||||
|       </widget> | ||||
|      </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> | ||||
|       <widget class="QGroupBox" name="groupBox"> | ||||
|        <property name="title"> | ||||
|  |  | |||
|  | @ -421,6 +421,8 @@ void GameList::DonePopulating(QStringList watch_list) { | |||
|     if (childrenTotal > 0) { | ||||
|         search_field->setFocus(); | ||||
|     } | ||||
| 
 | ||||
|     emit PopulatingCompleted(); | ||||
| } | ||||
| 
 | ||||
| void GameList::PopupContextMenu(const QPoint& menu_location) { | ||||
|  |  | |||
|  | @ -76,6 +76,7 @@ signals: | |||
|     void OpenDirectory(QString directory); | ||||
|     void AddDirectory(); | ||||
|     void ShowList(bool show); | ||||
|     void PopulatingCompleted(); | ||||
| 
 | ||||
| private slots: | ||||
|     void onItemExpanded(const QModelIndex& item); | ||||
|  |  | |||
|  | @ -506,6 +506,8 @@ void GMainWindow::ConnectWidgetEvents() { | |||
|     connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, | ||||
|             &GMainWindow::OnGameListAddDirectory); | ||||
|     connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); | ||||
|     connect(game_list, &GameList::PopulatingCompleted, | ||||
|             [this] { multiplayer_state->UpdateGameList(game_list->GetModel()); }); | ||||
| 
 | ||||
|     connect(this, &GMainWindow::EmulationStarting, render_window, | ||||
|             &GRenderWindow::OnEmulationStarting); | ||||
|  | @ -1335,7 +1337,8 @@ void GMainWindow::OnCheats() { | |||
| } | ||||
| 
 | ||||
| void GMainWindow::OnConfigure() { | ||||
|     ConfigureDialog configureDialog(this, hotkey_registry); | ||||
|     ConfigureDialog configureDialog(this, hotkey_registry, | ||||
|                                     !multiplayer_state->IsHostingPublicRoom()); | ||||
|     connect(&configureDialog, &ConfigureDialog::languageChanged, this, | ||||
|             &GMainWindow::OnLanguageChanged); | ||||
|     auto old_theme = UISettings::values.theme; | ||||
|  | @ -1350,6 +1353,8 @@ void GMainWindow::OnConfigure() { | |||
|             UpdateUITheme(); | ||||
|         if (UISettings::values.enable_discord_presence != old_discord_presence) | ||||
|             SetDiscordEnabled(UISettings::values.enable_discord_presence); | ||||
|         if (!multiplayer_state->IsHostingPublicRoom()) | ||||
|             multiplayer_state->UpdateCredentials(); | ||||
|         emit UpdateThemedIcons(); | ||||
|         SyncMenuUISettings(); | ||||
|         game_list->RefreshGameDirectory(); | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include <QImage> | ||||
| #include <QList> | ||||
| #include <QLocale> | ||||
| #include <QMessageBox> | ||||
| #include <QMetaType> | ||||
| #include <QTime> | ||||
| #include <QtConcurrent/QtConcurrentRun> | ||||
|  | @ -40,13 +41,7 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, | |||
| 
 | ||||
|     // Create a proxy to the game list to display the list of preferred games
 | ||||
|     game_list = new QStandardItemModel; | ||||
| 
 | ||||
|     for (int i = 0; i < list->rowCount(); i++) { | ||||
|         auto parent = list->item(i, 0); | ||||
|         for (int j = 0; j < parent->rowCount(); j++) { | ||||
|             game_list->appendRow(parent->child(j)->clone()); | ||||
|         } | ||||
|     } | ||||
|     UpdateGameList(list); | ||||
| 
 | ||||
|     proxy = new ComboBoxProxyModel; | ||||
|     proxy->setSourceModel(game_list); | ||||
|  | @ -78,6 +73,16 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list, | |||
| 
 | ||||
| HostRoomWindow::~HostRoomWindow() = default; | ||||
| 
 | ||||
| void HostRoomWindow::UpdateGameList(QStandardItemModel* list) { | ||||
|     game_list->clear(); | ||||
|     for (int i = 0; i < list->rowCount(); i++) { | ||||
|         auto parent = list->item(i, 0); | ||||
|         for (int j = 0; j < parent->rowCount(); j++) { | ||||
|             game_list->appendRow(parent->child(j)->clone()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void HostRoomWindow::RetranslateUi() { | ||||
|     ui->retranslateUi(this); | ||||
| } | ||||
|  | @ -110,6 +115,10 @@ void HostRoomWindow::Host() { | |||
|         NetworkMessage::ShowError(NetworkMessage::PORT_NOT_VALID); | ||||
|         return; | ||||
|     } | ||||
|     if (ui->game_list->currentIndex() == -1) { | ||||
|         NetworkMessage::ShowError(NetworkMessage::GAME_NOT_SELECTED); | ||||
|         return; | ||||
|     } | ||||
|     if (auto member = Network::GetRoomMember().lock()) { | ||||
|         if (member->GetState() == Network::RoomMember::State::Joining) { | ||||
|             return; | ||||
|  | @ -148,7 +157,22 @@ void HostRoomWindow::Host() { | |||
|         if (is_public) { | ||||
|             if (auto session = announce_multiplayer_session.lock()) { | ||||
|                 // Register the room first to ensure verify_UID is present when we connect
 | ||||
|                 session->Register(); | ||||
|                 Common::WebResult result = session->Register(); | ||||
|                 if (result.result_code != Common::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 Citra 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), | ||||
|                         QMessageBox::Ok); | ||||
|                     ui->host->setEnabled(true); | ||||
|                     if (auto room = Network::GetRoom().lock()) { | ||||
|                         room->Destroy(); | ||||
|                     } | ||||
|                     return; | ||||
|                 } | ||||
|                 session->Start(); | ||||
|             } else { | ||||
|                 LOG_ERROR(Network, "Starting announce session failed"); | ||||
|  |  | |||
|  | @ -38,6 +38,11 @@ public: | |||
|                             std::shared_ptr<Core::AnnounceMultiplayerSession> session); | ||||
|     ~HostRoomWindow(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Updates the dialog with a new game list model. | ||||
|      * This model should be the original model of the game list. | ||||
|      */ | ||||
|     void UpdateGameList(QStandardItemModel* list); | ||||
|     void RetranslateUi(); | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -35,13 +35,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | |||
| 
 | ||||
|     // Create a proxy to the game list to get the list of games owned
 | ||||
|     game_list = new QStandardItemModel; | ||||
| 
 | ||||
|     for (int i = 0; i < list->rowCount(); i++) { | ||||
|         auto parent = list->item(i, 0); | ||||
|         for (int j = 0; j < parent->rowCount(); j++) { | ||||
|             game_list->appendRow(parent->child(j)->clone()); | ||||
|         } | ||||
|     } | ||||
|     UpdateGameList(list); | ||||
| 
 | ||||
|     proxy = new LobbyFilterProxyModel(this, game_list); | ||||
|     proxy->setSourceModel(model); | ||||
|  | @ -88,6 +82,18 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | |||
|     RefreshLobby(); | ||||
| } | ||||
| 
 | ||||
| void Lobby::UpdateGameList(QStandardItemModel* list) { | ||||
|     game_list->clear(); | ||||
|     for (int i = 0; i < list->rowCount(); i++) { | ||||
|         auto parent = list->item(i, 0); | ||||
|         for (int j = 0; j < parent->rowCount(); j++) { | ||||
|             game_list->appendRow(parent->child(j)->clone()); | ||||
|         } | ||||
|     } | ||||
|     if (proxy) | ||||
|         proxy->UpdateGameList(game_list); | ||||
| } | ||||
| 
 | ||||
| void Lobby::RetranslateUi() { | ||||
|     ui->retranslateUi(this); | ||||
| } | ||||
|  | @ -260,6 +266,10 @@ void Lobby::OnRefreshLobby() { | |||
| LobbyFilterProxyModel::LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list) | ||||
|     : QSortFilterProxyModel(parent), game_list(list) {} | ||||
| 
 | ||||
| void LobbyFilterProxyModel::UpdateGameList(QStandardItemModel* list) { | ||||
|     game_list = list; | ||||
| } | ||||
| 
 | ||||
| bool LobbyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { | ||||
|     // Prioritize filters by fastest to compute
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -30,6 +30,11 @@ public: | |||
|                    std::shared_ptr<Core::AnnounceMultiplayerSession> session); | ||||
|     ~Lobby() = default; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Updates the lobby with a new game list model. | ||||
|      * This model should be the original model of the game list. | ||||
|      */ | ||||
|     void UpdateGameList(QStandardItemModel* list); | ||||
|     void RetranslateUi(); | ||||
| 
 | ||||
| public slots: | ||||
|  | @ -76,9 +81,9 @@ private: | |||
|      */ | ||||
|     QString PasswordPrompt(); | ||||
| 
 | ||||
|     QStandardItemModel* model; | ||||
|     QStandardItemModel* game_list; | ||||
|     LobbyFilterProxyModel* proxy; | ||||
|     QStandardItemModel* model{}; | ||||
|     QStandardItemModel* game_list{}; | ||||
|     LobbyFilterProxyModel* proxy{}; | ||||
| 
 | ||||
|     QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; | ||||
|     std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; | ||||
|  | @ -95,6 +100,13 @@ class LobbyFilterProxyModel : public QSortFilterProxyModel { | |||
| 
 | ||||
| public: | ||||
|     explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Updates the filter with a new game list model. | ||||
|      * This model should be the processed one created by the Lobby. | ||||
|      */ | ||||
|     void UpdateGameList(QStandardItemModel* list); | ||||
| 
 | ||||
|     bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override; | ||||
|     void sort(int column, Qt::SortOrder order) override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,6 +16,9 @@ const ConnectionError USERNAME_NOT_VALID_SERVER( | |||
|     QT_TR_NOOP("Username is already in use or not valid. Please choose another.")); | ||||
| const ConnectionError IP_ADDRESS_NOT_VALID(QT_TR_NOOP("IP is not a valid IPv4 address.")); | ||||
| const ConnectionError PORT_NOT_VALID(QT_TR_NOOP("Port must be a number between 0 to 65535.")); | ||||
| const ConnectionError GAME_NOT_SELECTED(QT_TR_NOOP( | ||||
|     "You must choose a Preferred Game to host a room. If you do not have any games in your game " | ||||
|     "list yet, add a game folder by clicking on the plus icon in the game list.")); | ||||
| const ConnectionError NO_INTERNET( | ||||
|     QT_TR_NOOP("Unable to find an internet connection. Check your internet settings.")); | ||||
| const ConnectionError UNABLE_TO_CONNECT( | ||||
|  |  | |||
|  | @ -27,6 +27,7 @@ extern const ConnectionError ROOMNAME_NOT_VALID; | |||
| extern const ConnectionError USERNAME_NOT_VALID_SERVER; | ||||
| extern const ConnectionError IP_ADDRESS_NOT_VALID; | ||||
| extern const ConnectionError PORT_NOT_VALID; | ||||
| extern const ConnectionError GAME_NOT_SELECTED; | ||||
| extern const ConnectionError NO_INTERNET; | ||||
| extern const ConnectionError UNABLE_TO_CONNECT; | ||||
| extern const ConnectionError ROOM_IS_FULL; | ||||
|  |  | |||
|  | @ -174,14 +174,11 @@ void MultiplayerState::OnNetworkError(const Network::RoomMember::Error& error) { | |||
| 
 | ||||
| void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) { | ||||
|     announce_multiplayer_session->Stop(); | ||||
|     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 Citra account configured in Emulation -> Configure -> Web. If you do " | ||||
|            "not want to publish a room in the public lobby, then select Unlisted instead.\n" | ||||
|            "Debug Message: ") + | ||||
|             QString::fromStdString(result.result_string), | ||||
|         QMessageBox::Ok); | ||||
|     QMessageBox::warning(this, tr("Error"), | ||||
|                          tr("Failed to update the room information. Please check your Internet " | ||||
|                             "connection and try hosting the room again.\nDebug Message: ") + | ||||
|                              QString::fromStdString(result.result_string), | ||||
|                          QMessageBox::Ok); | ||||
| } | ||||
| 
 | ||||
| void MultiplayerState::UpdateThemedIcons() { | ||||
|  | @ -281,3 +278,21 @@ void MultiplayerState::OnDirectConnectToRoom() { | |||
|     } | ||||
|     BringWidgetToFront(direct_connect); | ||||
| } | ||||
| 
 | ||||
| bool MultiplayerState::IsHostingPublicRoom() const { | ||||
|     return announce_multiplayer_session->IsRunning(); | ||||
| } | ||||
| 
 | ||||
| void MultiplayerState::UpdateCredentials() { | ||||
|     announce_multiplayer_session->UpdateCredentials(); | ||||
| } | ||||
| 
 | ||||
| void MultiplayerState::UpdateGameList(QStandardItemModel* game_list) { | ||||
|     game_list_model = game_list; | ||||
|     if (lobby) { | ||||
|         lobby->UpdateGameList(game_list); | ||||
|     } | ||||
|     if (host_room) { | ||||
|         host_room->UpdateGameList(game_list); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -38,6 +38,20 @@ public: | |||
| 
 | ||||
|     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(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Updates the multiplayer dialogs with a new game list model. | ||||
|      * This model should be the original model of the game list. | ||||
|      */ | ||||
|     void UpdateGameList(QStandardItemModel* game_list); | ||||
| 
 | ||||
| public slots: | ||||
|     void OnNetworkStateChanged(const Network::RoomMember::State& state); | ||||
|     void OnNetworkError(const Network::RoomMember::Error& error); | ||||
|  |  | |||
|  | @ -83,9 +83,10 @@ public: | |||
| 
 | ||||
|     /**
 | ||||
|      * Registers the data in the announce service | ||||
|      * @result A global Guid of the room which may be used for verification | ||||
|      * @result The result of the register attempt. When the result code is Success, A global Guid of | ||||
|      * the room which may be used for verification will be in the result's returned_data. | ||||
|      */ | ||||
|     virtual std::string Register() = 0; | ||||
|     virtual Common::WebResult Register() = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Empties the stored players | ||||
|  | @ -121,8 +122,8 @@ public: | |||
|     Common::WebResult Update() override { | ||||
|         return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"}; | ||||
|     } | ||||
|     std::string Register() override { | ||||
|         return ""; | ||||
|     Common::WebResult Register() override { | ||||
|         return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"}; | ||||
|     } | ||||
|     void ClearPlayers() override {} | ||||
|     RoomList GetRoomList() override { | ||||
|  |  | |||
|  | @ -29,19 +29,23 @@ AnnounceMultiplayerSession::AnnounceMultiplayerSession() { | |||
| #endif | ||||
| } | ||||
| 
 | ||||
| void AnnounceMultiplayerSession::Register() { | ||||
| Common::WebResult AnnounceMultiplayerSession::Register() { | ||||
|     std::shared_ptr<Network::Room> room = Network::GetRoom().lock(); | ||||
|     if (!room) { | ||||
|         return; | ||||
|         return Common::WebResult{Common::WebResult::Code::LibError, "Network is not initialized"}; | ||||
|     } | ||||
|     if (room->GetState() != Network::Room::State::Open) { | ||||
|         return; | ||||
|         return Common::WebResult{Common::WebResult::Code::LibError, "Room is not open"}; | ||||
|     } | ||||
|     UpdateBackendData(room); | ||||
|     std::string result = backend->Register(); | ||||
|     Common::WebResult result = backend->Register(); | ||||
|     if (result.result_code != Common::WebResult::Code::Success) { | ||||
|         return result; | ||||
|     } | ||||
|     LOG_INFO(WebService, "Room has been registered"); | ||||
|     room->SetVerifyUID(result); | ||||
|     room->SetVerifyUID(result.returned_data); | ||||
|     registered = true; | ||||
|     return Common::WebResult{Common::WebResult::Code::Success}; | ||||
| } | ||||
| 
 | ||||
| void AnnounceMultiplayerSession::Start() { | ||||
|  | @ -95,9 +99,22 @@ void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room | |||
| } | ||||
| 
 | ||||
| void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | ||||
|     // Invokes all current bound error callbacks.
 | ||||
|     const auto ErrorCallback = [this](Common::WebResult result) { | ||||
|         std::lock_guard<std::mutex> lock(callback_mutex); | ||||
|         for (auto callback : error_callbacks) { | ||||
|             (*callback)(result); | ||||
|         } | ||||
|     }; | ||||
| 
 | ||||
|     if (!registered) { | ||||
|         Register(); | ||||
|         Common::WebResult result = Register(); | ||||
|         if (result.result_code != Common::WebResult::Code::Success) { | ||||
|             ErrorCallback(result); | ||||
|             return; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     auto update_time = std::chrono::steady_clock::now(); | ||||
|     std::future<Common::WebResult> future; | ||||
|     while (!shutdown_event.WaitUntil(update_time)) { | ||||
|  | @ -112,15 +129,15 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { | |||
|         UpdateBackendData(room); | ||||
|         Common::WebResult result = backend->Update(); | ||||
|         if (result.result_code != Common::WebResult::Code::Success) { | ||||
|             std::lock_guard lock(callback_mutex); | ||||
|             for (auto callback : error_callbacks) { | ||||
|                 (*callback)(result); | ||||
|             } | ||||
|             ErrorCallback(result); | ||||
|         } | ||||
|         if (result.result_string == "404") { | ||||
|             registered = false; | ||||
|             // Needs to register the room again
 | ||||
|             Register(); | ||||
|             Common::WebResult result = Register(); | ||||
|             if (result.result_code != Common::WebResult::Code::Success) { | ||||
|                 ErrorCallback(result); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -129,4 +146,18 @@ AnnounceMultiplayerRoom::RoomList AnnounceMultiplayerSession::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
 | ||||
|  |  | |||
|  | @ -44,8 +44,11 @@ public: | |||
|      */ | ||||
|     void UnbindErrorCallback(CallbackHandle handle); | ||||
| 
 | ||||
|     /// Registers a room to web services
 | ||||
|     void Register(); | ||||
|     /**
 | ||||
|      * Registers a room to web services | ||||
|      * @return The result of the registration attempt. | ||||
|      */ | ||||
|     Common::WebResult Register(); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Starts the announce of a room to web services | ||||
|  | @ -64,6 +67,17 @@ public: | |||
|      */ | ||||
|     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: | ||||
|     Common::Event shutdown_event; | ||||
|     std::mutex callback_mutex; | ||||
|  |  | |||
|  | @ -92,13 +92,6 @@ bool VerifyLogin(const std::string& username, const std::string& token) { | |||
| } | ||||
| 
 | ||||
| TelemetrySession::TelemetrySession() { | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url, | ||||
|                                                           Settings::values.citra_username, | ||||
|                                                           Settings::values.citra_token); | ||||
| #else | ||||
|     backend = std::make_unique<Telemetry::NullVisitor>(); | ||||
| #endif | ||||
|     // Log one-time top-level information
 | ||||
|     AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId()); | ||||
| 
 | ||||
|  | @ -192,9 +185,15 @@ TelemetrySession::~TelemetrySession() { | |||
|                                 .count()}; | ||||
|     AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time); | ||||
| 
 | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     auto backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url, | ||||
|                                                                Settings::values.citra_username, | ||||
|                                                                Settings::values.citra_token); | ||||
| #else | ||||
|     auto backend = std::make_unique<Telemetry::NullVisitor>(); | ||||
| #endif | ||||
| 
 | ||||
|     // Complete the session, submitting to web service if necessary
 | ||||
|     // This is just a placeholder to wrap up the session once the core completes and this is
 | ||||
|     // destroyed. This will be moved elsewhere once we are actually doing real I/O with the service.
 | ||||
|     field_collection.Accept(*backend); | ||||
|     if (Settings::values.enable_telemetry) | ||||
|         backend->Complete(); | ||||
|  | @ -203,6 +202,9 @@ TelemetrySession::~TelemetrySession() { | |||
| 
 | ||||
| bool TelemetrySession::SubmitTestcase() { | ||||
| #ifdef ENABLE_WEB_SERVICE | ||||
|     auto backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url, | ||||
|                                                                Settings::values.citra_username, | ||||
|                                                                Settings::values.citra_token); | ||||
|     field_collection.Accept(*backend); | ||||
|     return backend->SubmitTestcase(); | ||||
| #else | ||||
|  |  | |||
|  | @ -39,7 +39,6 @@ public: | |||
| 
 | ||||
| private: | ||||
|     Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
 | ||||
|     std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
 | ||||
| }; | ||||
| 
 | ||||
| /**
 | ||||
|  |  | |||
|  | @ -117,16 +117,16 @@ Common::WebResult RoomJson::Update() { | |||
|     return client.PostJson(fmt::format("/lobby/{}", room_id), json.dump(), false); | ||||
| } | ||||
| 
 | ||||
| std::string RoomJson::Register() { | ||||
| Common::WebResult RoomJson::Register() { | ||||
|     nlohmann::json json = room; | ||||
|     auto reply = client.PostJson("/lobby", json.dump(), false).returned_data; | ||||
|     if (reply.empty()) { | ||||
|         return ""; | ||||
|     auto result = client.PostJson("/lobby", json.dump(), false); | ||||
|     if (result.result_code != Common::WebResult::Code::Success) { | ||||
|         return result; | ||||
|     } | ||||
|     auto reply_json = nlohmann::json::parse(reply); | ||||
|     auto reply_json = nlohmann::json::parse(result.returned_data); | ||||
|     room = reply_json.get<AnnounceMultiplayerRoom::Room>(); | ||||
|     room_id = reply_json.at("id").get<std::string>(); | ||||
|     return room.verify_UID; | ||||
|     return Common::WebResult{Common::WebResult::Code::Success, "", room.verify_UID}; | ||||
| } | ||||
| 
 | ||||
| void RoomJson::ClearPlayers() { | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ public: | |||
|                    const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id, | ||||
|                    const std::string& game_name) override; | ||||
|     Common::WebResult Update() override; | ||||
|     std::string Register() override; | ||||
|     Common::WebResult Register() override; | ||||
|     void ClearPlayers() override; | ||||
|     AnnounceMultiplayerRoom::RoomList GetRoomList() override; | ||||
|     void Delete() override; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue