Merge pull request #10118 from lioncash/messageid

NetPlayProto: Remove lots of casts to MessageId when inserting enum values into packets
This commit is contained in:
Léo Lam 2021-10-13 02:27:52 +02:00 committed by GitHub
commit f19da1cf92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 294 additions and 299 deletions

View File

@ -3,18 +3,37 @@
#pragma once
#include <type_traits>
#include <SFML/Network/Packet.hpp>
#include "Common/CommonTypes.h"
#include "Common/Swap.h"
namespace sf
{
class Packet;
}
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u16>& data);
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u32>& data);
sf::Packet& operator>>(sf::Packet& packet, Common::BigEndianValue<u64>& data);
template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>>* = nullptr>
sf::Packet& operator<<(sf::Packet& packet, Enum e)
{
using Underlying = std::underlying_type_t<Enum>;
packet << static_cast<Underlying>(e);
return packet;
}
template <typename Enum, std::enable_if_t<std::is_enum_v<Enum>>* = nullptr>
sf::Packet& operator>>(sf::Packet& packet, Enum& e)
{
using Underlying = std::underlying_type_t<Enum>;
Underlying value{};
packet >> value;
e = static_cast<Enum>(value);
return packet;
}
namespace Common
{
u64 PacketReadU64(sf::Packet& packet);

View File

@ -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:
@ -313,143 +313,143 @@ static void ReceiveSyncIdentifier(sf::Packet& spac, SyncIdentifier& sync_identif
// called from ---NETPLAY--- thread
void NetPlayClient::OnData(sf::Packet& packet)
{
MessageId mid;
MessageID mid;
packet >> mid;
INFO_LOG_FMT(NETPLAY, "Got server message: {:x}", mid);
switch (mid)
{
case NP_MSG_PLAYER_JOIN:
case MessageID::PlayerJoin:
OnPlayerJoin(packet);
break;
case NP_MSG_PLAYER_LEAVE:
case MessageID::PlayerLeave:
OnPlayerLeave(packet);
break;
case NP_MSG_CHAT_MESSAGE:
case MessageID::ChatMessage:
OnChatMessage(packet);
break;
case NP_MSG_CHUNKED_DATA_START:
case MessageID::ChunkedDataStart:
OnChunkedDataStart(packet);
break;
case NP_MSG_CHUNKED_DATA_END:
case MessageID::ChunkedDataEnd:
OnChunkedDataEnd(packet);
break;
case NP_MSG_CHUNKED_DATA_PAYLOAD:
case MessageID::ChunkedDataPayload:
OnChunkedDataPayload(packet);
break;
case NP_MSG_CHUNKED_DATA_ABORT:
case MessageID::ChunkedDataAbort:
OnChunkedDataAbort(packet);
break;
case NP_MSG_PAD_MAPPING:
case MessageID::PadMapping:
OnPadMapping(packet);
break;
case NP_MSG_GBA_CONFIG:
case MessageID::GBAConfig:
OnGBAConfig(packet);
break;
case NP_MSG_WIIMOTE_MAPPING:
case MessageID::WiimoteMapping:
OnWiimoteMapping(packet);
break;
case NP_MSG_PAD_DATA:
case MessageID::PadData:
OnPadData(packet);
break;
case NP_MSG_PAD_HOST_DATA:
case MessageID::PadHostData:
OnPadHostData(packet);
break;
case NP_MSG_WIIMOTE_DATA:
case MessageID::WiimoteData:
OnWiimoteData(packet);
break;
case NP_MSG_PAD_BUFFER:
case MessageID::PadBuffer:
OnPadBuffer(packet);
break;
case NP_MSG_HOST_INPUT_AUTHORITY:
case MessageID::HostInputAuthority:
OnHostInputAuthority(packet);
break;
case NP_MSG_GOLF_SWITCH:
case MessageID::GolfSwitch:
OnGolfSwitch(packet);
break;
case NP_MSG_GOLF_PREPARE:
case MessageID::GolfPrepare:
OnGolfPrepare(packet);
break;
case NP_MSG_CHANGE_GAME:
case MessageID::ChangeGame:
OnChangeGame(packet);
break;
case NP_MSG_GAME_STATUS:
case MessageID::GameStatus:
OnGameStatus(packet);
break;
case NP_MSG_START_GAME:
case MessageID::StartGame:
OnStartGame(packet);
break;
case NP_MSG_STOP_GAME:
case NP_MSG_DISABLE_GAME:
case MessageID::StopGame:
case MessageID::DisableGame:
OnStopGame(packet);
break;
case NP_MSG_POWER_BUTTON:
case MessageID::PowerButton:
OnPowerButton();
break;
case NP_MSG_PING:
case MessageID::Ping:
OnPing(packet);
break;
case NP_MSG_PLAYER_PING_DATA:
case MessageID::PlayerPingData:
OnPlayerPingData(packet);
break;
case NP_MSG_DESYNC_DETECTED:
case MessageID::DesyncDetected:
OnDesyncDetected(packet);
break;
case NP_MSG_SYNC_GC_SRAM:
case MessageID::SyncGCSRAM:
OnSyncGCSRAM(packet);
break;
case NP_MSG_SYNC_SAVE_DATA:
case MessageID::SyncSaveData:
OnSyncSaveData(packet);
break;
case NP_MSG_SYNC_CODES:
case MessageID::SyncCodes:
OnSyncCodes(packet);
break;
case NP_MSG_COMPUTE_MD5:
case MessageID::ComputeMD5:
OnComputeMD5(packet);
break;
case NP_MSG_MD5_PROGRESS:
case MessageID::MD5Progress:
OnMD5Progress(packet);
break;
case NP_MSG_MD5_RESULT:
case MessageID::MD5Result:
OnMD5Result(packet);
break;
case NP_MSG_MD5_ERROR:
case MessageID::MD5Error:
OnMD5Error(packet);
break;
case NP_MSG_MD5_ABORT:
case MessageID::MD5Abort:
OnMD5Abort();
break;
@ -547,7 +547,7 @@ void NetPlayClient::OnChunkedDataEnd(sf::Packet& packet)
m_dialog->HideChunkedProgressDialog();
sf::Packet complete_packet;
complete_packet << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_COMPLETE);
complete_packet << MessageID::ChunkedDataComplete;
complete_packet << cid;
Send(complete_packet, CHUNKED_DATA_CHANNEL);
}
@ -572,7 +572,7 @@ void NetPlayClient::OnChunkedDataPayload(sf::Packet& packet)
m_dialog->SetChunkedProgress(m_local_player->pid, data_packet.getDataSize());
sf::Packet progress_packet;
progress_packet << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_PROGRESS);
progress_packet << MessageID::ChunkedDataProgress;
progress_packet << cid;
progress_packet << sf::Uint64{data_packet.getDataSize()};
Send(progress_packet, CHUNKED_DATA_CHANNEL);
@ -731,13 +731,13 @@ void NetPlayClient::OnGolfSwitch(sf::Packet& packet)
if (m_local_player->pid == previous_golfer)
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_RELEASE);
spac << MessageID::GolfRelease;
Send(spac);
}
else if (m_local_player->pid == pid)
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_ACQUIRE);
spac << MessageID::GolfAcquire;
Send(spac);
// Pads are already calibrated so we can just ignore this
@ -771,7 +771,7 @@ void NetPlayClient::OnChangeGame(sf::Packet& packet)
SendGameStatus();
sf::Packet client_capabilities_packet;
client_capabilities_packet << static_cast<MessageId>(NP_MSG_CLIENT_CAPABILITIES);
client_capabilities_packet << MessageID::ClientCapabilities;
client_capabilities_packet << ExpansionInterface::CEXIIPL::HasIPLDump();
client_capabilities_packet << Config::Get(Config::SESSION_USE_FMA);
Send(client_capabilities_packet);
@ -784,10 +784,7 @@ void NetPlayClient::OnGameStatus(sf::Packet& packet)
{
std::lock_guard lkp(m_crit.players);
Player& player = m_players[pid];
u32 status;
packet >> status;
player.game_status = static_cast<SyncIdentifierComparison>(status);
packet >> m_players[pid].game_status;
}
m_dialog->Update();
@ -797,19 +794,12 @@ void NetPlayClient::OnStartGame(sf::Packet& packet)
{
{
std::lock_guard lkg(m_crit.game);
packet >> m_current_game;
packet >> m_net_settings.m_CPUthread;
INFO_LOG_FMT(NETPLAY, "Start of game {}", m_selected_game.game_id);
{
std::underlying_type_t<PowerPC::CPUCore> core;
if (packet >> core)
m_net_settings.m_CPUcore = static_cast<PowerPC::CPUCore>(core);
else
m_net_settings.m_CPUcore = PowerPC::CPUCore::CachedInterpreter;
}
packet >> m_current_game;
packet >> m_net_settings.m_CPUthread;
packet >> m_net_settings.m_CPUcore;
packet >> m_net_settings.m_EnableCheats;
packet >> m_net_settings.m_SelectedLanguage;
packet >> m_net_settings.m_OverrideRegionSettings;
@ -819,24 +809,14 @@ void NetPlayClient::OnStartGame(sf::Packet& packet)
packet >> m_net_settings.m_RAMOverrideEnable;
packet >> m_net_settings.m_Mem1Size;
packet >> m_net_settings.m_Mem2Size;
{
std::underlying_type_t<DiscIO::Region> tmp;
packet >> tmp;
m_net_settings.m_FallbackRegion = static_cast<DiscIO::Region>(tmp);
}
packet >> m_net_settings.m_FallbackRegion;
packet >> m_net_settings.m_AllowSDWrites;
packet >> m_net_settings.m_CopyWiiSave;
packet >> m_net_settings.m_OCEnable;
packet >> m_net_settings.m_OCFactor;
for (auto& device : m_net_settings.m_EXIDevice)
{
int tmp;
packet >> tmp;
device = static_cast<ExpansionInterface::TEXIDevices>(tmp);
}
packet >> device;
for (u32& value : m_net_settings.m_SYSCONFSettings)
packet >> value;
@ -924,7 +904,7 @@ void NetPlayClient::OnPing(sf::Packet& packet)
packet >> ping_key;
sf::Packet response_packet;
response_packet << static_cast<MessageId>(NP_MSG_PONG);
response_packet << MessageID::Pong;
response_packet << ping_key;
Send(response_packet);
@ -981,7 +961,7 @@ void NetPlayClient::OnSyncGCSRAM(sf::Packet& packet)
void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
{
MessageId sub_id;
SyncSaveDataID sub_id;
packet >> sub_id;
if (m_local_player->IsHost())
@ -989,23 +969,23 @@ void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
switch (sub_id)
{
case SYNC_SAVE_DATA_NOTIFY:
case SyncSaveDataID::Notify:
OnSyncSaveDataNotify(packet);
break;
case SYNC_SAVE_DATA_RAW:
case SyncSaveDataID::RawData:
OnSyncSaveDataRaw(packet);
break;
case SYNC_SAVE_DATA_GCI:
case SyncSaveDataID::GCIData:
OnSyncSaveDataGCI(packet);
break;
case SYNC_SAVE_DATA_WII:
case SyncSaveDataID::WiiData:
OnSyncSaveDataWii(packet);
break;
case SYNC_SAVE_DATA_GBA:
case SyncSaveDataID::GBAData:
OnSyncSaveDataGBA(packet);
break;
@ -1183,11 +1163,7 @@ void NetPlayClient::OnSyncSaveDataWii(sf::Packet& packet)
{
WiiSave::Storage::SaveFile file;
packet >> file.mode >> file.attributes;
{
u8 tmp;
packet >> tmp;
file.type = static_cast<WiiSave::Storage::SaveFile::Type>(tmp);
}
packet >> file.type;
packet >> file.path;
if (file.type == WiiSave::Storage::SaveFile::Type::File)
@ -1239,29 +1215,29 @@ void NetPlayClient::OnSyncSaveDataGBA(sf::Packet& packet)
void NetPlayClient::OnSyncCodes(sf::Packet& packet)
{
// Recieve Data Packet
MessageId sub_id;
SyncCodeID sub_id;
packet >> sub_id;
// Check Which Operation to Perform with This Packet
switch (sub_id)
{
case SYNC_CODES_NOTIFY:
case SyncCodeID::Notify:
OnSyncCodesNotify();
break;
case SYNC_CODES_NOTIFY_GECKO:
case SyncCodeID::NotifyGecko:
OnSyncCodesNotifyGecko(packet);
break;
case SYNC_CODES_DATA_GECKO:
case SyncCodeID::GeckoData:
OnSyncCodesDataGecko(packet);
break;
case SYNC_CODES_NOTIFY_AR:
case SyncCodeID::NotifyAR:
OnSyncCodesNotifyAR(packet);
break;
case SYNC_CODES_DATA_AR:
case SyncCodeID::ARData:
OnSyncCodesDataAR(packet);
break;
@ -1643,7 +1619,7 @@ const NetSettings& NetPlayClient::GetNetSettings() const
void NetPlayClient::SendChatMessage(const std::string& msg)
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_CHAT_MESSAGE);
packet << MessageID::ChatMessage;
packet << msg;
SendAsync(std::move(packet));
@ -1666,7 +1642,7 @@ void NetPlayClient::AddPadStateToPacket(const int in_game_pad, const GCPadStatus
void NetPlayClient::SendWiimoteState(const int in_game_pad, const WiimoteInput& nw)
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_WIIMOTE_DATA);
packet << MessageID::WiimoteData;
packet << static_cast<PadIndex>(in_game_pad);
packet << static_cast<u8>(nw.report_id);
packet << static_cast<u8>(nw.data.size());
@ -1678,7 +1654,7 @@ void NetPlayClient::SendWiimoteState(const int in_game_pad, const WiimoteInput&
void NetPlayClient::SendStartGamePacket()
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_START_GAME);
packet << MessageID::StartGame;
packet << m_current_game;
SendAsync(std::move(packet));
@ -1688,7 +1664,7 @@ void NetPlayClient::SendStartGamePacket()
void NetPlayClient::SendStopGamePacket()
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_STOP_GAME);
packet << MessageID::StopGame;
SendAsync(std::move(packet));
}
@ -1760,8 +1736,8 @@ void NetPlayClient::SyncSaveDataResponse(const bool success)
if (++m_sync_save_data_success_count >= m_sync_save_data_count)
{
sf::Packet response_packet;
response_packet << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
response_packet << static_cast<MessageId>(SYNC_SAVE_DATA_SUCCESS);
response_packet << MessageID::SyncSaveData;
response_packet << SyncSaveDataID::Success;
Send(response_packet);
}
@ -1769,8 +1745,8 @@ void NetPlayClient::SyncSaveDataResponse(const bool success)
else
{
sf::Packet response_packet;
response_packet << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
response_packet << static_cast<MessageId>(SYNC_SAVE_DATA_FAILURE);
response_packet << MessageID::SyncSaveData;
response_packet << SyncSaveDataID::Failure;
Send(response_packet);
}
@ -1784,8 +1760,8 @@ void NetPlayClient::SyncCodeResponse(const bool success)
m_dialog->AppendChat(Common::GetStringT("Error processing codes."));
sf::Packet response_packet;
response_packet << static_cast<MessageId>(NP_MSG_SYNC_CODES);
response_packet << static_cast<MessageId>(SYNC_CODES_FAILURE);
response_packet << MessageID::SyncCodes;
response_packet << SyncCodeID::Failure;
Send(response_packet);
return;
@ -1797,8 +1773,8 @@ void NetPlayClient::SyncCodeResponse(const bool success)
m_dialog->AppendChat(Common::GetStringT("Codes received!"));
sf::Packet response_packet;
response_packet << static_cast<MessageId>(NP_MSG_SYNC_CODES);
response_packet << static_cast<MessageId>(SYNC_CODES_SUCCESS);
response_packet << MessageID::SyncCodes;
response_packet << SyncCodeID::Success;
Send(response_packet);
}
@ -1960,7 +1936,7 @@ bool NetPlayClient::GetNetPads(const int pad_nb, const bool batching, GCPadStatu
{
// Tell the server we've acknowledged the message
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_PREPARE);
spac << MessageID::GolfPrepare;
Send(spac);
m_wait_on_input_received = false;
@ -1972,7 +1948,7 @@ bool NetPlayClient::GetNetPads(const int pad_nb, const bool batching, GCPadStatu
if (IsFirstInGamePad(pad_nb) && batching)
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
packet << MessageID::PadData;
bool send_packet = false;
const int num_local_pads = NumLocalPads();
@ -1990,11 +1966,11 @@ bool NetPlayClient::GetNetPads(const int pad_nb, const bool batching, GCPadStatu
if (!batching)
{
int local_pad = InGamePadToLocalPad(pad_nb);
const int local_pad = InGamePadToLocalPad(pad_nb);
if (local_pad < 4)
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_PAD_DATA);
packet << MessageID::PadData;
if (PollLocalPad(local_pad, packet))
SendAsync(std::move(packet));
}
@ -2208,7 +2184,7 @@ void NetPlayClient::SendPadHostPoll(const PadIndex pad_num)
return;
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_PAD_HOST_DATA);
packet << MessageID::PadHostData;
if (pad_num < 0)
{
@ -2309,7 +2285,7 @@ void NetPlayClient::RequestStopGame()
void NetPlayClient::SendPowerButtonEvent()
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_POWER_BUTTON);
packet << MessageID::PowerButton;
SendAsync(std::move(packet));
}
@ -2319,7 +2295,7 @@ void NetPlayClient::RequestGolfControl(const PlayerId pid)
return;
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_GOLF_REQUEST);
packet << MessageID::GolfRequest;
packet << pid;
SendAsync(std::move(packet));
}
@ -2410,7 +2386,7 @@ bool NetPlayClient::IsLocalPlayer(const PlayerId pid) const
void NetPlayClient::SendGameStatus()
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_GAME_STATUS);
packet << MessageID::GameStatus;
SyncIdentifierComparison result;
m_dialog->FindGameFile(m_selected_game, &result);
@ -2436,7 +2412,7 @@ void NetPlayClient::SendTimeBase()
const sf::Uint64 timebase = SystemTimers::GetFakeTimeBase();
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_TIMEBASE);
packet << MessageID::TimeBase;
packet << timebase;
packet << netplay_client->m_timebase_frame;
@ -2472,7 +2448,7 @@ void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)
if (file.empty() || !File::Exists(file))
{
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_MD5_ERROR);
packet << MessageID::MD5Error;
packet << "file not found";
Send(packet);
return;
@ -2483,7 +2459,7 @@ void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)
m_MD5_thread = std::thread([this, file]() {
std::string sum = MD5::MD5Sum(file, [&](int progress) {
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_MD5_PROGRESS);
packet << MessageID::MD5Progress;
packet << progress;
SendAsync(std::move(packet));
@ -2491,7 +2467,7 @@ void NetPlayClient::ComputeMD5(const SyncIdentifier& sync_identifier)
});
sf::Packet packet;
packet << static_cast<MessageId>(NP_MSG_MD5_RESULT);
packet << MessageID::MD5Result;
packet << sum;
SendAsync(std::move(packet));
});

View File

@ -120,94 +120,96 @@ struct NetTraversalConfig
u16 traversal_port = 0;
};
// messages
enum
enum class MessageID : u8
{
NP_MSG_PLAYER_JOIN = 0x10,
NP_MSG_PLAYER_LEAVE = 0x11,
ConnectionSuccessful = 0,
NP_MSG_CHAT_MESSAGE = 0x30,
PlayerJoin = 0x10,
PlayerLeave = 0x11,
NP_MSG_CHUNKED_DATA_START = 0x40,
NP_MSG_CHUNKED_DATA_END = 0x41,
NP_MSG_CHUNKED_DATA_PAYLOAD = 0x42,
NP_MSG_CHUNKED_DATA_PROGRESS = 0x43,
NP_MSG_CHUNKED_DATA_COMPLETE = 0x44,
NP_MSG_CHUNKED_DATA_ABORT = 0x45,
ChatMessage = 0x30,
NP_MSG_PAD_DATA = 0x60,
NP_MSG_PAD_MAPPING = 0x61,
NP_MSG_PAD_BUFFER = 0x62,
NP_MSG_PAD_HOST_DATA = 0x63,
NP_MSG_GBA_CONFIG = 0x64,
ChunkedDataStart = 0x40,
ChunkedDataEnd = 0x41,
ChunkedDataPayload = 0x42,
ChunkedDataProgress = 0x43,
ChunkedDataComplete = 0x44,
ChunkedDataAbort = 0x45,
NP_MSG_WIIMOTE_DATA = 0x70,
NP_MSG_WIIMOTE_MAPPING = 0x71,
PadData = 0x60,
PadMapping = 0x61,
PadBuffer = 0x62,
PadHostData = 0x63,
GBAConfig = 0x64,
NP_MSG_GOLF_REQUEST = 0x90,
NP_MSG_GOLF_SWITCH = 0x91,
NP_MSG_GOLF_ACQUIRE = 0x92,
NP_MSG_GOLF_RELEASE = 0x93,
NP_MSG_GOLF_PREPARE = 0x94,
WiimoteData = 0x70,
WiimoteMapping = 0x71,
NP_MSG_START_GAME = 0xA0,
NP_MSG_CHANGE_GAME = 0xA1,
NP_MSG_STOP_GAME = 0xA2,
NP_MSG_DISABLE_GAME = 0xA3,
NP_MSG_GAME_STATUS = 0xA4,
NP_MSG_CLIENT_CAPABILITIES = 0xA5,
NP_MSG_HOST_INPUT_AUTHORITY = 0xA6,
NP_MSG_POWER_BUTTON = 0xA7,
GolfRequest = 0x90,
GolfSwitch = 0x91,
GolfAcquire = 0x92,
GolfRelease = 0x93,
GolfPrepare = 0x94,
NP_MSG_TIMEBASE = 0xB0,
NP_MSG_DESYNC_DETECTED = 0xB1,
StartGame = 0xA0,
ChangeGame = 0xA1,
StopGame = 0xA2,
DisableGame = 0xA3,
GameStatus = 0xA4,
ClientCapabilities = 0xA5,
HostInputAuthority = 0xA6,
PowerButton = 0xA7,
NP_MSG_COMPUTE_MD5 = 0xC0,
NP_MSG_MD5_PROGRESS = 0xC1,
NP_MSG_MD5_RESULT = 0xC2,
NP_MSG_MD5_ABORT = 0xC3,
NP_MSG_MD5_ERROR = 0xC4,
TimeBase = 0xB0,
DesyncDetected = 0xB1,
NP_MSG_READY = 0xD0,
NP_MSG_NOT_READY = 0xD1,
ComputeMD5 = 0xC0,
MD5Progress = 0xC1,
MD5Result = 0xC2,
MD5Abort = 0xC3,
MD5Error = 0xC4,
NP_MSG_PING = 0xE0,
NP_MSG_PONG = 0xE1,
NP_MSG_PLAYER_PING_DATA = 0xE2,
Ready = 0xD0,
NotReady = 0xD1,
NP_MSG_SYNC_GC_SRAM = 0xF0,
NP_MSG_SYNC_SAVE_DATA = 0xF1,
NP_MSG_SYNC_CODES = 0xF2,
Ping = 0xE0,
Pong = 0xE1,
PlayerPingData = 0xE2,
SyncGCSRAM = 0xF0,
SyncSaveData = 0xF1,
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
enum class SyncSaveDataID : u8
{
SYNC_SAVE_DATA_NOTIFY = 0,
SYNC_SAVE_DATA_SUCCESS = 1,
SYNC_SAVE_DATA_FAILURE = 2,
SYNC_SAVE_DATA_RAW = 3,
SYNC_SAVE_DATA_GCI = 4,
SYNC_SAVE_DATA_WII = 5,
SYNC_SAVE_DATA_GBA = 6
Notify = 0,
Success = 1,
Failure = 2,
RawData = 3,
GCIData = 4,
WiiData = 5,
GBAData = 6
};
enum
enum class SyncCodeID : u8
{
SYNC_CODES_NOTIFY = 0,
SYNC_CODES_NOTIFY_GECKO = 1,
SYNC_CODES_NOTIFY_AR = 2,
SYNC_CODES_DATA_GECKO = 3,
SYNC_CODES_DATA_AR = 4,
SYNC_CODES_SUCCESS = 5,
SYNC_CODES_FAILURE = 6,
Notify = 0,
NotifyGecko = 1,
NotifyAR = 2,
GeckoData = 3,
ARData = 4,
Success = 5,
Failure = 6,
};
constexpr u32 MAX_NAME_LENGTH = 30;
@ -225,7 +227,6 @@ struct WiimoteInput
u8 report_id;
std::vector<u8> data;
};
using MessageId = u8;
using PlayerId = u8;
using FrameNum = u32;
using PadIndex = s8;

View File

@ -242,7 +242,7 @@ void NetPlayServer::ThreadFunc()
m_ping_key = Common::Timer::GetTimeMs();
sf::Packet spac;
spac << (MessageId)NP_MSG_PING;
spac << MessageID::Ping;
spac << m_ping_key;
m_ping_timer.Start();
@ -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;
@ -427,13 +427,13 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
// send join message to already connected clients
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_PLAYER_JOIN);
spac << MessageID::PlayerJoin;
spac << player.pid << player.name << player.revision;
SendToClients(spac);
// send new client success message with their id
// send new client success message with their ID
spac.clear();
spac << static_cast<MessageId>(0);
spac << MessageID::ConnectionSuccessful;
spac << player.pid;
Send(player.socket, spac);
@ -441,7 +441,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
if (!m_selected_game_name.empty())
{
spac.clear();
spac << static_cast<MessageId>(NP_MSG_CHANGE_GAME);
spac << MessageID::ChangeGame;
SendSyncIdentifier(spac, m_selected_game_identifier);
spac << m_selected_game_name;
Send(player.socket, spac);
@ -451,14 +451,14 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
{
// send the pad buffer value
spac.clear();
spac << static_cast<MessageId>(NP_MSG_PAD_BUFFER);
spac << static_cast<u32>(m_target_buffer_size);
spac << MessageID::PadBuffer;
spac << m_target_buffer_size;
Send(player.socket, spac);
}
// send input authority state
spac.clear();
spac << static_cast<MessageId>(NP_MSG_HOST_INPUT_AUTHORITY);
spac << MessageID::HostInputAuthority;
spac << m_host_input_authority;
Send(player.socket, spac);
@ -466,13 +466,13 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
for (const auto& p : m_players)
{
spac.clear();
spac << static_cast<MessageId>(NP_MSG_PLAYER_JOIN);
spac << MessageID::PlayerJoin;
spac << p.second.pid << p.second.name << p.second.revision;
Send(player.socket, spac);
spac.clear();
spac << static_cast<MessageId>(NP_MSG_GAME_STATUS);
spac << p.second.pid << static_cast<u32>(p.second.game_status);
spac << MessageID::GameStatus;
spac << p.second.pid << p.second.game_status;
Send(player.socket, spac);
}
@ -488,7 +488,7 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
UpdateWiimoteMapping();
}
return 0;
return ConnectionError::NoError;
}
// called from ---NETPLAY--- thread
@ -506,7 +506,7 @@ unsigned int NetPlayServer::OnDisconnect(const Client& player)
m_is_running = false;
sf::Packet spac;
spac << (MessageId)NP_MSG_DISABLE_GAME;
spac << MessageID::DisableGame;
// this thread doesn't need players lock
SendToClients(spac);
break;
@ -522,7 +522,7 @@ unsigned int NetPlayServer::OnDisconnect(const Client& player)
}
sf::Packet spac;
spac << (MessageId)NP_MSG_PLAYER_LEAVE;
spac << MessageID::PlayerLeave;
spac << pid;
enet_peer_disconnect(player.socket, 0);
@ -612,7 +612,7 @@ void NetPlayServer::SetWiimoteMapping(const PadMappingArray& mappings)
void NetPlayServer::UpdatePadMapping()
{
sf::Packet spac;
spac << (MessageId)NP_MSG_PAD_MAPPING;
spac << MessageID::PadMapping;
for (PlayerId mapping : m_pad_map)
{
spac << mapping;
@ -624,7 +624,7 @@ void NetPlayServer::UpdatePadMapping()
void NetPlayServer::UpdateGBAConfig()
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GBA_CONFIG);
spac << MessageID::GBAConfig;
for (const auto& config : m_gba_config)
{
spac << config.enabled << config.has_rom << config.title;
@ -638,7 +638,7 @@ void NetPlayServer::UpdateGBAConfig()
void NetPlayServer::UpdateWiimoteMapping()
{
sf::Packet spac;
spac << (MessageId)NP_MSG_WIIMOTE_MAPPING;
spac << MessageID::WiimoteMapping;
for (PlayerId mapping : m_wiimote_map)
{
spac << mapping;
@ -658,8 +658,8 @@ void NetPlayServer::AdjustPadBufferSize(unsigned int size)
{
// tell clients to change buffer size
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_PAD_BUFFER);
spac << static_cast<u32>(m_target_buffer_size);
spac << MessageID::PadBuffer;
spac << m_target_buffer_size;
SendAsyncToClients(std::move(spac));
}
@ -673,7 +673,7 @@ void NetPlayServer::SetHostInputAuthority(const bool enable)
// tell clients about the new value
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_HOST_INPUT_AUTHORITY);
spac << MessageID::HostInputAuthority;
spac << m_host_input_authority;
SendAsyncToClients(std::move(spac));
@ -727,7 +727,7 @@ void NetPlayServer::SendChunkedToClients(sf::Packet&& packet, const PlayerId ski
// called from ---NETPLAY--- thread
unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
{
MessageId mid;
MessageID mid;
packet >> mid;
INFO_LOG_FMT(NETPLAY, "Got client message: {:x}", mid);
@ -737,14 +737,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
switch (mid)
{
case NP_MSG_CHAT_MESSAGE:
case MessageID::ChatMessage:
{
std::string msg;
packet >> msg;
// send msg to other clients
sf::Packet spac;
spac << (MessageId)NP_MSG_CHAT_MESSAGE;
spac << MessageID::ChatMessage;
spac << player.pid;
spac << msg;
@ -752,7 +752,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_CHUNKED_DATA_PROGRESS:
case MessageID::ChunkedDataProgress:
{
u32 cid;
packet >> cid;
@ -762,7 +762,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_CHUNKED_DATA_COMPLETE:
case MessageID::ChunkedDataComplete:
{
u32 cid;
packet >> cid;
@ -775,14 +775,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_PAD_DATA:
case MessageID::PadData:
{
// if this is pad data from the last game still being received, ignore it
if (player.current_game != m_current_game)
break;
sf::Packet spac;
spac << static_cast<MessageId>(m_host_input_authority ? NP_MSG_PAD_HOST_DATA : NP_MSG_PAD_DATA);
spac << (m_host_input_authority ? MessageID::PadHostData : MessageID::PadData);
while (!packet.endOfPacket())
{
@ -822,14 +822,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_PAD_HOST_DATA:
case MessageID::PadHostData:
{
// Kick player if they're not the golfer.
if (m_current_golfer != 0 && player.pid != m_current_golfer)
return 1;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_PAD_DATA);
spac << MessageID::PadData;
while (!packet.endOfPacket())
{
@ -853,7 +853,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_WIIMOTE_DATA:
case MessageID::WiimoteData:
{
// if this is Wiimote data from the last game still being received, ignore it
if (player.current_game != m_current_game)
@ -875,7 +875,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
// relay to clients
sf::Packet spac;
spac << (MessageId)NP_MSG_WIIMOTE_DATA;
spac << MessageID::WiimoteData;
spac << map;
spac << size;
for (const u8& byte : data)
@ -885,7 +885,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_GOLF_REQUEST:
case MessageID::GolfRequest:
{
PlayerId pid;
packet >> pid;
@ -900,25 +900,25 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
m_pending_golfer = pid;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_PREPARE);
spac << MessageID::GolfPrepare;
Send(m_players[pid].socket, spac);
}
}
break;
case NP_MSG_GOLF_RELEASE:
case MessageID::GolfRelease:
{
if (m_pending_golfer == 0)
break;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_SWITCH);
spac << static_cast<PlayerId>(m_pending_golfer);
spac << MessageID::GolfSwitch;
spac << m_pending_golfer;
SendToClients(spac);
}
break;
case NP_MSG_GOLF_ACQUIRE:
case MessageID::GolfAcquire:
{
if (m_pending_golfer == 0)
break;
@ -928,7 +928,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_GOLF_PREPARE:
case MessageID::GolfPrepare:
{
if (m_pending_golfer == 0)
break;
@ -936,13 +936,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
m_current_golfer = 0;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GOLF_SWITCH);
spac << static_cast<PlayerId>(0);
spac << MessageID::GolfSwitch;
spac << PlayerId{0};
SendToClients(spac);
}
break;
case NP_MSG_PONG:
case MessageID::Pong:
{
const u32 ping = (u32)m_ping_timer.GetTimeElapsed();
u32 ping_key = 0;
@ -954,7 +954,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
sf::Packet spac;
spac << (MessageId)NP_MSG_PLAYER_PING_DATA;
spac << MessageID::PlayerPingData;
spac << player.pid;
spac << player.ping;
@ -962,13 +962,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_START_GAME:
case MessageID::StartGame:
{
packet >> player.current_game;
}
break;
case NP_MSG_STOP_GAME:
case MessageID::StopGame:
{
if (!m_is_running)
break;
@ -977,23 +977,23 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
// tell clients to stop game
sf::Packet spac;
spac << (MessageId)NP_MSG_STOP_GAME;
spac << MessageID::StopGame;
std::lock_guard lkp(m_crit.players);
SendToClients(spac);
}
break;
case NP_MSG_GAME_STATUS:
case MessageID::GameStatus:
{
u32 status;
SyncIdentifierComparison status;
packet >> status;
m_players[player.pid].game_status = static_cast<SyncIdentifierComparison>(status);
m_players[player.pid].game_status = status;
// send msg to other clients
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_GAME_STATUS);
spac << MessageID::GameStatus;
spac << player.pid;
spac << status;
@ -1001,22 +1001,22 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_CLIENT_CAPABILITIES:
case MessageID::ClientCapabilities:
{
packet >> m_players[player.pid].has_ipl_dump;
packet >> m_players[player.pid].has_hardware_fma;
}
break;
case NP_MSG_POWER_BUTTON:
case MessageID::PowerButton:
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_POWER_BUTTON);
spac << MessageID::PowerButton;
SendToClients(spac, player.pid);
}
break;
case NP_MSG_TIMEBASE:
case MessageID::TimeBase:
{
u64 timebase = Common::PacketReadU64(packet);
u32 frame;
@ -1049,7 +1049,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
sf::Packet spac;
spac << (MessageId)NP_MSG_DESYNC_DETECTED;
spac << MessageID::DesyncDetected;
spac << pid_to_blame;
spac << frame;
SendToClients(spac);
@ -1061,13 +1061,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_MD5_PROGRESS:
case MessageID::MD5Progress:
{
int progress;
packet >> progress;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_PROGRESS);
spac << MessageID::MD5Progress;
spac << player.pid;
spac << progress;
@ -1075,13 +1075,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_MD5_RESULT:
case MessageID::MD5Result:
{
std::string result;
packet >> result;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_RESULT);
spac << MessageID::MD5Result;
spac << player.pid;
spac << result;
@ -1089,13 +1089,13 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_MD5_ERROR:
case MessageID::MD5Error:
{
std::string error;
packet >> error;
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_ERROR);
spac << MessageID::MD5Error;
spac << player.pid;
spac << error;
@ -1103,14 +1103,14 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_SYNC_SAVE_DATA:
case MessageID::SyncSaveData:
{
MessageId sub_id;
SyncSaveDataID sub_id;
packet >> sub_id;
switch (sub_id)
{
case SYNC_SAVE_DATA_SUCCESS:
case SyncSaveDataID::Success:
{
if (m_start_pending)
{
@ -1127,7 +1127,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case SYNC_SAVE_DATA_FAILURE:
case SyncSaveDataID::Failure:
{
m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize.", player.name));
m_dialog->OnGameStartAborted();
@ -1145,16 +1145,16 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case NP_MSG_SYNC_CODES:
case MessageID::SyncCodes:
{
// Receive Status of Code Sync
MessageId sub_id;
SyncCodeID sub_id;
packet >> sub_id;
// Check If Code Sync was successful or not
switch (sub_id)
{
case SYNC_CODES_SUCCESS:
case SyncCodeID::Success:
{
if (m_start_pending)
{
@ -1170,7 +1170,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
}
break;
case SYNC_CODES_FAILURE:
case SyncCodeID::Failure:
{
m_dialog->AppendChat(Common::FmtFormatT("{0} failed to synchronize codes.", player.name));
m_dialog->OnGameStartAborted();
@ -1217,8 +1217,8 @@ void NetPlayServer::OnTraversalStateChanged()
void NetPlayServer::SendChatMessage(const std::string& msg)
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_CHAT_MESSAGE);
spac << static_cast<PlayerId>(0); // server id always 0
spac << MessageID::ChatMessage;
spac << PlayerId{0}; // server ID always 0
spac << msg;
SendAsyncToClients(std::move(spac));
@ -1235,7 +1235,7 @@ bool NetPlayServer::ChangeGame(const SyncIdentifier& sync_identifier,
// send changed game to clients
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_CHANGE_GAME);
spac << MessageID::ChangeGame;
SendSyncIdentifier(spac, m_selected_game_identifier);
spac << m_selected_game_name;
@ -1248,7 +1248,7 @@ bool NetPlayServer::ChangeGame(const SyncIdentifier& sync_identifier,
bool NetPlayServer::ComputeMD5(const SyncIdentifier& sync_identifier)
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_COMPUTE_MD5);
spac << MessageID::ComputeMD5;
SendSyncIdentifier(spac, sync_identifier);
SendAsyncToClients(std::move(spac));
@ -1260,10 +1260,9 @@ bool NetPlayServer::ComputeMD5(const SyncIdentifier& sync_identifier)
bool NetPlayServer::AbortMD5()
{
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_MD5_ABORT);
spac << MessageID::MD5Abort;
SendAsyncToClients(std::move(spac));
return true;
}
@ -1462,7 +1461,7 @@ bool NetPlayServer::StartGame()
g_SRAM_netplay_initialized = true;
}
sf::Packet srampac;
srampac << static_cast<MessageId>(NP_MSG_SYNC_GC_SRAM);
srampac << MessageID::SyncGCSRAM;
for (size_t i = 0; i < sizeof(g_SRAM) - offsetof(Sram, settings); ++i)
{
srampac << g_SRAM[offsetof(Sram, settings) + i];
@ -1471,10 +1470,10 @@ bool NetPlayServer::StartGame()
// tell clients to start game
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_START_GAME);
spac << MessageID::StartGame;
spac << m_current_game;
spac << m_settings.m_CPUthread;
spac << static_cast<std::underlying_type_t<PowerPC::CPUCore>>(m_settings.m_CPUcore);
spac << m_settings.m_CPUcore;
spac << m_settings.m_EnableCheats;
spac << m_settings.m_SelectedLanguage;
spac << m_settings.m_OverrideRegionSettings;
@ -1484,7 +1483,7 @@ bool NetPlayServer::StartGame()
spac << m_settings.m_RAMOverrideEnable;
spac << m_settings.m_Mem1Size;
spac << m_settings.m_Mem2Size;
spac << static_cast<std::underlying_type_t<DiscIO::Region>>(m_settings.m_FallbackRegion);
spac << m_settings.m_FallbackRegion;
spac << m_settings.m_AllowSDWrites;
spac << m_settings.m_CopyWiiSave;
spac << m_settings.m_OCEnable;
@ -1620,8 +1619,8 @@ bool NetPlayServer::SyncSaveData()
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_NOTIFY);
pac << MessageID::SyncSaveData;
pac << SyncSaveDataID::Notify;
pac << save_count;
// send this on the chunked data channel to ensure it's sequenced properly
@ -1657,8 +1656,8 @@ bool NetPlayServer::SyncSaveData()
}
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_RAW);
pac << MessageID::SyncSaveData;
pac << SyncSaveDataID::RawData;
pac << is_slot_a << region << size_override;
if (File::Exists(path))
@ -1682,8 +1681,8 @@ bool NetPlayServer::SyncSaveData()
fmt::format("Card {}", is_slot_a ? 'A' : 'B');
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_GCI);
pac << MessageID::SyncSaveData;
pac << SyncSaveDataID::GCIData;
pac << is_slot_a;
if (File::IsDirectory(path))
@ -1734,8 +1733,8 @@ bool NetPlayServer::SyncSaveData()
std::vector<u64> titles;
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_WII);
pac << MessageID::SyncSaveData;
pac << SyncSaveDataID::WiiData;
// Shove the Mii data into the start the packet
{
@ -1798,7 +1797,7 @@ bool NetPlayServer::SyncSaveData()
// Files
for (const WiiSave::Storage::SaveFile& file : *files)
{
pac << file.mode << file.attributes << static_cast<u8>(file.type) << file.path;
pac << file.mode << file.attributes << file.type << file.path;
if (file.type == WiiSave::Storage::SaveFile::Type::File)
{
@ -1825,8 +1824,8 @@ bool NetPlayServer::SyncSaveData()
if (m_gba_config[i].enabled && m_gba_config[i].has_rom)
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_SAVE_DATA);
pac << static_cast<MessageId>(SYNC_SAVE_DATA_GBA);
pac << MessageID::SyncSaveData;
pac << SyncSaveDataID::GBAData;
pac << static_cast<u8>(i);
std::string path;
@ -1882,8 +1881,8 @@ bool NetPlayServer::SyncCodes()
// Notify Clients of Incoming Code Sync
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_CODES);
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY);
pac << MessageID::SyncCodes;
pac << SyncCodeID::Notify;
SendAsyncToClients(std::move(pac));
}
// Sync Gecko Codes
@ -1910,8 +1909,8 @@ bool NetPlayServer::SyncCodes()
// Send initial packet. Notify of the sync operation and total number of lines being sent.
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_CODES);
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY_GECKO);
pac << MessageID::SyncCodes;
pac << SyncCodeID::NotifyGecko;
pac << codelines;
SendAsyncToClients(std::move(pac));
}
@ -1919,8 +1918,8 @@ bool NetPlayServer::SyncCodes()
// Send entire codeset in the second packet
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_CODES);
pac << static_cast<MessageId>(SYNC_CODES_DATA_GECKO);
pac << MessageID::SyncCodes;
pac << SyncCodeID::GeckoData;
// Iterate through the active code vector and send each codeline
for (const Gecko::GeckoCode& active_code : s_active_codes)
{
@ -1960,8 +1959,8 @@ bool NetPlayServer::SyncCodes()
// Send initial packet. Notify of the sync operation and total number of lines being sent.
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_CODES);
pac << static_cast<MessageId>(SYNC_CODES_NOTIFY_AR);
pac << MessageID::SyncCodes;
pac << SyncCodeID::NotifyAR;
pac << codelines;
SendAsyncToClients(std::move(pac));
}
@ -1969,8 +1968,8 @@ bool NetPlayServer::SyncCodes()
// Send entire codeset in the second packet
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_SYNC_CODES);
pac << static_cast<MessageId>(SYNC_CODES_DATA_AR);
pac << MessageID::SyncCodes;
pac << SyncCodeID::ARData;
// Iterate through the active code vector and send each codeline
for (const ActionReplay::ARCode& active_code : s_active_codes)
{
@ -2160,7 +2159,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
player_count = players.size();
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_START);
pac << MessageID::ChunkedDataStart;
pac << id << e.title << sf::Uint64{e.packet.getDataSize()};
ChunkedDataSend(std::move(pac), e.target_pid, e.target_mode);
@ -2182,7 +2181,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
if (m_abort_chunked_data)
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_ABORT);
pac << MessageID::ChunkedDataAbort;
pac << id;
ChunkedDataSend(std::move(pac), e.target_pid, e.target_mode);
break;
@ -2199,7 +2198,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
auto start = std::chrono::steady_clock::now();
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_PAYLOAD);
pac << MessageID::ChunkedDataPayload;
pac << id;
size_t len = std::min(CHUNKED_DATA_UNIT_SIZE, e.packet.getDataSize() - index);
pac.append(static_cast<const u8*>(e.packet.getData()) + index, len);
@ -2217,7 +2216,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
if (!m_abort_chunked_data)
{
sf::Packet pac;
pac << static_cast<MessageId>(NP_MSG_CHUNKED_DATA_END);
pac << MessageID::ChunkedDataEnd;
pac << id;
ChunkedDataSend(std::move(pac), e.target_pid, e.target_mode);
}

View File

@ -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);