Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'netplay-stop-fix'
Fixes issue 6511.
  • Loading branch information
RachelBryk committed Sep 3, 2013
2 parents eb8e03f + 7d09e72 commit 3ff81c9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 22 deletions.
19 changes: 19 additions & 0 deletions Source/Core/Core/Src/NetPlayClient.cpp
Expand Up @@ -564,6 +564,25 @@ bool NetPlayClient::StopGame()
return true;
}

void NetPlayClient::Stop()
{
if (m_is_running == false)
return;
bool isPadMapped = false;
for (unsigned int i = 0; i < 4; ++i)
{
if (m_pad_map[i] == m_local_player->pid)
isPadMapped = true;
}
// tell the server to stop if we have a pad mapped in game.
if (isPadMapped)
{
sf::Packet spac;
spac << (MessageId)NP_MSG_STOP_GAME;
m_socket.Send(spac);
}
}

// called from ---CPU--- thread
u8 NetPlayClient::GetPadNum(u8 numPAD)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/Src/NetPlayClient.h
Expand Up @@ -74,6 +74,7 @@ class NetPlayClient

bool StartGame(const std::string &path);
bool StopGame();
void Stop();
bool ChangeGame(const std::string& game);
void SendChatMessage(const std::string& msg);

Expand Down
31 changes: 14 additions & 17 deletions Source/Core/Core/Src/NetPlayServer.cpp
Expand Up @@ -376,6 +376,20 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, sf::SocketTCP& socket)
}
break;

case NP_MSG_STOP_GAME:
{
// tell clients to stop game
sf::Packet spac;
spac << (MessageId)NP_MSG_STOP_GAME;

std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac);

m_is_running = false;
}
break;

default :
PanicAlertT("Unknown message with id:%d received from player:%d Kicking player!", mid, player.pid);
// unknown message, kick the client
Expand Down Expand Up @@ -451,23 +465,6 @@ bool NetPlayServer::StartGame(const std::string &path)
return true;
}


// called from ---GUI--- thread
bool NetPlayServer::StopGame()
{
// tell clients to stop game
sf::Packet spac;
spac << (MessageId)NP_MSG_STOP_GAME;

std::lock_guard<std::recursive_mutex> lkp(m_crit.players);
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac);

m_is_running = false;

return true;
}

// called from multiple threads
void NetPlayServer::SendToClients(sf::Packet& packet, const PlayerId skip_pid)
{
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/Src/NetPlayServer.h
Expand Up @@ -33,7 +33,6 @@ class NetPlayServer
void SetNetSettings(const NetSettings &settings);

bool StartGame(const std::string &path);
bool StopGame();

void GetPadMapping(PadMapping map[]);
void SetPadMapping(const PadMapping map[]);
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/DolphinWX/Src/NetWindow.cpp
Expand Up @@ -650,8 +650,6 @@ void PadMapDiag::OnAdjust(wxCommandEvent& event)

void NetPlay::StopGame()
{
if (netplay_server != NULL)
netplay_server->StopGame();

// TODO: allow non-hosting clients to close the window
if (netplay_client != NULL)
netplay_client->Stop();
}

0 comments on commit 3ff81c9

Please sign in to comment.