Skip to content

Commit

Permalink
[Netplay] Allow a spectator to leave without affecting players.
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelBryk committed Oct 17, 2013
1 parent 5a212a8 commit f605ea9
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions Source/Core/Core/Src/NetPlayServer.cpp
Expand Up @@ -228,20 +228,27 @@ unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket)
// called from ---NETPLAY--- thread
unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket)
{
PlayerId pid = m_players[socket].pid;

if (m_is_running)
{
PanicAlertT("Client disconnect while game is running!! NetPlay is disabled. You must manually stop the game.");
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
m_is_running = false;

sf::Packet spac;
spac << (MessageId)NP_MSG_DISABLE_GAME;
// this thread doesn't need players lock
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac);
}
for (int i = 0; i < 4; i++)
{
if (m_pad_map[i] == pid)
{
PanicAlertT("Client disconnect while game is running!! NetPlay is disabled. You must manually stop the game.");
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
m_is_running = false;

PlayerId pid = m_players[socket].pid;
sf::Packet spac;
spac << (MessageId)NP_MSG_DISABLE_GAME;
// this thread doesn't need players lock
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
SendToClients(spac);
break;
}
}
}

sf::Packet spac;
spac << (MessageId)NP_MSG_PLAYER_LEAVE;
Expand Down

0 comments on commit f605ea9

Please sign in to comment.