mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Frontend: Prevent connecting to another room when already joining
This commit is contained in:
		
							parent
							
								
									c8d4ca8915
								
							
						
					
					
						commit
						5fef22fc52
					
				
					 4 changed files with 20 additions and 15 deletions
				
			
		|  | @ -51,8 +51,14 @@ void DirectConnectWindow::Connect() { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (const auto member = Network::GetRoomMember().lock()) { |     if (const auto member = Network::GetRoomMember().lock()) { | ||||||
|         if (member->IsConnected() && !NetworkMessage::WarnDisconnect()) { |         // Prevent the user from trying to join a room while they are already joining.
 | ||||||
|  |         if (member->GetState() == Network::RoomMember::State::Joining) { | ||||||
|             return; |             return; | ||||||
|  |         } else if (member->GetState() == Network::RoomMember::State::Joined) { | ||||||
|  |             // And ask if they want to leave the room if they are already in one.
 | ||||||
|  |             if (!NetworkMessage::WarnDisconnect()) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) { |     switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) { | ||||||
|  |  | ||||||
|  | @ -74,7 +74,9 @@ void HostRoomWindow::Host() { | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (auto member = Network::GetRoomMember().lock()) { |     if (auto member = Network::GetRoomMember().lock()) { | ||||||
|         if (member->IsConnected()) { |         if (member->GetState() == Network::RoomMember::State::Joining) { | ||||||
|  |             return; | ||||||
|  |         } else if (member->GetState() == Network::RoomMember::State::Joined) { | ||||||
|             auto parent = static_cast<MultiplayerState*>(parentWidget()); |             auto parent = static_cast<MultiplayerState*>(parentWidget()); | ||||||
|             if (!parent->OnCloseRoom()) { |             if (!parent->OnCloseRoom()) { | ||||||
|                 close(); |                 close(); | ||||||
|  |  | ||||||
|  | @ -26,7 +26,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | ||||||
| 
 | 
 | ||||||
|     // setup the watcher for background connections
 |     // setup the watcher for background connections
 | ||||||
|     watcher = new QFutureWatcher<void>; |     watcher = new QFutureWatcher<void>; | ||||||
|     connect(watcher, &QFutureWatcher<void>::finished, [&] { joining = false; }); |  | ||||||
| 
 | 
 | ||||||
|     model = new QStandardItemModel(ui->room_list); |     model = new QStandardItemModel(ui->room_list); | ||||||
|     proxy = new LobbyFilterProxyModel(this, game_list); |     proxy = new LobbyFilterProxyModel(this, game_list); | ||||||
|  | @ -51,7 +50,6 @@ Lobby::Lobby(QWidget* parent, QStandardItemModel* list, | ||||||
|     ui->nickname->setText(UISettings::values.nickname); |     ui->nickname->setText(UISettings::values.nickname); | ||||||
| 
 | 
 | ||||||
|     // UI Buttons
 |     // UI Buttons
 | ||||||
|     MultiplayerState* p = reinterpret_cast<MultiplayerState*>(parent); |  | ||||||
|     connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby); |     connect(ui->refresh_list, &QPushButton::pressed, this, &Lobby::RefreshLobby); | ||||||
|     connect(ui->games_owned, &QCheckBox::stateChanged, proxy, |     connect(ui->games_owned, &QCheckBox::stateChanged, proxy, | ||||||
|             &LobbyFilterProxyModel::SetFilterOwned); |             &LobbyFilterProxyModel::SetFilterOwned); | ||||||
|  | @ -84,10 +82,17 @@ void Lobby::OnExpandRoom(const QModelIndex& index) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Lobby::OnJoinRoom(const QModelIndex& source) { | void Lobby::OnJoinRoom(const QModelIndex& source) { | ||||||
|     if (joining) { |     if (const auto member = Network::GetRoomMember().lock()) { | ||||||
|         return; |         // Prevent the user from trying to join a room while they are already joining.
 | ||||||
|  |         if (member->GetState() == Network::RoomMember::State::Joining) { | ||||||
|  |             return; | ||||||
|  |         } else if (member->GetState() == Network::RoomMember::State::Joined) { | ||||||
|  |             // And ask if they want to leave the room if they are already in one.
 | ||||||
|  |             if (!NetworkMessage::WarnDisconnect()) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|     joining = true; |  | ||||||
|     QModelIndex index = source; |     QModelIndex index = source; | ||||||
|     // If the user double clicks on a child row (aka the player list) then use the parent instead
 |     // If the user double clicks on a child row (aka the player list) then use the parent instead
 | ||||||
|     if (source.parent() != QModelIndex()) { |     if (source.parent() != QModelIndex()) { | ||||||
|  | @ -97,13 +102,6 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { | ||||||
|         NetworkMessage::ShowError(NetworkMessage::USERNAME_NOT_VALID); |         NetworkMessage::ShowError(NetworkMessage::USERNAME_NOT_VALID); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     if (const auto member = Network::GetRoomMember().lock()) { |  | ||||||
|         if (member->IsConnected()) { |  | ||||||
|             if (!NetworkMessage::WarnDisconnect()) { |  | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     // Get a password to pass if the room is password protected
 |     // Get a password to pass if the room is password protected
 | ||||||
|     QModelIndex password_index = proxy->index(index.row(), Column::ROOM_NAME); |     QModelIndex password_index = proxy->index(index.row(), Column::ROOM_NAME); | ||||||
|  |  | ||||||
|  | @ -89,7 +89,6 @@ private: | ||||||
|     std::unique_ptr<Ui::Lobby> ui; |     std::unique_ptr<Ui::Lobby> ui; | ||||||
|     QFutureWatcher<void>* watcher; |     QFutureWatcher<void>* watcher; | ||||||
|     Validation validation; |     Validation validation; | ||||||
|     bool joining = false; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue