citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #4749 from zhaowenlan1779/webfix

web_service: Misc fixes
This commit is contained in:
Pengfei Zhu 2019-05-01 17:00:17 +08:00 committed by GitHub
commit e0a0bca13a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 220 additions and 63 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

@ -421,6 +421,8 @@ void GameList::DonePopulating(QStringList watch_list) {
if (childrenTotal > 0) { if (childrenTotal > 0) {
search_field->setFocus(); search_field->setFocus();
} }
emit PopulatingCompleted();
} }
void GameList::PopupContextMenu(const QPoint& menu_location) { void GameList::PopupContextMenu(const QPoint& menu_location) {

View File

@ -76,6 +76,7 @@ signals:
void OpenDirectory(QString directory); void OpenDirectory(QString directory);
void AddDirectory(); void AddDirectory();
void ShowList(bool show); void ShowList(bool show);
void PopulatingCompleted();
private slots: private slots:
void onItemExpanded(const QModelIndex& item); void onItemExpanded(const QModelIndex& item);

View File

@ -506,6 +506,8 @@ void GMainWindow::ConnectWidgetEvents() {
connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this, connect(game_list_placeholder, &GameListPlaceholder::AddDirectory, this,
&GMainWindow::OnGameListAddDirectory); &GMainWindow::OnGameListAddDirectory);
connect(game_list, &GameList::ShowList, this, &GMainWindow::OnGameListShowList); 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, connect(this, &GMainWindow::EmulationStarting, render_window,
&GRenderWindow::OnEmulationStarting); &GRenderWindow::OnEmulationStarting);
@ -1335,7 +1337,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 +1353,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

@ -7,6 +7,7 @@
#include <QImage> #include <QImage>
#include <QList> #include <QList>
#include <QLocale> #include <QLocale>
#include <QMessageBox>
#include <QMetaType> #include <QMetaType>
#include <QTime> #include <QTime>
#include <QtConcurrent/QtConcurrentRun> #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 // Create a proxy to the game list to display the list of preferred games
game_list = new QStandardItemModel; game_list = new QStandardItemModel;
UpdateGameList(list);
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());
}
}
proxy = new ComboBoxProxyModel; proxy = new ComboBoxProxyModel;
proxy->setSourceModel(game_list); proxy->setSourceModel(game_list);
@ -78,6 +73,16 @@ HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list,
HostRoomWindow::~HostRoomWindow() = default; 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() { void HostRoomWindow::RetranslateUi() {
ui->retranslateUi(this); ui->retranslateUi(this);
} }
@ -110,6 +115,10 @@ void HostRoomWindow::Host() {
NetworkMessage::ShowError(NetworkMessage::PORT_NOT_VALID); NetworkMessage::ShowError(NetworkMessage::PORT_NOT_VALID);
return; return;
} }
if (ui->game_list->currentIndex() == -1) {
NetworkMessage::ShowError(NetworkMessage::GAME_NOT_SELECTED);
return;
}
if (auto member = Network::GetRoomMember().lock()) { if (auto member = Network::GetRoomMember().lock()) {
if (member->GetState() == Network::RoomMember::State::Joining) { if (member->GetState() == Network::RoomMember::State::Joining) {
return; return;
@ -148,7 +157,22 @@ void HostRoomWindow::Host() {
if (is_public) { if (is_public) {
if (auto session = announce_multiplayer_session.lock()) { if (auto session = announce_multiplayer_session.lock()) {
// Register the room first to ensure verify_UID is present when we connect // 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(); session->Start();
} else { } else {
LOG_ERROR(Network, "Starting announce session failed"); LOG_ERROR(Network, "Starting announce session failed");

View File

@ -38,6 +38,11 @@ public:
std::shared_ptr<Core::AnnounceMultiplayerSession> session); std::shared_ptr<Core::AnnounceMultiplayerSession> session);
~HostRoomWindow(); ~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(); void RetranslateUi();
private: private:

View File

@ -35,13 +35,7 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
// Create a proxy to the game list to get the list of games owned // Create a proxy to the game list to get the list of games owned
game_list = new QStandardItemModel; game_list = new QStandardItemModel;
UpdateGameList(list);
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());
}
}
proxy = new LobbyFilterProxyModel(this, game_list); proxy = new LobbyFilterProxyModel(this, game_list);
proxy->setSourceModel(model); proxy->setSourceModel(model);
@ -88,6 +82,18 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
RefreshLobby(); 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() { void Lobby::RetranslateUi() {
ui->retranslateUi(this); ui->retranslateUi(this);
} }
@ -260,6 +266,10 @@ void Lobby::OnRefreshLobby() {
LobbyFilterProxyModel::LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list) LobbyFilterProxyModel::LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list)
: QSortFilterProxyModel(parent), game_list(list) {} : QSortFilterProxyModel(parent), game_list(list) {}
void LobbyFilterProxyModel::UpdateGameList(QStandardItemModel* list) {
game_list = list;
}
bool LobbyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const { bool LobbyFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const {
// Prioritize filters by fastest to compute // Prioritize filters by fastest to compute

View File

@ -30,6 +30,11 @@ public:
std::shared_ptr<Core::AnnounceMultiplayerSession> session); std::shared_ptr<Core::AnnounceMultiplayerSession> session);
~Lobby() = default; ~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(); void RetranslateUi();
public slots: public slots:
@ -76,9 +81,9 @@ private:
*/ */
QString PasswordPrompt(); QString PasswordPrompt();
QStandardItemModel* model; QStandardItemModel* model{};
QStandardItemModel* game_list; QStandardItemModel* game_list{};
LobbyFilterProxyModel* proxy; LobbyFilterProxyModel* proxy{};
QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher; QFutureWatcher<AnnounceMultiplayerRoom::RoomList> room_list_watcher;
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session; std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
@ -95,6 +100,13 @@ class LobbyFilterProxyModel : public QSortFilterProxyModel {
public: public:
explicit LobbyFilterProxyModel(QWidget* parent, QStandardItemModel* list); 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; bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
void sort(int column, Qt::SortOrder order) override; void sort(int column, Qt::SortOrder order) override;

View File

@ -16,6 +16,9 @@ const ConnectionError USERNAME_NOT_VALID_SERVER(
QT_TR_NOOP("Username is already in use or not valid. Please choose another.")); 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 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 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( const ConnectionError NO_INTERNET(
QT_TR_NOOP("Unable to find an internet connection. Check your internet settings.")); QT_TR_NOOP("Unable to find an internet connection. Check your internet settings."));
const ConnectionError UNABLE_TO_CONNECT( const ConnectionError UNABLE_TO_CONNECT(

View File

@ -27,6 +27,7 @@ extern const ConnectionError ROOMNAME_NOT_VALID;
extern const ConnectionError USERNAME_NOT_VALID_SERVER; extern const ConnectionError USERNAME_NOT_VALID_SERVER;
extern const ConnectionError IP_ADDRESS_NOT_VALID; extern const ConnectionError IP_ADDRESS_NOT_VALID;
extern const ConnectionError PORT_NOT_VALID; extern const ConnectionError PORT_NOT_VALID;
extern const ConnectionError GAME_NOT_SELECTED;
extern const ConnectionError NO_INTERNET; extern const ConnectionError NO_INTERNET;
extern const ConnectionError UNABLE_TO_CONNECT; extern const ConnectionError UNABLE_TO_CONNECT;
extern const ConnectionError ROOM_IS_FULL; extern const ConnectionError ROOM_IS_FULL;

View File

@ -174,12 +174,9 @@ void MultiplayerState::OnNetworkError(const Network::RoomMember::Error& error) {
void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) { void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {
announce_multiplayer_session->Stop(); announce_multiplayer_session->Stop();
QMessageBox::warning( QMessageBox::warning(this, tr("Error"),
this, tr("Error"), tr("Failed to update the room information. Please check your Internet "
tr("Failed to announce the room to the public lobby. In order to host a room publicly, you " "connection and try hosting the room again.\nDebug Message: ") +
"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), QString::fromStdString(result.result_string),
QMessageBox::Ok); QMessageBox::Ok);
} }
@ -281,3 +278,21 @@ 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();
}
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);
}
}

View File

@ -38,6 +38,20 @@ 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();
/**
* 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: 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

@ -83,9 +83,10 @@ public:
/** /**
* Registers the data in the announce service * 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 * Empties the stored players
@ -121,8 +122,8 @@ public:
Common::WebResult Update() override { Common::WebResult Update() override {
return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"}; return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"};
} }
std::string Register() override { Common::WebResult Register() override {
return ""; return Common::WebResult{Common::WebResult::Code::NoWebservice, "WebService is missing"};
} }
void ClearPlayers() override {} void ClearPlayers() override {}
RoomList GetRoomList() override { RoomList GetRoomList() override {

View File

@ -29,19 +29,23 @@ AnnounceMultiplayerSession::AnnounceMultiplayerSession() {
#endif #endif
} }
void AnnounceMultiplayerSession::Register() { Common::WebResult AnnounceMultiplayerSession::Register() {
std::shared_ptr<Network::Room> room = Network::GetRoom().lock(); std::shared_ptr<Network::Room> room = Network::GetRoom().lock();
if (!room) { if (!room) {
return; return Common::WebResult{Common::WebResult::Code::LibError, "Network is not initialized"};
} }
if (room->GetState() != Network::Room::State::Open) { if (room->GetState() != Network::Room::State::Open) {
return; return Common::WebResult{Common::WebResult::Code::LibError, "Room is not open"};
} }
UpdateBackendData(room); 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"); LOG_INFO(WebService, "Room has been registered");
room->SetVerifyUID(result); room->SetVerifyUID(result.returned_data);
registered = true; registered = true;
return Common::WebResult{Common::WebResult::Code::Success};
} }
void AnnounceMultiplayerSession::Start() { void AnnounceMultiplayerSession::Start() {
@ -95,9 +99,22 @@ void AnnounceMultiplayerSession::UpdateBackendData(std::shared_ptr<Network::Room
} }
void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() { void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
if (!registered) { // Invokes all current bound error callbacks.
Register(); const auto ErrorCallback = [this](Common::WebResult result) {
std::lock_guard<std::mutex> lock(callback_mutex);
for (auto callback : error_callbacks) {
(*callback)(result);
} }
};
if (!registered) {
Common::WebResult result = Register();
if (result.result_code != Common::WebResult::Code::Success) {
ErrorCallback(result);
return;
}
}
auto update_time = std::chrono::steady_clock::now(); auto update_time = std::chrono::steady_clock::now();
std::future<Common::WebResult> future; std::future<Common::WebResult> future;
while (!shutdown_event.WaitUntil(update_time)) { while (!shutdown_event.WaitUntil(update_time)) {
@ -112,15 +129,15 @@ void AnnounceMultiplayerSession::AnnounceMultiplayerLoop() {
UpdateBackendData(room); UpdateBackendData(room);
Common::WebResult result = backend->Update(); Common::WebResult result = backend->Update();
if (result.result_code != Common::WebResult::Code::Success) { if (result.result_code != Common::WebResult::Code::Success) {
std::lock_guard lock(callback_mutex); ErrorCallback(result);
for (auto callback : error_callbacks) {
(*callback)(result);
}
} }
if (result.result_string == "404") { if (result.result_string == "404") {
registered = false; registered = false;
// Needs to register the room again // 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(); 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

@ -44,8 +44,11 @@ public:
*/ */
void UnbindErrorCallback(CallbackHandle handle); 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 * Starts the announce of a room to web services
@ -64,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;

View File

@ -92,13 +92,6 @@ bool VerifyLogin(const std::string& username, const std::string& token) {
} }
TelemetrySession::TelemetrySession() { 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 // Log one-time top-level information
AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId()); AddField(Telemetry::FieldType::None, "TelemetryId", GetTelemetryId());
@ -192,9 +185,15 @@ TelemetrySession::~TelemetrySession() {
.count()}; .count()};
AddField(Telemetry::FieldType::Session, "Shutdown_Time", shutdown_time); 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 // 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); field_collection.Accept(*backend);
if (Settings::values.enable_telemetry) if (Settings::values.enable_telemetry)
backend->Complete(); backend->Complete();
@ -203,6 +202,9 @@ TelemetrySession::~TelemetrySession() {
bool TelemetrySession::SubmitTestcase() { bool TelemetrySession::SubmitTestcase() {
#ifdef ENABLE_WEB_SERVICE #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); field_collection.Accept(*backend);
return backend->SubmitTestcase(); return backend->SubmitTestcase();
#else #else

View File

@ -39,7 +39,6 @@ public:
private: private:
Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
}; };
/** /**

View File

@ -117,16 +117,16 @@ Common::WebResult RoomJson::Update() {
return client.PostJson(fmt::format("/lobby/{}", room_id), json.dump(), false); return client.PostJson(fmt::format("/lobby/{}", room_id), json.dump(), false);
} }
std::string RoomJson::Register() { Common::WebResult RoomJson::Register() {
nlohmann::json json = room; nlohmann::json json = room;
auto reply = client.PostJson("/lobby", json.dump(), false).returned_data; auto result = client.PostJson("/lobby", json.dump(), false);
if (reply.empty()) { if (result.result_code != Common::WebResult::Code::Success) {
return ""; 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 = reply_json.get<AnnounceMultiplayerRoom::Room>();
room_id = reply_json.at("id").get<std::string>(); 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() { void RoomJson::ClearPlayers() {

View File

@ -29,7 +29,7 @@ public:
const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id, const AnnounceMultiplayerRoom::MacAddress& mac_address, const u64 game_id,
const std::string& game_name) override; const std::string& game_name) override;
Common::WebResult Update() override; Common::WebResult Update() override;
std::string Register() override; Common::WebResult Register() override;
void ClearPlayers() override; void ClearPlayers() override;
AnnounceMultiplayerRoom::RoomList GetRoomList() override; AnnounceMultiplayerRoom::RoomList GetRoomList() override;
void Delete() override; void Delete() override;