[Netplay] Allow a spectator to leave without affecting players.
This commit is contained in:
parent
5a212a8fe0
commit
f605ea9eeb
|
@ -228,21 +228,28 @@ unsigned int NetPlayServer::OnConnect(sf::SocketTCP& socket)
|
||||||
// called from ---NETPLAY--- thread
|
// called from ---NETPLAY--- thread
|
||||||
unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket)
|
unsigned int NetPlayServer::OnDisconnect(sf::SocketTCP& socket)
|
||||||
{
|
{
|
||||||
|
PlayerId pid = m_players[socket].pid;
|
||||||
|
|
||||||
if (m_is_running)
|
if (m_is_running)
|
||||||
{
|
{
|
||||||
PanicAlertT("Client disconnect while game is running!! NetPlay is disabled. You must manually stop the game.");
|
for (int i = 0; i < 4; i++)
|
||||||
std::lock_guard<std::recursive_mutex> lkg(m_crit.game);
|
{
|
||||||
m_is_running = false;
|
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;
|
||||||
|
|
||||||
sf::Packet spac;
|
sf::Packet spac;
|
||||||
spac << (MessageId)NP_MSG_DISABLE_GAME;
|
spac << (MessageId)NP_MSG_DISABLE_GAME;
|
||||||
// this thread doesn't need players lock
|
// this thread doesn't need players lock
|
||||||
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
std::lock_guard<std::recursive_mutex> lks(m_crit.send);
|
||||||
SendToClients(spac);
|
SendToClients(spac);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerId pid = m_players[socket].pid;
|
|
||||||
|
|
||||||
sf::Packet spac;
|
sf::Packet spac;
|
||||||
spac << (MessageId)NP_MSG_PLAYER_LEAVE;
|
spac << (MessageId)NP_MSG_PLAYER_LEAVE;
|
||||||
spac << pid;
|
spac << pid;
|
||||||
|
|
Loading…
Reference in New Issue