diff --git a/Source/Core/Core/NetPlayClient.cpp b/Source/Core/Core/NetPlayClient.cpp index 810553f6c2..be937c5299 100644 --- a/Source/Core/Core/NetPlayClient.cpp +++ b/Source/Core/Core/NetPlayClient.cpp @@ -93,7 +93,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay if (m_client == nullptr) { - PanicAlertT("Couldn't Create Client"); + m_dialog->OnConnectionError(_trans("Could not create client.")); + return; } ENetAddress addr; @@ -104,7 +105,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay if (m_server == nullptr) { - PanicAlertT("Couldn't create peer."); + m_dialog->OnConnectionError(_trans("Could not create peer.")); + return; } ENetEvent netEvent; @@ -119,14 +121,15 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay } else { - PanicAlertT("Failed to Connect!"); + m_dialog->OnConnectionError(_trans("Could not communicate with host.")); } } else { if (address.size() > NETPLAY_CODE_SIZE) { - PanicAlertT("Host code size is to large.\nPlease recheck that you have the correct code"); + m_dialog->OnConnectionError( + _trans("Host code size is too large.\nPlease recheck that you have the correct code.")); return; } @@ -174,7 +177,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay if (connect_timer.GetTimeElapsed() > 5000) break; } - PanicAlertT("Failed To Connect!"); + m_dialog->OnConnectionError(_trans("Could not communicate with host.")); } } @@ -209,16 +212,17 @@ bool NetPlayClient::Connect() switch (error) { case CON_ERR_SERVER_FULL: - PanicAlertT("The server is full!"); + m_dialog->OnConnectionError(_trans("The server is full.")); break; case CON_ERR_VERSION_MISMATCH: - PanicAlertT("The server and client's NetPlay versions are incompatible!"); + m_dialog->OnConnectionError( + _trans("The server and client's NetPlay versions are incompatible.")); break; case CON_ERR_GAME_RUNNING: - PanicAlertT("The server responded: the game is currently running!"); + m_dialog->OnConnectionError(_trans("The game is currently running.")); break; default: - PanicAlertT("The server sent an unknown error message!"); + m_dialog->OnConnectionError(_trans("The server sent an unknown error message.")); break; } diff --git a/Source/Core/Core/NetPlayClient.h b/Source/Core/Core/NetPlayClient.h index cf7889abf1..4fc401e950 100644 --- a/Source/Core/Core/NetPlayClient.h +++ b/Source/Core/Core/NetPlayClient.h @@ -34,6 +34,7 @@ public: virtual void OnPadBufferChanged(u32 buffer) = 0; virtual void OnDesync(u32 frame, const std::string& player) = 0; virtual void OnConnectionLost() = 0; + virtual void OnConnectionError(const std::string& message) = 0; virtual void OnTraversalError(TraversalClient::FailureReason error) = 0; virtual bool IsRecording() = 0; virtual std::string FindGame(const std::string& game) = 0; diff --git a/Source/Core/Core/NetPlayServer.cpp b/Source/Core/Core/NetPlayServer.cpp index 783cf06409..84eb1d6ee0 100644 --- a/Source/Core/Core/NetPlayServer.cpp +++ b/Source/Core/Core/NetPlayServer.cpp @@ -173,7 +173,7 @@ void NetPlayServer::ThreadFunc() delete (PlayerId*)netEvent.peer->data; netEvent.peer->data = nullptr; } - enet_peer_disconnect(accept_peer, 0); + enet_peer_disconnect_later(accept_peer, 0); } } break; diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 8bb919079b..73954c225f 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -1094,8 +1094,6 @@ bool MainWindow::NetPlayJoin() if (!Settings::Instance().GetNetPlayClient()->IsConnected()) { - QMessageBox::critical(nullptr, QObject::tr("Error"), - QObject::tr("Failed to connect to server")); NetPlayQuit(); return false; } diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp index 69c23fc892..0a7caf45e8 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.cpp @@ -578,6 +578,14 @@ void NetPlayDialog::OnConnectionLost() DisplayMessage(tr("Lost connection to NetPlay server..."), "red"); } +void NetPlayDialog::OnConnectionError(const std::string& message) +{ + QueueOnObject(this, [this, message] { + QMessageBox::critical(this, tr("Error"), + tr("Failed to connect to server: %1").arg(tr(message.c_str()))); + }); +} + void NetPlayDialog::OnTraversalError(TraversalClient::FailureReason error) { QueueOnObject(this, [this, error] { diff --git a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h index b62e689049..4c1013eeb5 100644 --- a/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h +++ b/Source/Core/DolphinQt2/NetPlay/NetPlayDialog.h @@ -49,6 +49,7 @@ public: void OnPadBufferChanged(u32 buffer) override; void OnDesync(u32 frame, const std::string& player) override; void OnConnectionLost() override; + void OnConnectionError(const std::string& message) override; void OnTraversalError(TraversalClient::FailureReason error) override; bool IsRecording() override; std::string FindGame(const std::string& game) override;