mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 15:31:17 +01:00
NetPlayProto: Turn connection error enum into an enum class
Continues the migration off the MessageId type alias
This commit is contained in:
parent
dedd0b7ba1
commit
a034f378a0
@ -244,25 +244,25 @@ bool NetPlayClient::Connect()
|
||||
return false;
|
||||
}
|
||||
|
||||
MessageId error;
|
||||
ConnectionError error;
|
||||
rpac >> error;
|
||||
|
||||
// got error message
|
||||
if (error)
|
||||
if (error != ConnectionError::NoError)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case CON_ERR_SERVER_FULL:
|
||||
case ConnectionError::ServerFull:
|
||||
m_dialog->OnConnectionError(_trans("The server is full."));
|
||||
break;
|
||||
case CON_ERR_VERSION_MISMATCH:
|
||||
case ConnectionError::VersionMismatch:
|
||||
m_dialog->OnConnectionError(
|
||||
_trans("The server and client's NetPlay versions are incompatible."));
|
||||
break;
|
||||
case CON_ERR_GAME_RUNNING:
|
||||
case ConnectionError::GameRunning:
|
||||
m_dialog->OnConnectionError(_trans("The game is currently running."));
|
||||
break;
|
||||
case CON_ERR_NAME_TOO_LONG:
|
||||
case ConnectionError::NameTooLong:
|
||||
m_dialog->OnConnectionError(_trans("Nickname is too long."));
|
||||
break;
|
||||
default:
|
||||
|
@ -179,12 +179,13 @@ enum class MessageID : u8
|
||||
SyncCodes = 0xF2,
|
||||
};
|
||||
|
||||
enum
|
||||
enum class ConnectionError : u8
|
||||
{
|
||||
CON_ERR_SERVER_FULL = 1,
|
||||
CON_ERR_GAME_RUNNING = 2,
|
||||
CON_ERR_VERSION_MISMATCH = 3,
|
||||
CON_ERR_NAME_TOO_LONG = 4
|
||||
NoError = 0,
|
||||
ServerFull = 1,
|
||||
GameRunning = 2,
|
||||
VersionMismatch = 3,
|
||||
NameTooLong = 4
|
||||
};
|
||||
|
||||
enum class SyncSaveDataID : u8
|
||||
|
@ -297,16 +297,16 @@ void NetPlayServer::ThreadFunc()
|
||||
if (!netEvent.peer->data)
|
||||
{
|
||||
// uninitialized client, we'll assume this is their initialization packet
|
||||
unsigned int error;
|
||||
ConnectionError error;
|
||||
{
|
||||
std::lock_guard lkg(m_crit.game);
|
||||
error = OnConnect(netEvent.peer, rpac);
|
||||
}
|
||||
|
||||
if (error)
|
||||
if (error != ConnectionError::NoError)
|
||||
{
|
||||
sf::Packet spac;
|
||||
spac << static_cast<MessageId>(error);
|
||||
spac << error;
|
||||
// don't need to lock, this client isn't in the client map
|
||||
Send(netEvent.peer, spac);
|
||||
|
||||
@ -374,7 +374,7 @@ static void SendSyncIdentifier(sf::Packet& spac, const SyncIdentifier& sync_iden
|
||||
}
|
||||
|
||||
// called from ---NETPLAY--- thread
|
||||
unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||
ConnectionError NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||
{
|
||||
// give new client first available id
|
||||
PlayerId pid = 1;
|
||||
@ -392,15 +392,15 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||
rpac >> npver;
|
||||
// Dolphin netplay version
|
||||
if (npver != Common::scm_rev_git_str)
|
||||
return CON_ERR_VERSION_MISMATCH;
|
||||
return ConnectionError::VersionMismatch;
|
||||
|
||||
// game is currently running or game start is pending
|
||||
if (m_is_running || m_start_pending)
|
||||
return CON_ERR_GAME_RUNNING;
|
||||
return ConnectionError::GameRunning;
|
||||
|
||||
// too many players
|
||||
if (m_players.size() >= 255)
|
||||
return CON_ERR_SERVER_FULL;
|
||||
return ConnectionError::ServerFull;
|
||||
|
||||
Client player;
|
||||
player.pid = pid;
|
||||
@ -410,7 +410,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||
rpac >> player.name;
|
||||
|
||||
if (StringUTF8CodePointCount(player.name) > MAX_NAME_LENGTH)
|
||||
return CON_ERR_NAME_TOO_LONG;
|
||||
return ConnectionError::NameTooLong;
|
||||
|
||||
// cause pings to be updated
|
||||
m_update_pings = true;
|
||||
@ -488,7 +488,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
|
||||
UpdateWiimoteMapping();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return ConnectionError::NoError;
|
||||
}
|
||||
|
||||
// called from ---NETPLAY--- thread
|
||||
|
@ -129,7 +129,7 @@ private:
|
||||
void SendToClients(const sf::Packet& packet, PlayerId skip_pid = 0,
|
||||
u8 channel_id = DEFAULT_CHANNEL);
|
||||
void Send(ENetPeer* socket, const sf::Packet& packet, u8 channel_id = DEFAULT_CHANNEL);
|
||||
unsigned int OnConnect(ENetPeer* socket, sf::Packet& rpac);
|
||||
ConnectionError OnConnect(ENetPeer* socket, sf::Packet& rpac);
|
||||
unsigned int OnDisconnect(const Client& player);
|
||||
unsigned int OnData(sf::Packet& packet, Client& player);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user