Improve NetPlay connection error handling
This commit is contained in:
parent
f5730e1636
commit
a29cdb5713
|
@ -93,7 +93,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
|
||||||
|
|
||||||
if (m_client == nullptr)
|
if (m_client == nullptr)
|
||||||
{
|
{
|
||||||
PanicAlertT("Couldn't Create Client");
|
m_dialog->OnConnectionError(_trans("Could not create client."));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetAddress addr;
|
ENetAddress addr;
|
||||||
|
@ -104,7 +105,8 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
|
||||||
|
|
||||||
if (m_server == nullptr)
|
if (m_server == nullptr)
|
||||||
{
|
{
|
||||||
PanicAlertT("Couldn't create peer.");
|
m_dialog->OnConnectionError(_trans("Could not create peer."));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetEvent netEvent;
|
ENetEvent netEvent;
|
||||||
|
@ -119,14 +121,15 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PanicAlertT("Failed to Connect!");
|
m_dialog->OnConnectionError(_trans("Could not communicate with host."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (address.size() > NETPLAY_CODE_SIZE)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +177,7 @@ NetPlayClient::NetPlayClient(const std::string& address, const u16 port, NetPlay
|
||||||
if (connect_timer.GetTimeElapsed() > 5000)
|
if (connect_timer.GetTimeElapsed() > 5000)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PanicAlertT("Failed To Connect!");
|
m_dialog->OnConnectionError(_trans("Could not communicate with host."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,16 +212,17 @@ bool NetPlayClient::Connect()
|
||||||
switch (error)
|
switch (error)
|
||||||
{
|
{
|
||||||
case CON_ERR_SERVER_FULL:
|
case CON_ERR_SERVER_FULL:
|
||||||
PanicAlertT("The server is full!");
|
m_dialog->OnConnectionError(_trans("The server is full."));
|
||||||
break;
|
break;
|
||||||
case CON_ERR_VERSION_MISMATCH:
|
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;
|
break;
|
||||||
case CON_ERR_GAME_RUNNING:
|
case CON_ERR_GAME_RUNNING:
|
||||||
PanicAlertT("The server responded: the game is currently running!");
|
m_dialog->OnConnectionError(_trans("The game is currently running."));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PanicAlertT("The server sent an unknown error message!");
|
m_dialog->OnConnectionError(_trans("The server sent an unknown error message."));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ public:
|
||||||
virtual void OnPadBufferChanged(u32 buffer) = 0;
|
virtual void OnPadBufferChanged(u32 buffer) = 0;
|
||||||
virtual void OnDesync(u32 frame, const std::string& player) = 0;
|
virtual void OnDesync(u32 frame, const std::string& player) = 0;
|
||||||
virtual void OnConnectionLost() = 0;
|
virtual void OnConnectionLost() = 0;
|
||||||
|
virtual void OnConnectionError(const std::string& message) = 0;
|
||||||
virtual void OnTraversalError(TraversalClient::FailureReason error) = 0;
|
virtual void OnTraversalError(TraversalClient::FailureReason error) = 0;
|
||||||
virtual bool IsRecording() = 0;
|
virtual bool IsRecording() = 0;
|
||||||
virtual std::string FindGame(const std::string& game) = 0;
|
virtual std::string FindGame(const std::string& game) = 0;
|
||||||
|
|
|
@ -173,7 +173,7 @@ void NetPlayServer::ThreadFunc()
|
||||||
delete (PlayerId*)netEvent.peer->data;
|
delete (PlayerId*)netEvent.peer->data;
|
||||||
netEvent.peer->data = nullptr;
|
netEvent.peer->data = nullptr;
|
||||||
}
|
}
|
||||||
enet_peer_disconnect(accept_peer, 0);
|
enet_peer_disconnect_later(accept_peer, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1085,8 +1085,6 @@ bool MainWindow::NetPlayJoin()
|
||||||
|
|
||||||
if (!Settings::Instance().GetNetPlayClient()->IsConnected())
|
if (!Settings::Instance().GetNetPlayClient()->IsConnected())
|
||||||
{
|
{
|
||||||
QMessageBox::critical(nullptr, QObject::tr("Error"),
|
|
||||||
QObject::tr("Failed to connect to server"));
|
|
||||||
NetPlayQuit();
|
NetPlayQuit();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -558,6 +558,14 @@ void NetPlayDialog::OnConnectionLost()
|
||||||
DisplayMessage(tr("Lost connection to NetPlay server..."), "red");
|
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)
|
void NetPlayDialog::OnTraversalError(TraversalClient::FailureReason error)
|
||||||
{
|
{
|
||||||
QueueOnObject(this, [this, error] {
|
QueueOnObject(this, [this, error] {
|
||||||
|
|
|
@ -49,6 +49,7 @@ public:
|
||||||
void OnPadBufferChanged(u32 buffer) override;
|
void OnPadBufferChanged(u32 buffer) override;
|
||||||
void OnDesync(u32 frame, const std::string& player) override;
|
void OnDesync(u32 frame, const std::string& player) override;
|
||||||
void OnConnectionLost() override;
|
void OnConnectionLost() override;
|
||||||
|
void OnConnectionError(const std::string& message) override;
|
||||||
void OnTraversalError(TraversalClient::FailureReason error) override;
|
void OnTraversalError(TraversalClient::FailureReason error) override;
|
||||||
bool IsRecording() override;
|
bool IsRecording() override;
|
||||||
std::string FindGame(const std::string& game) override;
|
std::string FindGame(const std::string& game) override;
|
||||||
|
|
Loading…
Reference in New Issue