mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 01:22:37 -06:00
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:
parent
a5c8e07f46
commit
1f6791431d
7 changed files with 55 additions and 88 deletions
|
@ -49,44 +49,9 @@ void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
|
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
|
||||||
switch (state) {
|
if (state == Network::RoomMember::State::Joined) {
|
||||||
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");
|
|
||||||
ui->chat->Clear();
|
ui->chat->Clear();
|
||||||
ui->chat->AppendStatusMessage(tr("Connected"));
|
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();
|
UpdateView();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +64,6 @@ void ClientRoomWindow::Disconnect() {
|
||||||
member->Leave();
|
member->Leave();
|
||||||
ui->chat->AppendStatusMessage(tr("Disconnected"));
|
ui->chat->AppendStatusMessage(tr("Disconnected"));
|
||||||
close();
|
close();
|
||||||
emit Closed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,6 +84,4 @@ void ClientRoomWindow::UpdateView() {
|
||||||
}
|
}
|
||||||
// TODO(B3N30): can't get RoomMember*, show error and close window
|
// TODO(B3N30): can't get RoomMember*, show error and close window
|
||||||
close();
|
close();
|
||||||
emit Closed();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,6 @@ public slots:
|
||||||
void OnStateChange(const Network::RoomMember::State&);
|
void OnStateChange(const Network::RoomMember::State&);
|
||||||
|
|
||||||
signals:
|
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 RoomInformationChanged(const Network::RoomInformation&);
|
||||||
void StateChanged(const Network::RoomMember::State&);
|
void StateChanged(const Network::RoomMember::State&);
|
||||||
|
|
||||||
|
|
|
@ -105,20 +105,8 @@ void DirectConnectWindow::EndConnecting() {
|
||||||
void DirectConnectWindow::OnConnection() {
|
void DirectConnectWindow::OnConnection() {
|
||||||
EndConnecting();
|
EndConnecting();
|
||||||
|
|
||||||
bool isConnected = true;
|
|
||||||
if (auto room_member = Network::GetRoomMember().lock()) {
|
if (auto room_member = Network::GetRoomMember().lock()) {
|
||||||
switch (room_member->GetState()) {
|
if (room_member->GetState() == Network::RoomMember::State::Joined) {
|
||||||
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();
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,17 +119,8 @@ void HostRoomWindow::Host() {
|
||||||
void HostRoomWindow::OnConnection() {
|
void HostRoomWindow::OnConnection() {
|
||||||
ui->host->setEnabled(true);
|
ui->host->setEnabled(true);
|
||||||
if (auto room_member = Network::GetRoomMember().lock()) {
|
if (auto room_member = Network::GetRoomMember().lock()) {
|
||||||
switch (room_member->GetState()) {
|
if (room_member->GetState() == Network::RoomMember::State::Joining) {
|
||||||
case Network::RoomMember::State::CouldNotConnect:
|
// Start the announce session if they chose Public
|
||||||
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 (ui->host_type->currentIndex() == 0) {
|
if (ui->host_type->currentIndex() == 0) {
|
||||||
if (auto session = announce_multiplayer_session.lock()) {
|
if (auto session = announce_multiplayer_session.lock()) {
|
||||||
session->Start();
|
session->Start();
|
||||||
|
@ -137,12 +128,7 @@ void HostRoomWindow::OnConnection() {
|
||||||
NGLOG_ERROR(Network, "Starting announce session failed");
|
NGLOG_ERROR(Network, "Starting announce session failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto parent = static_cast<MultiplayerState*>(parentWidget());
|
|
||||||
// parent->ChangeRoomState();
|
|
||||||
parent->OnOpenNetworkRoom();
|
|
||||||
close();
|
close();
|
||||||
emit Closed();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,13 +34,6 @@ public:
|
||||||
std::shared_ptr<Core::AnnounceMultiplayerSession> session);
|
std::shared_ptr<Core::AnnounceMultiplayerSession> session);
|
||||||
~HostRoomWindow();
|
~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:
|
private slots:
|
||||||
/**
|
/**
|
||||||
* Handler for connection status changes. Launches the chat window if successful or
|
* Handler for connection status changes. Launches the chat window if successful or
|
||||||
|
|
|
@ -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 "
|
QT_TR_NOOP("The host of the room has banned you. Speak with the host to unban you "
|
||||||
"or try a different room."));
|
"or try a different room."));
|
||||||
const ConnectionError WRONG_VERSION(
|
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."));
|
"persists, contact the room host and ask them to update the server."));
|
||||||
const ConnectionError WRONG_PASSWORD(QT_TR_NOOP("Incorrect password."));
|
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 LOST_CONNECTION(QT_TR_NOOP("Connection to room lost. Try to reconnect."));
|
||||||
const ConnectionError MAC_COLLISION(
|
const ConnectionError MAC_COLLISION(
|
||||||
QT_TR_NOOP("MAC address is already in use. Please choose another."));
|
QT_TR_NOOP("MAC address is already in use. Please choose another."));
|
||||||
|
|
|
@ -67,17 +67,59 @@ void MultiplayerState::Close() {
|
||||||
|
|
||||||
void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {
|
void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& state) {
|
||||||
NGLOG_DEBUG(Frontend, "Network state change");
|
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_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
|
||||||
status_text->setText(tr("Connected"));
|
status_text->setText(tr("Connected"));
|
||||||
leave_room->setEnabled(true);
|
leave_room->setEnabled(true);
|
||||||
show_room->setEnabled(true);
|
show_room->setEnabled(true);
|
||||||
return;
|
} else {
|
||||||
}
|
|
||||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
||||||
status_text->setText(tr("Not Connected"));
|
status_text->setText(tr("Not Connected"));
|
||||||
leave_room->setEnabled(false);
|
leave_room->setEnabled(false);
|
||||||
show_room->setEnabled(false);
|
show_room->setEnabled(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {
|
void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {
|
||||||
|
|
Loading…
Reference in a new issue