2011-07-02 14:38:06 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
* PokerTH - The open source texas holdem engine *
|
2012-12-25 15:06:23 +01:00
|
|
|
* Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
|
2011-07-02 14:38:06 +00:00
|
|
|
* *
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as *
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* GNU Affero General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2012-12-25 15:06:23 +01:00
|
|
|
* *
|
|
|
|
|
* *
|
|
|
|
|
* Additional permission under GNU AGPL version 3 section 7 *
|
|
|
|
|
* *
|
|
|
|
|
* If you modify this program, or any covered work, by linking or *
|
|
|
|
|
* combining it with the OpenSSL project's OpenSSL library (or a *
|
|
|
|
|
* modified version of that library), containing parts covered by the *
|
|
|
|
|
* terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
|
|
|
|
|
* (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
|
|
|
|
|
* permission to convey the resulting work. *
|
|
|
|
|
* Corresponding Source for a non-source form of such a combination *
|
|
|
|
|
* shall include the source code for the parts of OpenSSL used as well *
|
|
|
|
|
* as that of the covered work. *
|
2011-07-02 14:38:06 +00:00
|
|
|
*****************************************************************************/
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
#include <net/sessionmanager.h>
|
2009-06-07 08:51:43 +00:00
|
|
|
#include <net/senderhelper.h>
|
2007-11-16 15:24:25 +00:00
|
|
|
#include <net/serverexception.h>
|
|
|
|
|
#include <net/socket_msg.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
2016-07-19 14:01:13 +02:00
|
|
|
#define SERVER_MAX_GUEST_USERS_LOBBY 50 // LG: Maximum number of guests users in lobby allowed
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionManager::SessionManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SessionManager::~SessionManager()
|
|
|
|
|
{
|
2009-06-04 22:13:52 +00:00
|
|
|
Clear();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
SessionManager::AddSession(boost::shared_ptr<SessionData> session)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
SessionMap::iterator pos = m_sessionMap.lower_bound(session->GetId());
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
// If pos points to a pair whose key is equivalent to the socket, this handle
|
|
|
|
|
// already exists within the list.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (pos != m_sessionMap.end() && session->GetId() == pos->first) {
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_SOCK_CONN_EXISTS, 0);
|
|
|
|
|
}
|
2011-03-10 20:55:46 +00:00
|
|
|
m_sessionMap.insert(pos, SessionMap::value_type(session->GetId(), session));
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SessionManager::SetSessionPlayerData(SessionId session, boost::shared_ptr<PlayerData> playerData)
|
|
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionMap::iterator pos = m_sessionMap.find(session);
|
|
|
|
|
|
|
|
|
|
if (pos != m_sessionMap.end())
|
2011-03-10 20:55:46 +00:00
|
|
|
pos->second->SetPlayerData(playerData);
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2010-09-26 06:58:49 +00:00
|
|
|
bool
|
2007-11-16 15:24:25 +00:00
|
|
|
SessionManager::RemoveSession(SessionId session)
|
|
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2010-09-26 06:58:49 +00:00
|
|
|
return m_sessionMap.erase(session) == 1;
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData>
|
2008-05-11 21:41:30 +00:00
|
|
|
SessionManager::GetSessionById(SessionId id) const
|
|
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession;
|
2008-05-11 21:41:30 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
|
|
|
|
SessionMap::const_iterator pos = m_sessionMap.find(id);
|
|
|
|
|
if (pos != m_sessionMap.end())
|
|
|
|
|
tmpSession = pos->second;
|
|
|
|
|
return tmpSession;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData>
|
2011-02-08 16:00:43 +00:00
|
|
|
SessionManager::GetSessionByPlayerName(const string &playerName) const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession;
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (session_i != session_end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Check all players which are fully connected.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session_i->second->GetState() != SessionData::Init) {
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second->GetPlayerData());
|
|
|
|
|
if (!tmpPlayer)
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpPlayer->GetName() == playerName) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpSession = session_i->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++session_i;
|
|
|
|
|
}
|
|
|
|
|
return tmpSession;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData>
|
2009-09-27 21:46:44 +00:00
|
|
|
SessionManager::GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions) const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession;
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (session_i != session_end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Check all players which are fully connected.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (initSessions || session_i->second->GetState() != SessionData::Init) {
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second->GetPlayerData());
|
2011-02-11 20:02:08 +00:00
|
|
|
if (tmpPlayer && tmpPlayer->GetUniqueId() == uniqueId) {
|
2007-11-16 15:24:25 +00:00
|
|
|
tmpSession = session_i->second;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++session_i;
|
|
|
|
|
}
|
|
|
|
|
return tmpSession;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerDataList
|
|
|
|
|
SessionManager::GetPlayerDataList() const
|
|
|
|
|
{
|
|
|
|
|
PlayerDataList playerList;
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (session_i != session_end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Get all players in the game.
|
2011-03-10 20:55:46 +00:00
|
|
|
if (session_i->second->GetState() == SessionData::Game) {
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second->GetPlayerData());
|
2007-11-16 15:24:25 +00:00
|
|
|
if (!tmpPlayer.get() || tmpPlayer->GetName().empty())
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
|
|
|
|
playerList.push_back(tmpPlayer);
|
|
|
|
|
}
|
|
|
|
|
++session_i;
|
|
|
|
|
}
|
|
|
|
|
return playerList;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-28 18:58:43 +02:00
|
|
|
PlayerDataList
|
|
|
|
|
SessionManager::GetSpectatorDataList() const
|
|
|
|
|
{
|
|
|
|
|
PlayerDataList spectatorList;
|
|
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
|
|
|
|
|
|
|
|
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
|
|
|
|
|
|
|
|
|
while (session_i != session_end) {
|
|
|
|
|
// Get all spectators of the game.
|
|
|
|
|
if (session_i->second->GetState() == SessionData::Spectating || session_i->second->GetState() == SessionData::SpectatorWaiting) {
|
|
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second->GetPlayerData());
|
|
|
|
|
if (!tmpPlayer.get() || tmpPlayer->GetName().empty())
|
|
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
|
|
|
|
spectatorList.push_back(tmpPlayer);
|
|
|
|
|
}
|
|
|
|
|
++session_i;
|
|
|
|
|
}
|
|
|
|
|
return spectatorList;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
PlayerIdList
|
2013-06-16 10:43:13 +02:00
|
|
|
SessionManager::GetPlayerIdList(int state) const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
|
|
|
|
PlayerIdList playerList;
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (session_i != session_end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Get all players in the game.
|
2013-06-16 15:56:34 +02:00
|
|
|
if ((session_i->second->GetState() & state) != 0) {
|
2011-03-10 20:55:46 +00:00
|
|
|
playerList.push_back(session_i->second->GetPlayerData()->GetUniqueId());
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
++session_i;
|
|
|
|
|
}
|
|
|
|
|
return playerList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
SessionManager::IsPlayerConnected(const string &playerName) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = GetSessionByPlayerName(playerName);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (tmpSession && tmpSession->GetPlayerData())
|
2007-11-16 15:24:25 +00:00
|
|
|
retVal = true;
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
SessionManager::IsPlayerConnected(unsigned uniqueId) const
|
|
|
|
|
{
|
|
|
|
|
bool retVal = false;
|
|
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
boost::shared_ptr<SessionData> tmpSession = GetSessionByUniquePlayerId(uniqueId);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2011-03-10 20:55:46 +00:00
|
|
|
if (tmpSession && tmpSession->GetPlayerData())
|
2007-11-16 15:24:25 +00:00
|
|
|
retVal = true;
|
|
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-02 19:50:49 +00:00
|
|
|
bool
|
|
|
|
|
SessionManager::IsClientAddressConnected(const std::string &clientAddress) 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();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
if ((*i).second->GetClientAddr() == clientAddress) {
|
2010-10-02 19:50:49 +00:00
|
|
|
retVal = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-17 18:02:10 +02:00
|
|
|
bool
|
2016-07-19 14:01:13 +02:00
|
|
|
SessionManager::IsGuestAllowedToConnect(const std::string &clientAddress) const
|
2016-06-17 18:02:10 +02:00
|
|
|
{
|
2016-07-19 14:01:13 +02:00
|
|
|
bool retVal = true;
|
2016-06-17 18:02:10 +02:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
|
|
|
|
|
|
|
|
|
SessionMap::const_iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator end = m_sessionMap.end();
|
|
|
|
|
|
2016-07-19 14:01:13 +02:00
|
|
|
int num = 0;
|
2016-06-17 18:02:10 +02:00
|
|
|
while (i != end) {
|
2016-06-18 15:42:38 +02:00
|
|
|
boost::shared_ptr<PlayerData> tmpPlayer(i->second->GetPlayerData());
|
2016-07-30 17:23:16 +02:00
|
|
|
if(tmpPlayer && tmpPlayer->GetRights() == PLAYER_RIGHTS_GUEST) {
|
2016-07-19 14:01:13 +02:00
|
|
|
num++;
|
2016-07-30 17:23:16 +02:00
|
|
|
if(i->second->GetClientAddr() == clientAddress) {
|
2016-07-19 14:01:13 +02:00
|
|
|
// guest has same ip as another guest in lobby or
|
|
|
|
|
// number of guests in lobby >= SERVER_MAX_GUEST_USERS_LOBBY => not allowed
|
|
|
|
|
retVal = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-07-12 18:36:25 +02:00
|
|
|
}
|
2016-06-17 18:02:10 +02:00
|
|
|
++i;
|
|
|
|
|
}
|
2016-07-30 17:23:16 +02:00
|
|
|
|
|
|
|
|
// Check if number of players in lobby exceeds max
|
|
|
|
|
if (num >= SERVER_MAX_GUEST_USERS_LOBBY) retVal = false;
|
|
|
|
|
|
2016-06-17 18:02:10 +02:00
|
|
|
return retVal;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2011-03-10 20:55:46 +00:00
|
|
|
SessionManager::ForEach(boost::function<void (boost::shared_ptr<SessionData>)> func)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2008-03-04 23:47:45 +00:00
|
|
|
|
|
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2008-03-04 23:47:45 +00:00
|
|
|
SessionMap::iterator next = i;
|
2011-02-09 14:33:39 +00:00
|
|
|
++next;
|
2008-03-06 15:27:31 +00:00
|
|
|
func((*i).second);
|
2008-03-04 23:47:45 +00:00
|
|
|
i = next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
unsigned
|
|
|
|
|
SessionManager::CountReadySessions() const
|
|
|
|
|
{
|
|
|
|
|
unsigned counter = 0;
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::const_iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::const_iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
if ((*i).second->IsReady())
|
2007-11-16 15:24:25 +00:00
|
|
|
++counter;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return counter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SessionManager::ResetAllReadyFlags()
|
|
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
(*i).second->ResetReadyFlag();
|
2007-11-16 15:24:25 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
SessionManager::Clear()
|
|
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2009-06-04 22:13:52 +00:00
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
2007-11-16 15:24:25 +00:00
|
|
|
|
2009-08-17 10:11:51 +00:00
|
|
|
boost::system::error_code ec;
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2013-09-15 22:54:45 +02:00
|
|
|
// Close all raw handles.
|
|
|
|
|
i->second->CloseSocketHandle();
|
|
|
|
|
i->second->CloseWebSocketHandle();
|
2009-06-04 22:13:52 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
2007-11-16 15:24:25 +00:00
|
|
|
m_sessionMap.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned
|
2013-09-02 00:37:02 +02:00
|
|
|
SessionManager::GetRawSessionCount() const
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2011-04-10 10:04:42 +00:00
|
|
|
return (unsigned)m_sessionMap.size();
|
2007-11-16 15:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-13 17:24:40 +00:00
|
|
|
unsigned
|
2013-09-02 00:37:02 +02:00
|
|
|
SessionManager::GetSessionCountWithState(int state) const
|
2011-02-13 17:24:40 +00:00
|
|
|
{
|
|
|
|
|
unsigned counter = 0;
|
|
|
|
|
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) {
|
2013-06-29 23:44:00 +02:00
|
|
|
if ((i->second->GetState() & state) != 0)
|
2011-02-13 17:24:40 +00:00
|
|
|
++counter;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return counter;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-02 00:37:02 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2013-06-16 10:43:13 +02:00
|
|
|
SessionManager::SendToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!i->second.get())
|
2007-11-16 15:24:25 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
|
|
|
|
|
|
|
|
|
// Send each client (with a certain state) a copy of the packet.
|
2013-06-16 15:56:34 +02:00
|
|
|
if ((i->second->GetState() & state) != 0)
|
2011-03-10 20:55:46 +00:00
|
|
|
sender.Send(i->second, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-05-11 21:41:30 +00:00
|
|
|
void
|
2013-06-16 10:43:13 +02:00
|
|
|
SessionManager::SendLobbyMsgToAllSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, int state)
|
2008-05-11 21:41:30 +00:00
|
|
|
{
|
|
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
|
|
|
|
|
|
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2011-03-10 20:55:46 +00:00
|
|
|
if (!i->second.get())
|
2008-05-11 21:41:30 +00:00
|
|
|
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
|
|
|
|
|
|
|
|
|
|
// Send each client (with a certain state) a copy of the packet.
|
2013-06-16 15:56:34 +02:00
|
|
|
if ((i->second->GetState() & state) != 0 && i->second->WantsLobbyMsg())
|
2011-03-10 20:55:46 +00:00
|
|
|
sender.Send(i->second, packet);
|
2008-05-11 21:41:30 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-16 15:24:25 +00:00
|
|
|
void
|
2013-06-16 10:43:13 +02:00
|
|
|
SessionManager::SendToAllButOneSessions(SenderHelper &sender, boost::shared_ptr<NetPacket> packet, SessionId except, int state)
|
2007-11-16 15:24:25 +00:00
|
|
|
{
|
2008-03-06 15:27:31 +00:00
|
|
|
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
|
2007-11-16 15:24:25 +00:00
|
|
|
|
|
|
|
|
SessionMap::iterator i = m_sessionMap.begin();
|
|
|
|
|
SessionMap::iterator end = m_sessionMap.end();
|
|
|
|
|
|
2011-02-11 20:02:08 +00:00
|
|
|
while (i != end) {
|
2007-11-16 15:24:25 +00:00
|
|
|
// Send each fully connected client but one a copy of the packet.
|
2013-06-16 15:56:34 +02:00
|
|
|
if ((i->second->GetState() & state) != 0)
|
2007-11-16 15:24:25 +00:00
|
|
|
if (i->first != except)
|
2011-03-10 20:55:46 +00:00
|
|
|
sender.Send(i->second, packet);
|
2007-11-16 15:24:25 +00:00
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-07-18 19:35:59 +02:00
|
|
|
|