TraversalClient: make FailureReason an enum class

This commit is contained in:
Michael M 2017-08-08 15:29:47 -07:00
parent 8b5ae7b0c7
commit 6faacbeea5
5 changed files with 18 additions and 18 deletions

View File

@ -16,8 +16,8 @@ static void GetRandomishBytes(u8* buf, size_t size)
} }
TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server, const u16 port) TraversalClient::TraversalClient(ENetHost* netHost, const std::string& server, const u16 port)
: m_NetHost(netHost), m_Client(nullptr), m_FailureReason(0), m_ConnectRequestId(0), : m_NetHost(netHost), m_Client(nullptr), m_ConnectRequestId(0), m_PendingConnect(false),
m_PendingConnect(false), m_Server(server), m_port(port), m_PingTime(0) m_Server(server), m_port(port), m_PingTime(0)
{ {
netHost->intercept = TraversalClient::InterceptCallback; netHost->intercept = TraversalClient::InterceptCallback;
@ -34,7 +34,7 @@ void TraversalClient::ReconnectToServer()
{ {
if (enet_address_set_host(&m_ServerAddress, m_Server.c_str())) if (enet_address_set_host(&m_ServerAddress, m_Server.c_str()))
{ {
OnFailure(BadHost); OnFailure(FailureReason::BadHost);
return; return;
} }
m_ServerAddress.port = m_port; m_ServerAddress.port = m_port;
@ -123,7 +123,7 @@ void TraversalClient::HandleServerPacket(TraversalPacket* packet)
case TraversalPacketAck: case TraversalPacketAck:
if (!packet->ack.ok) if (!packet->ack.ok)
{ {
OnFailure(ServerForgotAboutUs); OnFailure(FailureReason::ServerForgotAboutUs);
break; break;
} }
for (auto it = m_OutgoingTraversalPackets.begin(); it != m_OutgoingTraversalPackets.end(); ++it) for (auto it = m_OutgoingTraversalPackets.begin(); it != m_OutgoingTraversalPackets.end(); ++it)
@ -140,7 +140,7 @@ void TraversalClient::HandleServerPacket(TraversalPacket* packet)
break; break;
if (!packet->helloFromServer.ok) if (!packet->helloFromServer.ok)
{ {
OnFailure(VersionTooOld); OnFailure(FailureReason::VersionTooOld);
break; break;
} }
m_HostId = packet->helloFromServer.yourHostId; m_HostId = packet->helloFromServer.yourHostId;
@ -199,7 +199,7 @@ void TraversalClient::HandleServerPacket(TraversalPacket* packet)
buf.data = &ack; buf.data = &ack;
buf.dataLength = sizeof(ack); buf.dataLength = sizeof(ack);
if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1) if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1)
OnFailure(SocketSendError); OnFailure(FailureReason::SocketSendError);
} }
} }
@ -220,7 +220,7 @@ void TraversalClient::ResendPacket(OutgoingTraversalPacketInfo* info)
buf.data = &info->packet; buf.data = &info->packet;
buf.dataLength = sizeof(info->packet); buf.dataLength = sizeof(info->packet);
if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1) if (enet_socket_send(m_NetHost->socket, &m_ServerAddress, &buf, 1) == -1)
OnFailure(SocketSendError); OnFailure(FailureReason::SocketSendError);
} }
void TraversalClient::HandleResends() void TraversalClient::HandleResends()
@ -232,7 +232,7 @@ void TraversalClient::HandleResends()
{ {
if (tpi.tries >= 5) if (tpi.tries >= 5)
{ {
OnFailure(ResendTimeout); OnFailure(FailureReason::ResendTimeout);
m_OutgoingTraversalPackets.clear(); m_OutgoingTraversalPackets.clear();
break; break;
} }

View File

@ -28,7 +28,7 @@ public:
Connected, Connected,
Failure Failure
}; };
enum FailureReason enum class FailureReason
{ {
BadHost = 0x300, BadHost = 0x300,
VersionTooOld, VersionTooOld,
@ -50,7 +50,7 @@ public:
TraversalClientClient* m_Client; TraversalClientClient* m_Client;
TraversalHostId m_HostId; TraversalHostId m_HostId;
State m_State; State m_State;
int m_FailureReason; FailureReason m_FailureReason;
private: private:
struct OutgoingTraversalPacketInfo struct OutgoingTraversalPacketInfo

View File

@ -34,7 +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 OnTraversalError(int 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;
virtual void ShowMD5Dialog(const std::string& file_identifier) = 0; virtual void ShowMD5Dialog(const std::string& file_identifier) = 0;

View File

@ -457,19 +457,19 @@ void NetPlayDialog::OnConnectionLost()
GetEventHandler()->AddPendingEvent(evt); GetEventHandler()->AddPendingEvent(evt);
} }
void NetPlayDialog::OnTraversalError(int error) void NetPlayDialog::OnTraversalError(TraversalClient::FailureReason error)
{ {
switch (error) switch (error)
{ {
case TraversalClient::BadHost: case TraversalClient::FailureReason::BadHost:
PanicAlertT("Couldn't look up central server"); PanicAlertT("Couldn't look up central server");
break; break;
case TraversalClient::VersionTooOld: case TraversalClient::FailureReason::VersionTooOld:
PanicAlertT("Dolphin is too old for traversal server"); PanicAlertT("Dolphin is too old for traversal server");
break; break;
case TraversalClient::ServerForgotAboutUs: case TraversalClient::FailureReason::ServerForgotAboutUs:
case TraversalClient::SocketSendError: case TraversalClient::FailureReason::SocketSendError:
case TraversalClient::ResendTimeout: case TraversalClient::FailureReason::ResendTimeout:
wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_TRAVERSAL_CONNECTION_ERROR); wxThreadEvent evt(wxEVT_THREAD, NP_GUI_EVT_TRAVERSAL_CONNECTION_ERROR);
GetEventHandler()->AddPendingEvent(evt); GetEventHandler()->AddPendingEvent(evt);
break; break;

View File

@ -102,7 +102,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 OnTraversalError(int error) override; void OnTraversalError(TraversalClient::FailureReason error) override;
static NetPlayDialog*& GetInstance() { return npd; } static NetPlayDialog*& GetInstance() { return npd; }
static NetPlayClient*& GetNetPlayClient() { return netplay_client; } static NetPlayClient*& GetNetPlayClient() { return netplay_client; }