summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFearlessTobi <thm.frey@gmail.com>2022-08-27 03:41:19 +0200
committerFearlessTobi <thm.frey@gmail.com>2022-08-27 03:41:19 +0200
commit2b6ac4463c06cfdf50b1d150311a217d2ee11688 (patch)
treeb3c6e200499949a98a42b05f96bcc01134ca2ef5 /src
parentcore/socket_proxy: Correct broadcast behavior (diff)
downloadyuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar.gz
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar.bz2
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar.lz
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar.xz
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.tar.zst
yuzu-2b6ac4463c06cfdf50b1d150311a217d2ee11688.zip
Diffstat (limited to '')
-rw-r--r--src/yuzu/main.cpp2
-rw-r--r--src/yuzu/multiplayer/direct_connect.cpp16
-rw-r--r--src/yuzu/multiplayer/direct_connect.h4
-rw-r--r--src/yuzu/multiplayer/host_room.cpp16
-rw-r--r--src/yuzu/multiplayer/host_room.h4
-rw-r--r--src/yuzu/multiplayer/lobby.cpp19
-rw-r--r--src/yuzu/multiplayer/lobby.h4
-rw-r--r--src/yuzu/multiplayer/message.cpp10
-rw-r--r--src/yuzu/multiplayer/message.h9
-rw-r--r--src/yuzu/multiplayer/state.cpp12
-rw-r--r--src/yuzu/multiplayer/state.h4
11 files changed, 81 insertions, 19 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index e103df977..a85adc072 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -860,7 +860,7 @@ void GMainWindow::InitializeWidgets() {
});
multiplayer_state = new MultiplayerState(this, game_list->GetModel(), ui->action_Leave_Room,
- ui->action_Show_Room, system->GetRoomNetwork());
+ ui->action_Show_Room, *system);
multiplayer_state->setVisible(false);
// Create status bar
diff --git a/src/yuzu/multiplayer/direct_connect.cpp b/src/yuzu/multiplayer/direct_connect.cpp
index 4c0ea0a6b..65b5f0b9d 100644
--- a/src/yuzu/multiplayer/direct_connect.cpp
+++ b/src/yuzu/multiplayer/direct_connect.cpp
@@ -8,6 +8,7 @@
#include <QString>
#include <QtConcurrent/QtConcurrentRun>
#include "common/settings.h"
+#include "core/internal_network/network_interface.h"
#include "network/network.h"
#include "ui_direct_connect.h"
#include "yuzu/main.h"
@@ -20,9 +21,10 @@
enum class ConnectionType : u8 { TraversalServer, IP };
-DirectConnectWindow::DirectConnectWindow(Network::RoomNetwork& room_network_, QWidget* parent)
+DirectConnectWindow::DirectConnectWindow(Core::System& system_, QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
- ui(std::make_unique<Ui::DirectConnect>()), room_network{room_network_} {
+ ui(std::make_unique<Ui::DirectConnect>()), system{system_}, room_network{
+ system.GetRoomNetwork()} {
ui->setupUi(this);
@@ -53,10 +55,20 @@ void DirectConnectWindow::RetranslateUi() {
}
void DirectConnectWindow::Connect() {
+ if (!Network::GetSelectedNetworkInterface()) {
+ NetworkMessage::ErrorManager::ShowError(
+ NetworkMessage::ErrorManager::NO_INTERFACE_SELECTED);
+ return;
+ }
if (!ui->nickname->hasAcceptableInput()) {
NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::USERNAME_NOT_VALID);
return;
}
+ if (system.IsPoweredOn()) {
+ if (!NetworkMessage::WarnGameRunning()) {
+ return;
+ }
+ }
if (const auto member = room_network.GetRoomMember().lock()) {
// Prevent the user from trying to join a room while they are already joining.
if (member->GetState() == Network::RoomMember::State::Joining) {
diff --git a/src/yuzu/multiplayer/direct_connect.h b/src/yuzu/multiplayer/direct_connect.h
index 4e1043053..defa4f4ec 100644
--- a/src/yuzu/multiplayer/direct_connect.h
+++ b/src/yuzu/multiplayer/direct_connect.h
@@ -6,6 +6,7 @@
#include <memory>
#include <QDialog>
#include <QFutureWatcher>
+#include "core/core.h"
#include "yuzu/multiplayer/validation.h"
namespace Ui {
@@ -16,7 +17,7 @@ class DirectConnectWindow : public QDialog {
Q_OBJECT
public:
- explicit DirectConnectWindow(Network::RoomNetwork& room_network_, QWidget* parent = nullptr);
+ explicit DirectConnectWindow(Core::System& system_, QWidget* parent = nullptr);
~DirectConnectWindow();
void RetranslateUi();
@@ -39,5 +40,6 @@ private:
QFutureWatcher<void>* watcher;
std::unique_ptr<Ui::DirectConnect> ui;
Validation validation;
+ Core::System& system;
Network::RoomNetwork& room_network;
};
diff --git a/src/yuzu/multiplayer/host_room.cpp b/src/yuzu/multiplayer/host_room.cpp
index 8e7a81291..ad7dcc36d 100644
--- a/src/yuzu/multiplayer/host_room.cpp
+++ b/src/yuzu/multiplayer/host_room.cpp
@@ -12,6 +12,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include "common/logging/log.h"
#include "common/settings.h"
+#include "core/internal_network/network_interface.h"
#include "network/announce_multiplayer_session.h"
#include "ui_host_room.h"
#include "yuzu/game_list_p.h"
@@ -27,10 +28,11 @@
HostRoomWindow::HostRoomWindow(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session,
- Network::RoomNetwork& room_network_)
+ Core::System& system_)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::HostRoom>()),
- announce_multiplayer_session(session), room_network{room_network_} {
+ announce_multiplayer_session(session), system{system_}, room_network{
+ system.GetRoomNetwork()} {
ui->setupUi(this);
// set up validation for all of the fields
@@ -105,6 +107,11 @@ std::unique_ptr<Network::VerifyUser::Backend> HostRoomWindow::CreateVerifyBacken
}
void HostRoomWindow::Host() {
+ if (!Network::GetSelectedNetworkInterface()) {
+ NetworkMessage::ErrorManager::ShowError(
+ NetworkMessage::ErrorManager::NO_INTERFACE_SELECTED);
+ return;
+ }
if (!ui->username->hasAcceptableInput()) {
NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::USERNAME_NOT_VALID);
return;
@@ -121,6 +128,11 @@ void HostRoomWindow::Host() {
NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::GAME_NOT_SELECTED);
return;
}
+ if (system.IsPoweredOn()) {
+ if (!NetworkMessage::WarnGameRunning()) {
+ return;
+ }
+ }
if (auto member = room_network.GetRoomMember().lock()) {
if (member->GetState() == Network::RoomMember::State::Joining) {
return;
diff --git a/src/yuzu/multiplayer/host_room.h b/src/yuzu/multiplayer/host_room.h
index a968042d0..63c0d2333 100644
--- a/src/yuzu/multiplayer/host_room.h
+++ b/src/yuzu/multiplayer/host_room.h
@@ -8,6 +8,7 @@
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QVariant>
+#include "core/core.h"
#include "network/network.h"
#include "yuzu/multiplayer/chat_room.h"
#include "yuzu/multiplayer/validation.h"
@@ -35,7 +36,7 @@ class HostRoomWindow : public QDialog {
public:
explicit HostRoomWindow(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session,
- Network::RoomNetwork& room_network_);
+ Core::System& system_);
~HostRoomWindow();
/**
@@ -54,6 +55,7 @@ private:
QStandardItemModel* game_list;
ComboBoxProxyModel* proxy;
Validation validation;
+ Core::System& system;
Network::RoomNetwork& room_network;
};
diff --git a/src/yuzu/multiplayer/lobby.cpp b/src/yuzu/multiplayer/lobby.cpp
index 1cc518279..c5fb846c7 100644
--- a/src/yuzu/multiplayer/lobby.cpp
+++ b/src/yuzu/multiplayer/lobby.cpp
@@ -6,6 +6,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include "common/logging/log.h"
#include "common/settings.h"
+#include "core/internal_network/network_interface.h"
#include "network/network.h"
#include "ui_lobby.h"
#include "yuzu/game_list_p.h"
@@ -22,11 +23,11 @@
#endif
Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
- std::shared_ptr<Core::AnnounceMultiplayerSession> session,
- Network::RoomNetwork& room_network_)
+ std::shared_ptr<Core::AnnounceMultiplayerSession> session, Core::System& system_)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::Lobby>()),
- announce_multiplayer_session(session), room_network{room_network_} {
+ announce_multiplayer_session(session), system{system_}, room_network{
+ system.GetRoomNetwork()} {
ui->setupUi(this);
// setup the watcher for background connections
@@ -114,6 +115,18 @@ void Lobby::OnExpandRoom(const QModelIndex& index) {
}
void Lobby::OnJoinRoom(const QModelIndex& source) {
+ if (!Network::GetSelectedNetworkInterface()) {
+ NetworkMessage::ErrorManager::ShowError(
+ NetworkMessage::ErrorManager::NO_INTERFACE_SELECTED);
+ return;
+ }
+
+ if (system.IsPoweredOn()) {
+ if (!NetworkMessage::WarnGameRunning()) {
+ return;
+ }
+ }
+
if (const auto member = room_network.GetRoomMember().lock()) {
// Prevent the user from trying to join a room while they are already joining.
if (member->GetState() == Network::RoomMember::State::Joining) {
diff --git a/src/yuzu/multiplayer/lobby.h b/src/yuzu/multiplayer/lobby.h
index 02cc766e4..49fd4c473 100644
--- a/src/yuzu/multiplayer/lobby.h
+++ b/src/yuzu/multiplayer/lobby.h
@@ -9,6 +9,7 @@
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include "common/announce_multiplayer_room.h"
+#include "core/core.h"
#include "network/announce_multiplayer_session.h"
#include "network/network.h"
#include "yuzu/multiplayer/validation.h"
@@ -30,7 +31,7 @@ class Lobby : public QDialog {
public:
explicit Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session,
- Network::RoomNetwork& room_network_);
+ Core::System& system_);
~Lobby() override;
/**
@@ -94,6 +95,7 @@ private:
std::weak_ptr<Core::AnnounceMultiplayerSession> announce_multiplayer_session;
QFutureWatcher<void>* watcher;
Validation validation;
+ Core::System& system;
Network::RoomNetwork& room_network;
};
diff --git a/src/yuzu/multiplayer/message.cpp b/src/yuzu/multiplayer/message.cpp
index 94d7a38b8..758b5b731 100644
--- a/src/yuzu/multiplayer/message.cpp
+++ b/src/yuzu/multiplayer/message.cpp
@@ -49,6 +49,9 @@ const ConnectionError ErrorManager::PERMISSION_DENIED(
QT_TR_NOOP("You do not have enough permission to perform this action."));
const ConnectionError ErrorManager::NO_SUCH_USER(QT_TR_NOOP(
"The user you are trying to kick/ban could not be found.\nThey may have left the room."));
+const ConnectionError ErrorManager::NO_INTERFACE_SELECTED(
+ QT_TR_NOOP("No network interface is selected.\nPlease go to Configure -> System -> Network and "
+ "make a selection."));
static bool WarnMessage(const std::string& title, const std::string& text) {
return QMessageBox::Ok == QMessageBox::warning(nullptr, QObject::tr(title.c_str()),
@@ -60,6 +63,13 @@ void ErrorManager::ShowError(const ConnectionError& e) {
QMessageBox::critical(nullptr, tr("Error"), tr(e.GetString().c_str()));
}
+bool WarnGameRunning() {
+ return WarnMessage(
+ QT_TR_NOOP("Game already running"),
+ QT_TR_NOOP("Joining a room when the game is already running is discouraged "
+ "and can cause the room feature not to work correctly.\nProceed anyway?"));
+}
+
bool WarnCloseRoom() {
return WarnMessage(
QT_TR_NOOP("Leave Room"),
diff --git a/src/yuzu/multiplayer/message.h b/src/yuzu/multiplayer/message.h
index 812495c72..f038b9a1f 100644
--- a/src/yuzu/multiplayer/message.h
+++ b/src/yuzu/multiplayer/message.h
@@ -43,11 +43,20 @@ public:
static const ConnectionError IP_COLLISION;
static const ConnectionError PERMISSION_DENIED;
static const ConnectionError NO_SUCH_USER;
+ static const ConnectionError NO_INTERFACE_SELECTED;
/**
* Shows a standard QMessageBox with a error message
*/
static void ShowError(const ConnectionError& e);
};
+
+/**
+ * Show a standard QMessageBox with a warning message about joining a room when
+ * the game is already running
+ * return true if the user wants to close the network connection
+ */
+bool WarnGameRunning();
+
/**
* Show a standard QMessageBox with a warning message about leaving the room
* return true if the user wants to close the network connection
diff --git a/src/yuzu/multiplayer/state.cpp b/src/yuzu/multiplayer/state.cpp
index dba76b22b..d1a68b182 100644
--- a/src/yuzu/multiplayer/state.cpp
+++ b/src/yuzu/multiplayer/state.cpp
@@ -19,10 +19,9 @@
#include "yuzu/util/clickable_label.h"
MultiplayerState::MultiplayerState(QWidget* parent, QStandardItemModel* game_list_model_,
- QAction* leave_room_, QAction* show_room_,
- Network::RoomNetwork& room_network_)
+ QAction* leave_room_, QAction* show_room_, Core::System& system_)
: QWidget(parent), game_list_model(game_list_model_), leave_room(leave_room_),
- show_room(show_room_), room_network{room_network_} {
+ show_room(show_room_), system{system_}, room_network{system.GetRoomNetwork()} {
if (auto member = room_network.GetRoomMember().lock()) {
// register the network structs to use in slots and signals
state_callback_handle = member->BindOnStateChanged(
@@ -208,15 +207,14 @@ static void BringWidgetToFront(QWidget* widget) {
void MultiplayerState::OnViewLobby() {
if (lobby == nullptr) {
- lobby = new Lobby(this, game_list_model, announce_multiplayer_session, room_network);
+ lobby = new Lobby(this, game_list_model, announce_multiplayer_session, system);
}
BringWidgetToFront(lobby);
}
void MultiplayerState::OnCreateRoom() {
if (host_room == nullptr) {
- host_room =
- new HostRoomWindow(this, game_list_model, announce_multiplayer_session, room_network);
+ host_room = new HostRoomWindow(this, game_list_model, announce_multiplayer_session, system);
}
BringWidgetToFront(host_room);
}
@@ -279,7 +277,7 @@ void MultiplayerState::OnOpenNetworkRoom() {
void MultiplayerState::OnDirectConnectToRoom() {
if (direct_connect == nullptr) {
- direct_connect = new DirectConnectWindow(room_network, this);
+ direct_connect = new DirectConnectWindow(system, this);
}
BringWidgetToFront(direct_connect);
}
diff --git a/src/yuzu/multiplayer/state.h b/src/yuzu/multiplayer/state.h
index 23960414e..3921f2fc3 100644
--- a/src/yuzu/multiplayer/state.h
+++ b/src/yuzu/multiplayer/state.h
@@ -4,6 +4,7 @@
#pragma once
#include <QWidget>
+#include "core/core.h"
#include "network/announce_multiplayer_session.h"
#include "network/network.h"
@@ -19,7 +20,7 @@ class MultiplayerState : public QWidget {
public:
explicit MultiplayerState(QWidget* parent, QStandardItemModel* game_list, QAction* leave_room,
- QAction* show_room, Network::RoomNetwork& room_network_);
+ QAction* show_room, Core::System& system_);
~MultiplayerState();
/**
@@ -86,6 +87,7 @@ private:
Network::RoomMember::CallbackHandle<Network::RoomMember::Error> error_callback_handle;
bool show_notification = false;
+ Core::System& system;
Network::RoomNetwork& room_network;
};