NetPlayProto: Turn Sync-related enums into enum classes

This commit is contained in:
Lioncash 2021-09-22 14:49:41 -04:00
parent af4aaf4609
commit dedd0b7ba1
3 changed files with 48 additions and 48 deletions

View File

@ -981,7 +981,7 @@ void NetPlayClient::OnSyncGCSRAM(sf::Packet& packet)
void NetPlayClient::OnSyncSaveData(sf::Packet& packet) void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
{ {
MessageId sub_id; SyncSaveDataID sub_id;
packet >> sub_id; packet >> sub_id;
if (m_local_player->IsHost()) if (m_local_player->IsHost())
@ -989,23 +989,23 @@ void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
switch (sub_id) switch (sub_id)
{ {
case SYNC_SAVE_DATA_NOTIFY: case SyncSaveDataID::Notify:
OnSyncSaveDataNotify(packet); OnSyncSaveDataNotify(packet);
break; break;
case SYNC_SAVE_DATA_RAW: case SyncSaveDataID::RawData:
OnSyncSaveDataRaw(packet); OnSyncSaveDataRaw(packet);
break; break;
case SYNC_SAVE_DATA_GCI: case SyncSaveDataID::GCIData:
OnSyncSaveDataGCI(packet); OnSyncSaveDataGCI(packet);
break; break;
case SYNC_SAVE_DATA_WII: case SyncSaveDataID::WiiData:
OnSyncSaveDataWii(packet); OnSyncSaveDataWii(packet);
break; break;
case SYNC_SAVE_DATA_GBA: case SyncSaveDataID::GBAData:
OnSyncSaveDataGBA(packet); OnSyncSaveDataGBA(packet);
break; break;
@ -1239,29 +1239,29 @@ void NetPlayClient::OnSyncSaveDataGBA(sf::Packet& packet)
void NetPlayClient::OnSyncCodes(sf::Packet& packet) void NetPlayClient::OnSyncCodes(sf::Packet& packet)
{ {
// Recieve Data Packet // Recieve Data Packet
MessageId sub_id; SyncCodeID sub_id;
packet >> sub_id; packet >> sub_id;
// Check Which Operation to Perform with This Packet // Check Which Operation to Perform with This Packet
switch (sub_id) switch (sub_id)
{ {
case SYNC_CODES_NOTIFY: case SyncCodeID::Notify:
OnSyncCodesNotify(); OnSyncCodesNotify();
break; break;
case SYNC_CODES_NOTIFY_GECKO: case SyncCodeID::NotifyGecko:
OnSyncCodesNotifyGecko(packet); OnSyncCodesNotifyGecko(packet);
break; break;
case SYNC_CODES_DATA_GECKO: case SyncCodeID::GeckoData:
OnSyncCodesDataGecko(packet); OnSyncCodesDataGecko(packet);
break; break;
case SYNC_CODES_NOTIFY_AR: case SyncCodeID::NotifyAR:
OnSyncCodesNotifyAR(packet); OnSyncCodesNotifyAR(packet);
break; break;
case SYNC_CODES_DATA_AR: case SyncCodeID::ARData:
OnSyncCodesDataAR(packet); OnSyncCodesDataAR(packet);
break; break;
@ -1761,7 +1761,7 @@ void NetPlayClient::SyncSaveDataResponse(const bool success)
{ {
sf::Packet response_packet; sf::Packet response_packet;
response_packet << MessageID::SyncSaveData; response_packet << MessageID::SyncSaveData;
response_packet << static_cast<MessageId>(SYNC_SAVE_DATA_SUCCESS); response_packet << SyncSaveDataID::Success;
Send(response_packet); Send(response_packet);
} }
@ -1770,7 +1770,7 @@ void NetPlayClient::SyncSaveDataResponse(const bool success)
{ {
sf::Packet response_packet; sf::Packet response_packet;
response_packet << MessageID::SyncSaveData; response_packet << MessageID::SyncSaveData;
response_packet << static_cast<MessageId>(SYNC_SAVE_DATA_FAILURE); response_packet << SyncSaveDataID::Failure;
Send(response_packet); Send(response_packet);
} }
@ -1785,7 +1785,7 @@ void NetPlayClient::SyncCodeResponse(const bool success)
sf::Packet response_packet; sf::Packet response_packet;
response_packet << MessageID::SyncCodes; response_packet << MessageID::SyncCodes;
response_packet << static_cast<MessageId>(SYNC_CODES_FAILURE); response_packet << SyncCodeID::Failure;
Send(response_packet); Send(response_packet);
return; return;
@ -1798,7 +1798,7 @@ void NetPlayClient::SyncCodeResponse(const bool success)
sf::Packet response_packet; sf::Packet response_packet;
response_packet << MessageID::SyncCodes; response_packet << MessageID::SyncCodes;
response_packet << static_cast<MessageId>(SYNC_CODES_SUCCESS); response_packet << SyncCodeID::Success;
Send(response_packet); Send(response_packet);
} }

View File

@ -187,26 +187,26 @@ enum
CON_ERR_NAME_TOO_LONG = 4 CON_ERR_NAME_TOO_LONG = 4
}; };
enum enum class SyncSaveDataID : u8
{ {
SYNC_SAVE_DATA_NOTIFY = 0, Notify = 0,
SYNC_SAVE_DATA_SUCCESS = 1, Success = 1,
SYNC_SAVE_DATA_FAILURE = 2, Failure = 2,
SYNC_SAVE_DATA_RAW = 3, RawData = 3,
SYNC_SAVE_DATA_GCI = 4, GCIData = 4,
SYNC_SAVE_DATA_WII = 5, WiiData = 5,
SYNC_SAVE_DATA_GBA = 6 GBAData = 6
}; };
enum enum class SyncCodeID : u8
{ {
SYNC_CODES_NOTIFY = 0, Notify = 0,
SYNC_CODES_NOTIFY_GECKO = 1, NotifyGecko = 1,
SYNC_CODES_NOTIFY_AR = 2, NotifyAR = 2,
SYNC_CODES_DATA_GECKO = 3, GeckoData = 3,
SYNC_CODES_DATA_AR = 4, ARData = 4,
SYNC_CODES_SUCCESS = 5, Success = 5,
SYNC_CODES_FAILURE = 6, Failure = 6,
}; };
constexpr u32 MAX_NAME_LENGTH = 30; constexpr u32 MAX_NAME_LENGTH = 30;

View File

@ -1105,12 +1105,12 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
case MessageID::SyncSaveData: case MessageID::SyncSaveData:
{ {
MessageId sub_id; SyncSaveDataID sub_id;
packet >> sub_id; packet >> sub_id;
switch (sub_id) switch (sub_id)
{ {
case SYNC_SAVE_DATA_SUCCESS: case SyncSaveDataID::Success:
{ {
if (m_start_pending) if (m_start_pending)
{ {
@ -1127,7 +1127,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
} }
break; break;
case SYNC_SAVE_DATA_FAILURE: case SyncSaveDataID::Failure:
{ {
m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize.", player.name)); m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize.", player.name));
m_dialog->OnGameStartAborted(); m_dialog->OnGameStartAborted();
@ -1148,13 +1148,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
case MessageID::SyncCodes: case MessageID::SyncCodes:
{ {
// Receive Status of Code Sync // Receive Status of Code Sync
MessageId sub_id; SyncCodeID sub_id;
packet >> sub_id; packet >> sub_id;
// Check If Code Sync was successful or not // Check If Code Sync was successful or not
switch (sub_id) switch (sub_id)
{ {
case SYNC_CODES_SUCCESS: case SyncCodeID::Success:
{ {
if (m_start_pending) if (m_start_pending)
{ {
@ -1170,7 +1170,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
} }
break; break;
case SYNC_CODES_FAILURE: case SyncCodeID::Failure:
{ {
m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize codes.", player.name)); m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize codes.", player.name));
m_dialog->OnGameStartAborted(); m_dialog->OnGameStartAborted();
@ -1620,7 +1620,7 @@ bool NetPlayServer::SyncSaveData()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncSaveData; pac << MessageID::SyncSaveData;
pac << static_cast<MessageId>(SYNC_SAVE_DATA_NOTIFY); pac << SyncSaveDataID::Notify;
pac << save_count; pac << save_count;
// send this on the chunked data channel to ensure it's sequenced properly // send this on the chunked data channel to ensure it's sequenced properly
@ -1657,7 +1657,7 @@ bool NetPlayServer::SyncSaveData()
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncSaveData; pac << MessageID::SyncSaveData;
pac << static_cast<MessageId>(SYNC_SAVE_DATA_RAW); pac << SyncSaveDataID::RawData;
pac << is_slot_a << region << size_override; pac << is_slot_a << region << size_override;
if (File::Exists(path)) if (File::Exists(path))
@ -1682,7 +1682,7 @@ bool NetPlayServer::SyncSaveData()
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncSaveData; pac << MessageID::SyncSaveData;
pac << static_cast<MessageId>(SYNC_SAVE_DATA_GCI); pac << SyncSaveDataID::GCIData;
pac << is_slot_a; pac << is_slot_a;
if (File::IsDirectory(path)) if (File::IsDirectory(path))
@ -1734,7 +1734,7 @@ bool NetPlayServer::SyncSaveData()
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncSaveData; pac << MessageID::SyncSaveData;
pac << static_cast<MessageId>(SYNC_SAVE_DATA_WII); pac << SyncSaveDataID::WiiData;
// Shove the Mii data into the start the packet // Shove the Mii data into the start the packet
{ {
@ -1825,7 +1825,7 @@ bool NetPlayServer::SyncSaveData()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncSaveData; pac << MessageID::SyncSaveData;
pac << static_cast<MessageId>(SYNC_SAVE_DATA_GBA); pac << SyncSaveDataID::GBAData;
pac << static_cast<u8>(i); pac << static_cast<u8>(i);
std::string path; std::string path;
@ -1882,7 +1882,7 @@ bool NetPlayServer::SyncCodes()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncCodes; pac << MessageID::SyncCodes;
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY); pac << SyncCodeID::Notify;
SendAsyncToClients(std::move(pac)); SendAsyncToClients(std::move(pac));
} }
// Sync Gecko Codes // Sync Gecko Codes
@ -1910,7 +1910,7 @@ bool NetPlayServer::SyncCodes()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncCodes; pac << MessageID::SyncCodes;
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY_GECKO); pac << SyncCodeID::NotifyGecko;
pac << codelines; pac << codelines;
SendAsyncToClients(std::move(pac)); SendAsyncToClients(std::move(pac));
} }
@ -1919,7 +1919,7 @@ bool NetPlayServer::SyncCodes()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncCodes; pac << MessageID::SyncCodes;
pac << static_cast<MessageId>(SYNC_CODES_DATA_GECKO); pac << SyncCodeID::GeckoData;
// Iterate through the active code vector and send each codeline // Iterate through the active code vector and send each codeline
for (const Gecko::GeckoCode& active_code : s_active_codes) for (const Gecko::GeckoCode& active_code : s_active_codes)
{ {
@ -1960,7 +1960,7 @@ bool NetPlayServer::SyncCodes()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncCodes; pac << MessageID::SyncCodes;
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY_AR); pac << SyncCodeID::NotifyAR;
pac << codelines; pac << codelines;
SendAsyncToClients(std::move(pac)); SendAsyncToClients(std::move(pac));
} }
@ -1969,7 +1969,7 @@ bool NetPlayServer::SyncCodes()
{ {
sf::Packet pac; sf::Packet pac;
pac << MessageID::SyncCodes; pac << MessageID::SyncCodes;
pac << static_cast<MessageId>(SYNC_CODES_DATA_AR); pac << SyncCodeID::ARData;
// Iterate through the active code vector and send each codeline // Iterate through the active code vector and send each codeline
for (const ActionReplay::ARCode& active_code : s_active_codes) for (const ActionReplay::ARCode& active_code : s_active_codes)
{ {