Merge pull request #7202 from Techjar/better-netplay-errors
Improve NetPlay connection error handling
This commit is contained in:
commit
28ca6fec9a
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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] {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue