Beispiel #1
0
bool my::GateServer::kickConnection(ConnectionPtr conn)
{
	int netId = conn->getNetId();
	if (netId < 0)
	{
		//server, don't do anything stupid
	}
	else
	{
		boost::recursive_mutex::scoped_lock lock(mtx);
		ConnectionMap::iterator it = m_ConnMap.find(netId);
		if (it != m_ConnMap.end())
		{
			ConnectionPtr tmpConn = it->second;
			m_ConnMap.erase(it);//应检查conn和tmpConn是否相同
			m_nConnCount--;
			int playerId = conn->getPlayerId();
			kickPlayer(playerId, netId);
			tmpConn->stop();
			LogD << "erase from connMap" << LogEnd;
			return true;
		}
	}
	return false;
}
Beispiel #2
0
void my::GateServer::checkHeartBeat(boost::system_time tmp)
{
	ConnectionMap::iterator it = m_ConnMap.begin();
	for (; it != m_ConnMap.end(); )
	{
		ConnectionPtr conn = it->second;
		++it;
		if ((tmp - conn->getHeartBeat()).total_seconds() > 180)//一分钟没心跳,死了吧
		{
			LogW << "Connection is dead, kick it! netId=" << conn->getNetId() << "  playerId=" << conn->getPlayerId() << LogEnd;
			kickConnection(conn); //todo kick
		}
	}
}