void CGameServerChannel::OnDisconnect(EDisconnectionCause cause, const char *description)
{
	//CryLogAlways("CGameServerChannel::OnDisconnect(%d, '%s')", cause, description?description:"");
  CCryAction::GetCryAction()->OnActionEvent(SActionEvent(eAE_clientDisconnected,int(cause),description));

	IGameRules *pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules();

	if (pGameRules && IsOnHold())
	{
		pGameRules->OnClientDisconnect(GetChannelId(), cause, description, false);
		Cleanup();

		return;
	}

	if (sv_timeout_disconnect && pGameRules && sv_timeout_disconnect->GetIVal()>0 && pGameRules->ShouldKeepClient(GetChannelId(), cause, description))
	{
		if (m_pServerNub->PutChannelOnHold(this))
		{
			pGameRules->OnClientDisconnect(GetChannelId(), cause, description, true);
			m_hasLoadedLevel=false;
			return;
		}
	}

	if (pGameRules)
		pGameRules->OnClientDisconnect(GetChannelId(), cause, description, false);
	Cleanup();
}
//------------------------------------------------------------------------
void CGameServerNub::ResetOnHoldChannels()
{
	for (THoldChannelMap::iterator it=m_onhold.begin(); it!=m_onhold.end(); ++it)
	{
		IGameRules *pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules();
		pGameRules->OnClientDisconnect(it->first,eDC_Timeout,"OnHold reseted",false);
		TServerChannelMap::iterator ch_it = m_channels.find(it->first);
		if(ch_it!=m_channels.end())
		{
			delete ch_it->second;
			m_channels.erase(ch_it);
		}
	}
	m_onhold.clear();
}
//------------------------------------------------------------------------
void CGameServerNub::RemoveOnHoldChannel(CGameServerChannel *pServerChannel, bool renewed)
{
	for (THoldChannelMap::iterator it=m_onhold.begin(); it!=m_onhold.end(); ++it)
	{
		if (it->second.channelId == pServerChannel->GetChannelId())
		{
			m_onhold.erase(it);
			if(!renewed)//let gamerules know we should get rid of it...
			{
				IGameRules *pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules();
				pGameRules->OnClientDisconnect(pServerChannel->GetChannelId(),eDC_Timeout,"OnHold timed out",false);
			}				
			break;
		}
	}

	if(!renewed)
	{
		stl::member_find_and_erase(m_channels, pServerChannel->GetChannelId());

		delete pServerChannel;
	}	
}