TraversalProto: Convert TraversalConnectFailedReason into an enum class

This commit is contained in:
Lioncash 2021-01-19 14:05:16 -05:00
parent 2021175809
commit 2f0fb2056e
6 changed files with 15 additions and 15 deletions

View File

@ -19,7 +19,7 @@ public:
virtual ~TraversalClientClient() = default; virtual ~TraversalClientClient() = default;
virtual void OnTraversalStateChanged() = 0; virtual void OnTraversalStateChanged() = 0;
virtual void OnConnectReady(ENetAddress addr) = 0; virtual void OnConnectReady(ENetAddress addr) = 0;
virtual void OnConnectFailed(u8 reason) = 0; virtual void OnConnectFailed(TraversalConnectFailedReason reason) = 0;
}; };
class TraversalClient class TraversalClient

View File

@ -34,11 +34,11 @@ enum
TraversalProtoVersion = 0 TraversalProtoVersion = 0
}; };
enum TraversalConnectFailedReason enum class TraversalConnectFailedReason : u8
{ {
TraversalConnectFailedClientDidntRespond = 0, ClientDidntRespond = 0,
TraversalConnectFailedClientFailure, ClientFailure,
TraversalConnectFailedNoSuchClient NoSuchClient,
}; };
#pragma pack(push, 1) #pragma pack(push, 1)
@ -88,7 +88,7 @@ struct TraversalPacket
struct struct
{ {
TraversalRequestId requestId; TraversalRequestId requestId;
u8 reason; TraversalConnectFailedReason reason;
} connectFailed; } connectFailed;
}; };
}; };

View File

@ -247,7 +247,7 @@ static void ResendPackets()
TraversalPacket* fail = AllocPacket(MakeSinAddr(p.first)); TraversalPacket* fail = AllocPacket(MakeSinAddr(p.first));
fail->type = TraversalPacketConnectFailed; fail->type = TraversalPacketConnectFailed;
fail->connectFailed.requestId = p.second; fail->connectFailed.requestId = p.second;
fail->connectFailed.reason = TraversalConnectFailedClientDidntRespond; fail->connectFailed.reason = TraversalConnectFailedReason::ClientDidntRespond;
} }
} }
@ -280,7 +280,7 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr)
{ {
ready->type = TraversalPacketConnectFailed; ready->type = TraversalPacketConnectFailed;
ready->connectFailed.requestId = info->misc; ready->connectFailed.requestId = info->misc;
ready->connectFailed.reason = TraversalConnectFailedClientFailure; ready->connectFailed.reason = TraversalConnectFailedReason::ClientFailure;
} }
} }
@ -332,7 +332,7 @@ static void HandlePacket(TraversalPacket* packet, sockaddr_in6* addr)
TraversalPacket* reply = AllocPacket(*addr); TraversalPacket* reply = AllocPacket(*addr);
reply->type = TraversalPacketConnectFailed; reply->type = TraversalPacketConnectFailed;
reply->connectFailed.requestId = packet->requestId; reply->connectFailed.requestId = packet->requestId;
reply->connectFailed.reason = TraversalConnectFailedNoSuchClient; reply->connectFailed.reason = TraversalConnectFailedReason::NoSuchClient;
} }
else else
{ {

View File

@ -1780,19 +1780,19 @@ void NetPlayClient::OnConnectReady(ENetAddress addr)
} }
// called from ---NETPLAY--- thread // called from ---NETPLAY--- thread
void NetPlayClient::OnConnectFailed(u8 reason) void NetPlayClient::OnConnectFailed(TraversalConnectFailedReason reason)
{ {
m_connecting = false; m_connecting = false;
m_connection_state = ConnectionState::Failure; m_connection_state = ConnectionState::Failure;
switch (reason) switch (reason)
{ {
case TraversalConnectFailedClientDidntRespond: case TraversalConnectFailedReason::ClientDidntRespond:
PanicAlertFmtT("Traversal server timed out connecting to the host"); PanicAlertFmtT("Traversal server timed out connecting to the host");
break; break;
case TraversalConnectFailedClientFailure: case TraversalConnectFailedReason::ClientFailure:
PanicAlertFmtT("Server rejected traversal attempt"); PanicAlertFmtT("Server rejected traversal attempt");
break; break;
case TraversalConnectFailedNoSuchClient: case TraversalConnectFailedReason::NoSuchClient:
PanicAlertFmtT("Invalid host"); PanicAlertFmtT("Invalid host");
break; break;
default: default:

View File

@ -125,7 +125,7 @@ public:
void OnTraversalStateChanged() override; void OnTraversalStateChanged() override;
void OnConnectReady(ENetAddress addr) override; void OnConnectReady(ENetAddress addr) override;
void OnConnectFailed(u8 reason) override; void OnConnectFailed(TraversalConnectFailedReason reason) override;
bool IsFirstInGamePad(int ingame_pad) const; bool IsFirstInGamePad(int ingame_pad) const;
int NumLocalPads() const; int NumLocalPads() const;

View File

@ -134,7 +134,7 @@ private:
void OnTraversalStateChanged() override; void OnTraversalStateChanged() override;
void OnConnectReady(ENetAddress) override {} void OnConnectReady(ENetAddress) override {}
void OnConnectFailed(u8) override {} void OnConnectFailed(TraversalConnectFailedReason) override {}
void UpdatePadMapping(); void UpdatePadMapping();
void UpdateWiimoteMapping(); void UpdateWiimoteMapping();
std::vector<std::pair<std::string, std::string>> GetInterfaceListInternal() const; std::vector<std::pair<std::string, std::string>> GetInterfaceListInternal() const;