Core/NetPlayServer: Sync SRAM on every game start

This solves the issue of booting games locally while connected to
NetPlay causing desync.
This commit is contained in:
Techjar 2020-01-19 03:42:23 -05:00
parent c74b1140a5
commit de27dcebf6
1 changed files with 15 additions and 15 deletions

View File

@ -434,21 +434,6 @@ unsigned int NetPlayServer::OnConnect(ENetPeer* socket, sf::Packet& rpac)
spac << m_host_input_authority;
Send(player.socket, spac);
// sync GC SRAM with new client
if (!g_SRAM_netplay_initialized)
{
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
InitSRAM();
g_SRAM_netplay_initialized = true;
}
spac.clear();
spac << static_cast<MessageId>(NP_MSG_SYNC_GC_SRAM);
for (size_t i = 0; i < sizeof(g_SRAM) - offsetof(Sram, settings); ++i)
{
spac << g_SRAM[offsetof(Sram, settings) + i];
}
Send(player.socket, spac);
// sync values with new client
for (const auto& p : m_players)
{
@ -1275,6 +1260,21 @@ bool NetPlayServer::StartGame()
const std::string region = SConfig::GetDirectoryForRegion(
SConfig::ToGameCubeRegion(m_dialog->FindGameFile(m_selected_game)->GetRegion()));
// sync GC SRAM with clients
if (!g_SRAM_netplay_initialized)
{
SConfig::GetInstance().m_strSRAM = File::GetUserPath(F_GCSRAM_IDX);
InitSRAM();
g_SRAM_netplay_initialized = true;
}
sf::Packet srampac;
srampac << static_cast<MessageId>(NP_MSG_SYNC_GC_SRAM);
for (size_t i = 0; i < sizeof(g_SRAM) - offsetof(Sram, settings); ++i)
{
srampac << g_SRAM[offsetof(Sram, settings) + i];
}
SendAsyncToClients(std::move(srampac), 1);
// tell clients to start game
sf::Packet spac;
spac << static_cast<MessageId>(NP_MSG_START_GAME);