citra-emu
/
citra
Archived
1
0
Fork 0

Move almost all state change tracking to MultiplayerState

Each window can still watch for state changes to update the ui or to
close the window as appropriate, but for any error announcements, they
all belong in Multiplayer state now.
This commit is contained in:
James Rowe 2018-04-19 00:47:11 -06:00
parent a5c8e07f46
commit 1f6791431d
7 changed files with 55 additions and 88 deletions

View File

@ -49,44 +49,9 @@ void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) {
}
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
switch (state) {
case Network::RoomMember::State::Idle:
NGLOG_INFO(Network, "State: Idle");
break;
case Network::RoomMember::State::Joining:
NGLOG_INFO(Network, "State: Joining");
break;
case Network::RoomMember::State::Joined:
NGLOG_INFO(Network, "State: Joined");
if (state == Network::RoomMember::State::Joined) {
ui->chat->Clear();
ui->chat->AppendStatusMessage(tr("Connected"));
break;
case Network::RoomMember::State::LostConnection:
NetworkMessage::ShowError(NetworkMessage::LOST_CONNECTION);
NGLOG_INFO(Network, "State: LostConnection");
break;
case Network::RoomMember::State::CouldNotConnect:
NetworkMessage::ShowError(NetworkMessage::UNABLE_TO_CONNECT);
NGLOG_INFO(Network, "State: CouldNotConnect");
break;
case Network::RoomMember::State::NameCollision:
NetworkMessage::ShowError(NetworkMessage::USERNAME_IN_USE);
NGLOG_INFO(Network, "State: NameCollision");
break;
case Network::RoomMember::State::MacCollision:
NetworkMessage::ShowError(NetworkMessage::MAC_COLLISION);
NGLOG_INFO(Network, "State: MacCollision");
break;
case Network::RoomMember::State::WrongPassword:
NetworkMessage::ShowError(NetworkMessage::WRONG_PASSWORD);
NGLOG_INFO(Network, "State: WrongPassword");
break;
case Network::RoomMember::State::WrongVersion:
NetworkMessage::ShowError(NetworkMessage::WRONG_VERSION);
NGLOG_INFO(Network, "State: WrongVersion");
break;
default:
break;
}
UpdateView();
}
@ -99,7 +64,6 @@ void ClientRoomWindow::Disconnect() {
member->Leave();
ui->chat->AppendStatusMessage(tr("Disconnected"));
close();
emit Closed();
}
}
@ -120,6 +84,4 @@ void ClientRoomWindow::UpdateView() {
}
// TODO(B3N30): can't get RoomMember*, show error and close window
close();
emit Closed();
return;
}

View File

@ -22,11 +22,6 @@ public slots:
void OnStateChange(const Network::RoomMember::State&);
signals:
/**
* Signalled by this widget when it is closing itself and destroying any state such as
* connections that it might have.
*/
void Closed();
void RoomInformationChanged(const Network::RoomInformation&);
void StateChanged(const Network::RoomMember::State&);

View File

@ -105,20 +105,8 @@ void DirectConnectWindow::EndConnecting() {
void DirectConnectWindow::OnConnection() {
EndConnecting();
bool isConnected = true;
if (auto room_member = Network::GetRoomMember().lock()) {
switch (room_member->GetState()) {
case Network::RoomMember::State::CouldNotConnect:
isConnected = false;
ShowError(NetworkMessage::UNABLE_TO_CONNECT);
break;
case Network::RoomMember::State::NameCollision:
isConnected = false;
ShowError(NetworkMessage::USERNAME_IN_USE);
break;
case Network::RoomMember::State::Joining:
auto parent = static_cast<MultiplayerState*>(parentWidget());
parent->OnOpenNetworkRoom();
if (room_member->GetState() == Network::RoomMember::State::Joined) {
close();
}
}

View File

@ -119,17 +119,8 @@ void HostRoomWindow::Host() {
void HostRoomWindow::OnConnection() {
ui->host->setEnabled(true);
if (auto room_member = Network::GetRoomMember().lock()) {
switch (room_member->GetState()) {
case Network::RoomMember::State::CouldNotConnect:
ShowError(NetworkMessage::UNABLE_TO_CONNECT);
break;
case Network::RoomMember::State::NameCollision:
ShowError(NetworkMessage::USERNAME_IN_USE);
break;
case Network::RoomMember::State::Error:
ShowError(NetworkMessage::UNABLE_TO_CONNECT);
break;
case Network::RoomMember::State::Joining:
if (room_member->GetState() == Network::RoomMember::State::Joining) {
// Start the announce session if they chose Public
if (ui->host_type->currentIndex() == 0) {
if (auto session = announce_multiplayer_session.lock()) {
session->Start();
@ -137,12 +128,7 @@ void HostRoomWindow::OnConnection() {
NGLOG_ERROR(Network, "Starting announce session failed");
}
}
auto parent = static_cast<MultiplayerState*>(parentWidget());
// parent->ChangeRoomState();
parent->OnOpenNetworkRoom();
close();
emit Closed();
break;
}
}
}

View File

@ -34,13 +34,6 @@ public:
std::shared_ptr<Core::AnnounceMultiplayerSession> session);
~HostRoomWindow();
signals:
/**
* Signalled by this widget when it is closing itself and destroying any state such as
* connections that it might have.
*/
void Closed();
private slots:
/**
* Handler for connection status changes. Launches the chat window if successful or

View File

@ -28,10 +28,11 @@ const ConnectionError HOST_BANNED(
QT_TR_NOOP("The host of the room has banned you. Speak with the host to unban you "
"or try a different room."));
const ConnectionError WRONG_VERSION(
QT_TR_NOOP("Version mismatch! Please update to the latest version of citra. If the problem "
QT_TR_NOOP("Version mismatch! Please update to the latest version of Citra. If the problem "
"persists, contact the room host and ask them to update the server."));
const ConnectionError WRONG_PASSWORD(QT_TR_NOOP("Incorrect password."));
const ConnectionError GENERIC_ERROR(QT_TR_NOOP("An error occured."));
const ConnectionError GENERIC_ERROR(
QT_TR_NOOP("An unknown error occured. If this error continues to occur, please open an issue"));
const ConnectionError LOST_CONNECTION(QT_TR_NOOP("Connection to room lost. Try to reconnect."));
const ConnectionError MAC_COLLISION(
QT_TR_NOOP("MAC address is already in use. Please choose another."));

View File

@ -67,17 +67,59 @@ void MultiplayerState::Close() {
void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {
NGLOG_DEBUG(Frontend, "Network state change");
if (state == Network::RoomMember::State::Joined) {
bool is_connected = false;
switch (state) {
case Network::RoomMember::State::Idle:
NGLOG_DEBUG(Network, "State: Idle");
break;
case Network::RoomMember::State::Joining:
NGLOG_DEBUG(Network, "State: Joining");
break;
case Network::RoomMember::State::LostConnection:
NetworkMessage::ShowError(NetworkMessage::LOST_CONNECTION);
NGLOG_DEBUG(Network, "State: LostConnection");
break;
case Network::RoomMember::State::CouldNotConnect:
NetworkMessage::ShowError(NetworkMessage::UNABLE_TO_CONNECT);
NGLOG_DEBUG(Network, "State: CouldNotConnect");
break;
case Network::RoomMember::State::NameCollision:
NetworkMessage::ShowError(NetworkMessage::USERNAME_IN_USE);
NGLOG_DEBUG(Network, "State: NameCollision");
break;
case Network::RoomMember::State::MacCollision:
NetworkMessage::ShowError(NetworkMessage::MAC_COLLISION);
NGLOG_DEBUG(Network, "State: MacCollision");
break;
case Network::RoomMember::State::WrongPassword:
NetworkMessage::ShowError(NetworkMessage::WRONG_PASSWORD);
NGLOG_DEBUG(Network, "State: WrongPassword");
break;
case Network::RoomMember::State::WrongVersion:
NetworkMessage::ShowError(NetworkMessage::WRONG_VERSION);
NGLOG_DEBUG(Network, "State: WrongVersion");
break;
case Network::RoomMember::State::Error:
NetworkMessage::ShowError(NetworkMessage::UNABLE_TO_CONNECT);
NGLOG_DEBUG(Network, "State: GenericError");
break;
case Network::RoomMember::State::Joined:
NGLOG_DEBUG(Network, "State: Joined");
is_connected = true;
OnOpenNetworkRoom();
break;
}
if (is_connected) {
status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
status_text->setText(tr("Connected"));
leave_room->setEnabled(true);
show_room->setEnabled(true);
return;
} else {
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
status_text->setText(tr("Not Connected"));
leave_room->setEnabled(false);
show_room->setEnabled(false);
}
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
status_text->setText(tr("Not Connected"));
leave_room->setEnabled(false);
show_room->setEnabled(false);
}
void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {