Automatically close games if only spectators are left.
This commit is contained in:
@@ -1827,7 +1827,7 @@ ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec)
|
|||||||
GameMap::iterator next = i;
|
GameMap::iterator next = i;
|
||||||
++next;
|
++next;
|
||||||
boost::shared_ptr<ServerGame> tmpGame = i->second;
|
boost::shared_ptr<ServerGame> tmpGame = i->second;
|
||||||
if (!tmpGame->GetSessionManager().HasSessions())
|
if (!tmpGame->GetSessionManager().HasSessionWithState(SessionData::Game))
|
||||||
InternalRemoveGame(tmpGame); // This will delete the game.
|
InternalRemoveGame(tmpGame); // This will delete the game.
|
||||||
i = next;
|
i = next;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,13 +46,6 @@ SessionManager::~SessionManager()
|
|||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
SessionManager::HasSessions() const
|
|
||||||
{
|
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
|
||||||
return !m_sessionMap.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SessionManager::AddSession(boost::shared_ptr<SessionData> session)
|
SessionManager::AddSession(boost::shared_ptr<SessionData> session)
|
||||||
{
|
{
|
||||||
@@ -295,14 +288,14 @@ SessionManager::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
SessionManager::GetRawSessionCount()
|
SessionManager::GetRawSessionCount() const
|
||||||
{
|
{
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
return (unsigned)m_sessionMap.size();
|
return (unsigned)m_sessionMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
SessionManager::GetSessionCountWithState(int state)
|
SessionManager::GetSessionCountWithState(int state) const
|
||||||
{
|
{
|
||||||
unsigned counter = 0;
|
unsigned counter = 0;
|
||||||
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
@@ -318,6 +311,25 @@ SessionManager::GetSessionCountWithState(int state)
|
|||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
SessionManager::HasSessionWithState(int state) const
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
|
|
||||||
|
SessionMap::const_iterator i = m_sessionMap.begin();
|
||||||
|
SessionMap::const_iterator end = m_sessionMap.end();
|
||||||
|
|
||||||
|
while (i != end) {
|
||||||
|
if ((i->second->GetState() & state) != 0) {
|
||||||
|
retVal = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state)
|
SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,8 +50,6 @@ public:
|
|||||||
SessionManager();
|
SessionManager();
|
||||||
virtual ~SessionManager();
|
virtual ~SessionManager();
|
||||||
|
|
||||||
bool HasSessions() const;
|
|
||||||
|
|
||||||
void AddSession(boost::shared_ptr<SessionData> sessionData);
|
void AddSession(boost::shared_ptr<SessionData> sessionData);
|
||||||
void SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData);
|
void SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData);
|
||||||
bool RemoveSession(SessionId session);
|
bool RemoveSession(SessionId session);
|
||||||
@@ -72,8 +70,9 @@ public:
|
|||||||
void ResetAllReadyFlags();
|
void ResetAllReadyFlags();
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
unsigned GetRawSessionCount();
|
unsigned GetRawSessionCount() const;
|
||||||
unsigned GetSessionCountWithState(int state);
|
unsigned GetSessionCountWithState(int state) const;
|
||||||
|
bool HasSessionWithState(int state) const;
|
||||||
|
|
||||||
void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
void SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||||
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
void SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state);
|
||||||
|
|||||||
Reference in New Issue
Block a user