Ejemplo n.º 1
0
void ForServerMsgHandler::NofityClientExit(BaseSession* pSession, const NetMsgHead* pMsg,int32 nSize)
{
	const SSNofityClientExit* pPacket = static_cast<const SSNofityClientExit*>(pMsg);
	int32 nClientSessionID = pPacket->nClientSessionID;

	ClientSession* pClientSession = ClientSessionMgr::Instance()->GetSession(nClientSessionID);
	ASSERT(pClientSession);

	// 同步或保存重要数据到dp

	// 通知ls,ss
	SSNofityClientExit sMsgExit;
	sMsgExit.nClientSessionID = nClientSessionID;

	pClientSession->SendMsgToLs(&sMsgExit,sMsgExit.GetPackLength());
	if(pClientSession->Status() == ECLIENT_STATUS_IN_SCENE)
	{
		pClientSession->SendMsgToSs(&sMsgExit,sMsgExit.GetPackLength());
	}else
	{
		// 由dp去保存退出操作
		pClientSession->SendMsgToDp(&sMsgExit,sMsgExit.GetPackLength());
	}

	// 删除
	ClientSessionMgr::Instance()->RemoveSession(nClientSessionID);

}
Ejemplo n.º 2
0
void ForServerMsgHandler::ReqRoadLest(BaseSession* pSession, const NetMsgHead* pMsg,int32 nSize)
{
	//---------------------------------服务组代码begin-------------------------------
	const SSReqLoadLest* pPacket = static_cast<const SSReqLoadLest*>(pMsg);
	int32 nClientSessionID = pPacket->nClientSessionID;
	ServerSession* pFepSession = static_cast<ServerSession*>(pSession);

	// 找出分配最小的(或上一次分配的,以后再优化)
	ServerInfoMgr* pServerInfoMgr = ServerInfoMgr::Instance();
	ServerSession* pLsSession = pServerInfoMgr->GetLoadLestSession(ESERVER_TYPE_LS);
	ServerSession* pDpSession = pServerInfoMgr->GetLoadLestSession(ESERVER_TYPE_DP);
	ASSERT(pLsSession && pDpSession);

	// 第一次创建ClientSesson数据
	ClientSession* pClientSession = ClientSessionMgr::Instance()->AddSession(nClientSessionID);
	ASSERT(pClientSession);
	pClientSession->SetForWs1(pFepSession,pLsSession,pDpSession);

	// 同步到ls,dp,fep
	SSSessionNofitySInfo sNofityInfo;
	sNofityInfo.nClientSessionID = nClientSessionID;
	sNofityInfo.nLsServerID = pLsSession->ServerID();
	sNofityInfo.nDpServerID = pDpSession->ServerID();
	sNofityInfo.nFepServerID = pFepSession->ServerID();

	// 通知分配给Client的ServerID
	pClientSession->SendMsgToLs(&sNofityInfo,sNofityInfo.GetPackLength());
	pClientSession->SendMsgToDp(&sNofityInfo,sNofityInfo.GetPackLength());
	pClientSession->SendMsgToFep(&sNofityInfo,sNofityInfo.GetPackLength());

	// 负载+1
	pServerInfoMgr->OnLoadAddOne(pLsSession->ServerID());
	pServerInfoMgr->OnLoadAddOne(pDpSession->ServerID());
	pServerInfoMgr->OnLoadAddOne(pFepSession->ServerID());
	//---------------------------------服务组代码end-------------------------------

}