NetPlayClient: Split out OnData()

Over time OnData() has become a huge function-long case statement that
attempts to manage numerous packet-related behaviors, which makes it a
little difficult to reliably ensure certain handling doesn't interfere
with another case's. It's also mildly annoying to navigate due to its
size.

To make it a little easier to read and find the specific behavior, we
can break the relevant pieces of code out into their own functions.
This commit is contained in:
Lioncash 2021-09-15 10:26:01 -04:00
parent 94cfbfc49d
commit ae714b25ba
2 changed files with 1106 additions and 945 deletions

View File

@ -311,7 +311,7 @@ static void ReceiveSyncIdentifier(sf::Packet& spac, SyncIdentifier& sync_identif
}
// called from ---NETPLAY--- thread
unsigned int NetPlayClient::OnData(sf::Packet& packet)
u32 NetPlayClient::OnData(sf::Packet& packet)
{
MessageId mid;
packet >> mid;
@ -321,14 +321,154 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
switch (mid)
{
case NP_MSG_PLAYER_JOIN:
OnPlayerJoin(packet);
break;
case NP_MSG_PLAYER_LEAVE:
OnPlayerLeave(packet);
break;
case NP_MSG_CHAT_MESSAGE:
OnChatMessage(packet);
break;
case NP_MSG_CHUNKED_DATA_START:
OnChunkedDataStart(packet);
break;
case NP_MSG_CHUNKED_DATA_END:
OnChunkedDataEnd(packet);
break;
case NP_MSG_CHUNKED_DATA_PAYLOAD:
OnChunkedDataPayload(packet);
break;
case NP_MSG_CHUNKED_DATA_ABORT:
OnChunkedDataAbort(packet);
break;
case NP_MSG_PAD_MAPPING:
OnPadMapping(packet);
break;
case NP_MSG_GBA_CONFIG:
OnGBAConfig(packet);
break;
case NP_MSG_WIIMOTE_MAPPING:
OnWiimoteMapping(packet);
break;
case NP_MSG_PAD_DATA:
OnPadData(packet);
break;
case NP_MSG_PAD_HOST_DATA:
OnPadHostData(packet);
break;
case NP_MSG_WIIMOTE_DATA:
OnWiimoteData(packet);
break;
case NP_MSG_PAD_BUFFER:
OnPadBuffer(packet);
break;
case NP_MSG_HOST_INPUT_AUTHORITY:
OnHostInputAuthority(packet);
break;
case NP_MSG_GOLF_SWITCH:
OnGolfSwitch(packet);
break;
case NP_MSG_GOLF_PREPARE:
OnGolfPrepare(packet);
break;
case NP_MSG_CHANGE_GAME:
OnChangeGame(packet);
break;
case NP_MSG_GAME_STATUS:
OnGameStatus(packet);
break;
case NP_MSG_START_GAME:
OnStartGame(packet);
break;
case NP_MSG_STOP_GAME:
case NP_MSG_DISABLE_GAME:
OnStopGame(packet);
break;
case NP_MSG_POWER_BUTTON:
OnPowerButton();
break;
case NP_MSG_PING:
OnPing(packet);
break;
case NP_MSG_PLAYER_PING_DATA:
OnPlayerPingData(packet);
break;
case NP_MSG_DESYNC_DETECTED:
OnDesyncDetected(packet);
break;
case NP_MSG_SYNC_GC_SRAM:
OnSyncGCSRAM(packet);
break;
case NP_MSG_SYNC_SAVE_DATA:
OnSyncSaveData(packet);
break;
case NP_MSG_SYNC_CODES:
OnSyncCodes(packet);
break;
case NP_MSG_COMPUTE_MD5:
OnComputeMD5(packet);
break;
case NP_MSG_MD5_PROGRESS:
OnMD5Progress(packet);
break;
case NP_MSG_MD5_RESULT:
OnMD5Result(packet);
break;
case NP_MSG_MD5_ERROR:
OnMD5Error(packet);
break;
case NP_MSG_MD5_ABORT:
OnMD5Abort();
break;
default:
PanicAlertFmtT("Unknown message received with id : {0}", mid);
break;
}
return 0;
}
void NetPlayClient::OnPlayerJoin(sf::Packet& packet)
{
Player player;
Player player{};
packet >> player.pid;
packet >> player.name;
packet >> player.revision;
INFO_LOG_FMT(NETPLAY, "Player {} ({}) using {} joined", player.name, player.pid,
player.revision);
INFO_LOG_FMT(NETPLAY, "Player {} ({}) using {} joined", player.name, player.pid, player.revision);
{
std::lock_guard lkp(m_crit.players);
@ -339,9 +479,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->Update();
}
break;
case NP_MSG_PLAYER_LEAVE:
void NetPlayClient::OnPlayerLeave(sf::Packet& packet)
{
PlayerId pid;
packet >> pid;
@ -350,7 +489,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
std::lock_guard lkp(m_crit.players);
const auto it = m_players.find(pid);
if (it == m_players.end())
break;
return;
const auto& player = it->second;
INFO_LOG_FMT(NETPLAY, "Player {} ({}) left", player.name, pid);
@ -360,9 +499,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->Update();
}
break;
case NP_MSG_CHAT_MESSAGE:
void NetPlayClient::OnChatMessage(sf::Packet& packet)
{
PlayerId pid;
packet >> pid;
@ -376,19 +514,18 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
// add to gui
std::ostringstream ss;
ss << player.name << '[' << (char)(pid + '0') << "]: " << msg;
ss << player.name << '[' << char(pid + '0') << "]: " << msg;
m_dialog->AppendChat(ss.str());
}
break;
case NP_MSG_CHUNKED_DATA_START:
void NetPlayClient::OnChunkedDataStart(sf::Packet& packet)
{
u32 cid;
packet >> cid;
std::string title;
packet >> title;
u64 data_size = Common::PacketReadU64(packet);
const u64 data_size = Common::PacketReadU64(packet);
m_chunked_data_receive_queue.emplace(cid, sf::Packet{});
@ -396,17 +533,19 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
players.push_back(m_local_player->pid);
m_dialog->ShowChunkedProgressDialog(title, data_size, players);
}
break;
case NP_MSG_CHUNKED_DATA_END:
void NetPlayClient::OnChunkedDataEnd(sf::Packet& packet)
{
u32 cid;
packet >> cid;
if (m_chunked_data_receive_queue.count(cid))
{
OnData(m_chunked_data_receive_queue[cid]);
m_chunked_data_receive_queue.erase(cid);
const auto data_packet_iter = m_chunked_data_receive_queue.find(cid);
if (data_packet_iter == m_chunked_data_receive_queue.end())
return;
auto& data_packet = data_packet_iter->second;
OnData(data_packet);
m_chunked_data_receive_queue.erase(data_packet_iter);
m_dialog->HideChunkedProgressDialog();
sf::Packet complete_packet;
@ -414,62 +553,65 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
complete_packet << cid;
Send(complete_packet, CHUNKED_DATA_CHANNEL);
}
}
break;
case NP_MSG_CHUNKED_DATA_PAYLOAD:
void NetPlayClient::OnChunkedDataPayload(sf::Packet& packet)
{
u32 cid;
packet >> cid;
if (m_chunked_data_receive_queue.count(cid))
{
const auto data_packet_iter = m_chunked_data_receive_queue.find(cid);
if (data_packet_iter == m_chunked_data_receive_queue.end())
return;
auto& data_packet = data_packet_iter->second;
while (!packet.endOfPacket())
{
u8 byte;
packet >> byte;
m_chunked_data_receive_queue[cid] << byte;
data_packet << byte;
}
m_dialog->SetChunkedProgress(m_local_player->pid,
m_chunked_data_receive_queue[cid].getDataSize());
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 << cid;
progress_packet << sf::Uint64{m_chunked_data_receive_queue[cid].getDataSize()};
progress_packet << sf::Uint64{data_packet.getDataSize()};
Send(progress_packet, CHUNKED_DATA_CHANNEL);
}
}
break;
case NP_MSG_CHUNKED_DATA_ABORT:
void NetPlayClient::OnChunkedDataAbort(sf::Packet& packet)
{
u32 cid;
packet >> cid;
if (m_chunked_data_receive_queue.count(cid))
{
m_chunked_data_receive_queue.erase(cid);
const auto iter = m_chunked_data_receive_queue.find(cid);
if (iter == m_chunked_data_receive_queue.end())
return;
m_chunked_data_receive_queue.erase(iter);
m_dialog->HideChunkedProgressDialog();
}
}
break;
case NP_MSG_PAD_MAPPING:
void NetPlayClient::OnPadMapping(sf::Packet& packet)
{
for (PlayerId& mapping : m_pad_map)
{
packet >> mapping;
}
UpdateDevices();
m_dialog->Update();
}
break;
case NP_MSG_GBA_CONFIG:
void NetPlayClient::OnWiimoteMapping(sf::Packet& packet)
{
for (PlayerId& mapping : m_wiimote_map)
packet >> mapping;
m_dialog->Update();
}
void NetPlayClient::OnGBAConfig(sf::Packet& packet)
{
for (size_t i = 0; i < m_gba_config.size(); ++i)
{
@ -496,20 +638,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->Update();
}
break;
case NP_MSG_WIIMOTE_MAPPING:
{
for (PlayerId& mapping : m_wiimote_map)
{
packet >> mapping;
}
m_dialog->Update();
}
break;
case NP_MSG_PAD_DATA:
void NetPlayClient::OnPadData(sf::Packet& packet)
{
while (!packet.endOfPacket())
{
@ -530,9 +660,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_gc_pad_event.Set();
}
}
break;
case NP_MSG_PAD_HOST_DATA:
void NetPlayClient::OnPadHostData(sf::Packet& packet)
{
while (!packet.endOfPacket())
{
@ -558,14 +687,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
}
}
}
break;
case NP_MSG_WIIMOTE_DATA:
void NetPlayClient::OnWiimoteData(sf::Packet& packet)
{
PadIndex map;
WiimoteInput nw;
u8 size;
packet >> map >> nw.report_id >> size;
nw.data.resize(size);
for (auto& byte : nw.data)
packet >> byte;
@ -575,9 +705,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_wiimote_buffer.at(map).Push(nw);
m_wii_pad_event.Set();
}
break;
case NP_MSG_PAD_BUFFER:
void NetPlayClient::OnPadBuffer(sf::Packet& packet)
{
u32 size = 0;
packet >> size;
@ -585,16 +714,14 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_target_buffer_size = size;
m_dialog->OnPadBufferChanged(size);
}
break;
case NP_MSG_HOST_INPUT_AUTHORITY:
void NetPlayClient::OnHostInputAuthority(sf::Packet& packet)
{
packet >> m_host_input_authority;
m_dialog->OnHostInputAuthorityChanged(m_host_input_authority);
}
break;
case NP_MSG_GOLF_SWITCH:
void NetPlayClient::OnGolfSwitch(sf::Packet& packet)
{
PlayerId pid;
packet >> pid;
@ -622,16 +749,14 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_wait_on_input_event.Set();
}
}
break;
case NP_MSG_GOLF_PREPARE:
void NetPlayClient::OnGolfPrepare(sf::Packet& packet)
{
m_wait_on_input_received = true;
m_wait_on_input = true;
}
break;
case NP_MSG_CHANGE_GAME:
void NetPlayClient::OnChangeGame(sf::Packet& packet)
{
std::string netplay_name;
{
@ -653,9 +778,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
client_capabilities_packet << Config::Get(Config::SESSION_USE_FMA);
Send(client_capabilities_packet);
}
break;
case NP_MSG_GAME_STATUS:
void NetPlayClient::OnGameStatus(sf::Packet& packet)
{
PlayerId pid;
packet >> pid;
@ -670,9 +794,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->Update();
}
break;
case NP_MSG_START_GAME:
void NetPlayClient::OnStartGame(sf::Packet& packet)
{
{
std::lock_guard lkg(m_crit.game);
@ -783,25 +906,21 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->OnMsgStartGame();
}
break;
case NP_MSG_STOP_GAME:
case NP_MSG_DISABLE_GAME:
void NetPlayClient::OnStopGame(sf::Packet& packet)
{
INFO_LOG_FMT(NETPLAY, "Game stopped");
StopGame();
m_dialog->OnMsgStopGame();
}
break;
case NP_MSG_POWER_BUTTON:
void NetPlayClient::OnPowerButton()
{
m_dialog->OnMsgPowerButton();
}
break;
case NP_MSG_PING:
void NetPlayClient::OnPing(sf::Packet& packet)
{
u32 ping_key = 0;
packet >> ping_key;
@ -812,9 +931,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
Send(response_packet);
}
break;
case NP_MSG_PLAYER_PING_DATA:
void NetPlayClient::OnPlayerPingData(sf::Packet& packet)
{
PlayerId pid;
packet >> pid;
@ -828,9 +946,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
DisplayPlayersPing();
m_dialog->Update();
}
break;
case NP_MSG_DESYNC_DETECTED:
void NetPlayClient::OnDesyncDetected(sf::Packet& packet)
{
int pid_to_blame;
u32 frame;
@ -840,7 +957,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
std::string player = "??";
std::lock_guard lkp(m_crit.players);
{
auto it = m_players.find(pid_to_blame);
const auto it = m_players.find(pid_to_blame);
if (it != m_players.end())
player = it->second.name;
}
@ -849,16 +966,13 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->OnDesync(frame, player);
}
break;
case NP_MSG_SYNC_GC_SRAM:
void NetPlayClient::OnSyncGCSRAM(sf::Packet& packet)
{
const size_t sram_settings_len = sizeof(g_SRAM) - offsetof(Sram, settings);
u8 sram[sram_settings_len];
for (u8& cell : sram)
{
packet >> cell;
}
{
std::lock_guard lkg(m_crit.game);
@ -866,20 +980,45 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
g_SRAM_netplay_initialized = true;
}
}
break;
case NP_MSG_SYNC_SAVE_DATA:
void NetPlayClient::OnSyncSaveData(sf::Packet& packet)
{
MessageId sub_id;
packet >> sub_id;
if (m_local_player->IsHost())
return;
switch (sub_id)
{
case SYNC_SAVE_DATA_NOTIFY:
{
if (m_local_player->IsHost())
return 0;
OnSyncSaveDataNotify(packet);
break;
case SYNC_SAVE_DATA_RAW:
OnSyncSaveDataRaw(packet);
break;
case SYNC_SAVE_DATA_GCI:
OnSyncSaveDataGCI(packet);
break;
case SYNC_SAVE_DATA_WII:
OnSyncSaveDataWii(packet);
break;
case SYNC_SAVE_DATA_GBA:
OnSyncSaveDataGBA(packet);
break;
default:
PanicAlertFmtT("Unknown SYNC_SAVE_DATA message received with id: {0}", sub_id);
break;
}
}
void NetPlayClient::OnSyncSaveDataNotify(sf::Packet& packet)
{
packet >> m_sync_save_data_count;
m_sync_save_data_success_count = 0;
@ -888,13 +1027,9 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
else
m_dialog->AppendChat(Common::GetStringT("Synchronizing save data..."));
}
break;
case SYNC_SAVE_DATA_RAW:
void NetPlayClient::OnSyncSaveDataRaw(sf::Packet& packet)
{
if (m_local_player->IsHost())
return 0;
bool is_slot_a;
std::string region;
int size_override;
@ -904,7 +1039,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
if (region != JAP_DIR && region != USA_DIR && region != EUR_DIR)
{
SyncSaveDataResponse(false);
return 0;
return;
}
std::string size_suffix;
@ -920,19 +1055,15 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
PanicAlertFmtT("Failed to delete NetPlay memory card. Verify your write permissions.");
SyncSaveDataResponse(false);
return 0;
return;
}
const bool success = DecompressPacketIntoFile(packet, path);
SyncSaveDataResponse(success);
}
break;
case SYNC_SAVE_DATA_GCI:
void NetPlayClient::OnSyncSaveDataGCI(sf::Packet& packet)
{
if (m_local_player->IsHost())
return 0;
bool is_slot_a;
u8 file_count;
packet >> is_slot_a >> file_count;
@ -945,7 +1076,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
PanicAlertFmtT("Failed to reset NetPlay GCI folder. Verify your write permissions.");
SyncSaveDataResponse(false);
return 0;
return;
}
for (u8 i = 0; i < file_count; i++)
@ -957,34 +1088,32 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
!DecompressPacketIntoFile(packet, path + DIR_SEP + file_name))
{
SyncSaveDataResponse(false);
return 0;
return;
}
}
SyncSaveDataResponse(true);
}
break;
case SYNC_SAVE_DATA_WII:
void NetPlayClient::OnSyncSaveDataWii(sf::Packet& packet)
{
if (m_local_player->IsHost())
return 0;
const std::string path = File::GetUserPath(D_USER_IDX) + "Wii" GC_MEMCARD_NETPLAY DIR_SEP;
if (File::Exists(path) && !File::DeleteDirRecursively(path))
{
PanicAlertFmtT("Failed to reset NetPlay NAND folder. Verify your write permissions.");
SyncSaveDataResponse(false);
return 0;
return;
}
auto temp_fs = std::make_unique<IOS::HLE::FS::HostFileSystem>(path);
std::vector<u64> titles;
const IOS::HLE::FS::Modes fs_modes = {IOS::HLE::FS::Mode::ReadWrite,
constexpr IOS::HLE::FS::Modes fs_modes{
IOS::HLE::FS::Mode::ReadWrite,
IOS::HLE::FS::Mode::ReadWrite};
IOS::HLE::FS::Mode::ReadWrite,
IOS::HLE::FS::Mode::ReadWrite,
};
// Read the Mii data
bool mii_data;
@ -1002,7 +1131,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
{
PanicAlertFmtT("Failed to write Mii data.");
SyncSaveDataResponse(false);
return 0;
return;
}
}
@ -1069,7 +1198,7 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
if (!buffer)
{
SyncSaveDataResponse(false);
return 0;
return;
}
file.data = std::move(*buffer);
@ -1078,25 +1207,20 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
files.push_back(std::move(file));
}
if (!save->WriteHeader(header) || !save->WriteBkHeader(bk_header) ||
!save->WriteFiles(files))
if (!save->WriteHeader(header) || !save->WriteBkHeader(bk_header) || !save->WriteFiles(files))
{
PanicAlertFmtT("Failed to write Wii save.");
SyncSaveDataResponse(false);
return 0;
return;
}
}
SetWiiSyncData(std::move(temp_fs), titles);
SyncSaveDataResponse(true);
}
break;
case SYNC_SAVE_DATA_GBA:
void NetPlayClient::OnSyncSaveDataGBA(sf::Packet& packet)
{
if (m_local_player->IsHost())
return 0;
u8 slot;
packet >> slot;
@ -1107,22 +1231,14 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
PanicAlertFmtT("Failed to delete NetPlay GBA{0} save file. Verify your write permissions.",
slot + 1);
SyncSaveDataResponse(false);
return 0;
return;
}
const bool success = DecompressPacketIntoFile(packet, path);
SyncSaveDataResponse(success);
}
break;
default:
PanicAlertFmtT("Unknown SYNC_SAVE_DATA message received with id: {0}", sub_id);
break;
}
}
break;
case NP_MSG_SYNC_CODES:
void NetPlayClient::OnSyncCodes(sf::Packet& packet)
{
// Recieve Data Packet
MessageId sub_id;
@ -1132,18 +1248,43 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
switch (sub_id)
{
case SYNC_CODES_NOTIFY:
OnSyncCodesNotify();
break;
case SYNC_CODES_NOTIFY_GECKO:
OnSyncCodesNotifyGecko(packet);
break;
case SYNC_CODES_DATA_GECKO:
OnSyncCodesDataGecko(packet);
break;
case SYNC_CODES_NOTIFY_AR:
OnSyncCodesNotifyAR(packet);
break;
case SYNC_CODES_DATA_AR:
OnSyncCodesDataAR(packet);
break;
default:
PanicAlertFmtT("Unknown SYNC_CODES message received with id: {0}", sub_id);
break;
}
}
void NetPlayClient::OnSyncCodesNotify()
{
// Set both codes as unsynced
m_sync_gecko_codes_complete = false;
m_sync_ar_codes_complete = false;
}
break;
case SYNC_CODES_NOTIFY_GECKO:
void NetPlayClient::OnSyncCodesNotifyGecko(sf::Packet& packet)
{
// Return if this is the host
if (m_local_player->IsHost())
return 0;
return;
// Receive Number of Codelines to Receive
packet >> m_sync_gecko_codes_count;
@ -1163,25 +1304,22 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->AppendChat(Common::GetStringT("Synchronizing Gecko codes..."));
}
}
break;
case SYNC_CODES_DATA_GECKO:
void NetPlayClient::OnSyncCodesDataGecko(sf::Packet& packet)
{
// Return if this is the host
if (m_local_player->IsHost())
return 0;
return;
// Create a synced code vector
std::vector<Gecko::GeckoCode> synced_codes;
// Create a GeckoCode
Gecko::GeckoCode gcode;
gcode = Gecko::GeckoCode();
// Initialize gcode
synced_codes.reserve(m_sync_gecko_codes_count);
Gecko::GeckoCode gcode{};
gcode.name = "Synced Codes";
gcode.enabled = true;
// Receive code contents from packet
for (int i = 0; i < m_sync_gecko_codes_count; i++)
for (u32 i = 0; i < m_sync_gecko_codes_count; i++)
{
Gecko::GeckoCode::Code new_code;
packet >> new_code.address;
@ -1208,13 +1346,12 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
// Copy this to the vector located in GeckoCode.cpp
Gecko::UpdateSyncedCodes(synced_codes);
}
break;
case SYNC_CODES_NOTIFY_AR:
void NetPlayClient::OnSyncCodesNotifyAR(sf::Packet& packet)
{
// Return if this is the host
if (m_local_player->IsHost())
return 0;
return;
// Receive Number of Codelines to Receive
packet >> m_sync_ar_codes_count;
@ -1234,25 +1371,22 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->AppendChat(Common::GetStringT("Synchronizing AR codes..."));
}
}
break;
case SYNC_CODES_DATA_AR:
void NetPlayClient::OnSyncCodesDataAR(sf::Packet& packet)
{
// Return if this is the host
if (m_local_player->IsHost())
return 0;
return;
// Create a synced code vector
std::vector<ActionReplay::ARCode> synced_codes;
// Create an ARCode
ActionReplay::ARCode arcode;
arcode = ActionReplay::ARCode();
// Initialize arcode
synced_codes.reserve(m_sync_ar_codes_count);
ActionReplay::ARCode arcode{};
arcode.name = "Synced Codes";
arcode.enabled = true;
// Receive code contents from packet
for (int i = 0; i < m_sync_ar_codes_count; i++)
for (u32 i = 0; i < m_sync_ar_codes_count; i++)
{
ActionReplay::AREntry new_code;
packet >> new_code.cmd_addr;
@ -1278,21 +1412,16 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
// Copy this to the vector located in ActionReplay.cpp
ActionReplay::UpdateSyncedCodes(synced_codes);
}
break;
}
}
break;
case NP_MSG_COMPUTE_MD5:
void NetPlayClient::OnComputeMD5(sf::Packet& packet)
{
SyncIdentifier sync_identifier;
ReceiveSyncIdentifier(packet, sync_identifier);
ComputeMD5(sync_identifier);
}
break;
case NP_MSG_MD5_PROGRESS:
void NetPlayClient::OnMD5Progress(sf::Packet& packet)
{
PlayerId pid;
int progress;
@ -1301,9 +1430,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->SetMD5Progress(pid, progress);
}
break;
case NP_MSG_MD5_RESULT:
void NetPlayClient::OnMD5Result(sf::Packet& packet)
{
PlayerId pid;
std::string result;
@ -1312,9 +1440,8 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->SetMD5Result(pid, result);
}
break;
case NP_MSG_MD5_ERROR:
void NetPlayClient::OnMD5Error(sf::Packet& packet)
{
PlayerId pid;
std::string error;
@ -1323,22 +1450,12 @@ unsigned int NetPlayClient::OnData(sf::Packet& packet)
m_dialog->SetMD5Result(pid, error);
}
break;
case NP_MSG_MD5_ABORT:
void NetPlayClient::OnMD5Abort()
{
m_should_compute_MD5 = false;
m_dialog->AbortMD5();
}
break;
default:
PanicAlertFmtT("Unknown message received with id : {0}", mid);
break;
}
return 0;
}
void NetPlayClient::Send(const sf::Packet& packet, const u8 channel_id)
{

View File

@ -232,7 +232,6 @@ private:
void UpdateDevices();
void AddPadStateToPacket(int in_game_pad, const GCPadStatus& np, sf::Packet& packet);
void SendWiimoteState(int in_game_pad, const WiimoteInput& nw);
unsigned int OnData(sf::Packet& packet);
void Send(const sf::Packet& packet, u8 channel_id = DEFAULT_CHANNEL);
void Disconnect();
bool Connect();
@ -241,6 +240,51 @@ private:
void DisplayPlayersPing();
u32 GetPlayersMaxPing() const;
u32 OnData(sf::Packet& packet);
void OnPlayerJoin(sf::Packet& packet);
void OnPlayerLeave(sf::Packet& packet);
void OnChatMessage(sf::Packet& packet);
void OnChunkedDataStart(sf::Packet& packet);
void OnChunkedDataEnd(sf::Packet& packet);
void OnChunkedDataPayload(sf::Packet& packet);
void OnChunkedDataAbort(sf::Packet& packet);
void OnPadMapping(sf::Packet& packet);
void OnWiimoteMapping(sf::Packet& packet);
void OnGBAConfig(sf::Packet& packet);
void OnPadData(sf::Packet& packet);
void OnPadHostData(sf::Packet& packet);
void OnWiimoteData(sf::Packet& packet);
void OnPadBuffer(sf::Packet& packet);
void OnHostInputAuthority(sf::Packet& packet);
void OnGolfSwitch(sf::Packet& packet);
void OnGolfPrepare(sf::Packet& packet);
void OnChangeGame(sf::Packet& packet);
void OnGameStatus(sf::Packet& packet);
void OnStartGame(sf::Packet& packet);
void OnStopGame(sf::Packet& packet);
void OnPowerButton();
void OnPing(sf::Packet& packet);
void OnPlayerPingData(sf::Packet& packet);
void OnDesyncDetected(sf::Packet& packet);
void OnSyncGCSRAM(sf::Packet& packet);
void OnSyncSaveData(sf::Packet& packet);
void OnSyncSaveDataNotify(sf::Packet& packet);
void OnSyncSaveDataRaw(sf::Packet& packet);
void OnSyncSaveDataGCI(sf::Packet& packet);
void OnSyncSaveDataWii(sf::Packet& packet);
void OnSyncSaveDataGBA(sf::Packet& packet);
void OnSyncCodes(sf::Packet& packet);
void OnSyncCodesNotify();
void OnSyncCodesNotifyGecko(sf::Packet& packet);
void OnSyncCodesDataGecko(sf::Packet& packet);
void OnSyncCodesNotifyAR(sf::Packet& packet);
void OnSyncCodesDataAR(sf::Packet& packet);
void OnComputeMD5(sf::Packet& packet);
void OnMD5Progress(sf::Packet& packet);
void OnMD5Result(sf::Packet& packet);
void OnMD5Error(sf::Packet& packet);
void OnMD5Abort();
bool m_is_connected = false;
ConnectionState m_connection_state = ConnectionState::Failure;