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