int32_t CModifyRobotConfigEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
        const uint16_t nOptionLen, const void *pOptionData)
{
    int32_t ret = S_OK;
    if(pMsgBody == NULL || pMsgHead == NULL)
    {
        WRITE_ERROR_LOG("null pointer:{pMsgHead=0x%08x, pMsgBody=0x%08x}\n",pMsgHead,pMsgBody);
        return E_NULLPOINTER;
    }

    CWebModifyRobotConfigNoti *pWebModifyRobotConfigNoti = dynamic_cast<CWebModifyRobotConfigNoti *>(pMsgBody);
    if(NULL == pWebModifyRobotConfigNoti)
    {
        WRITE_ERROR_LOG("null pointer:{pWebModifyRobotConfigNoti=0x%08x}\n",pWebModifyRobotConfigNoti);
        return E_NULLPOINTER;
    }
    WRITE_NOTICE_LOG("recv modify robot config from web{nRoomID=%d, nRobotPercent=%d, nSendPercent=%d} ",pWebModifyRobotConfigNoti->nRoomID,
                     pWebModifyRobotConfigNoti->nRobotPercent,pWebModifyRobotConfigNoti->nSendPercent);

    //获取房间
    CRoom *pRoom = NULL;
    RoomIndex nRoomIndex = enmInvalidRoomIndex;
    ret = g_RoomMgt.GetRoom(pWebModifyRobotConfigNoti->nRoomID, pRoom, nRoomIndex);
    if(ret < 0 || pRoom == NULL)
    {
        WRITE_NOTICE_LOG("room is not exit in this server!{nRoomID=%d}",pWebModifyRobotConfigNoti->nRoomID);
        return E_NULLPOINTER;
    }
    //设置房间的机器人比例,以及发送彩条的概率
    pRoom->SetRobotPercent(pWebModifyRobotConfigNoti->nRobotPercent);
    pRoom->SetRobotSendPercent(pWebModifyRobotConfigNoti->nSendPercent);
    return S_OK;
}
int32_t CUpdateSelfSettingMessageEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}

	CHallSetSelfSettingNoti *pHallSetSelfSettingNoti = dynamic_cast<CHallSetSelfSettingNoti *>(pMsgBody);
	if(NULL == pHallSetSelfSettingNoti)
	{
		WRITE_ERROR_LOG("null pointer:{pHallSetSelfSettingNoti=0x%08x, nRoleID=%d}\n",pHallSetSelfSettingNoti,pMsgHead->nRoleID);
		return E_NULLPOINTER;
	}

	CPlayer *pPlayer = NULL;
	PlayerIndex nPlayerIndex = enmInvalidPlayerIndex;
	int32_t ret = g_PlayerMgt.GetPlayer(pHallSetSelfSettingNoti->nRoleID, pPlayer, nPlayerIndex);
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_WARNING_LOG("get player object failed or player is not in this server!{RoleID=%d, ret=0x%08x}\n",pHallSetSelfSettingNoti->nRoleID, ret);
		return E_NULLPOINTER;
	}

	pPlayer->SetPlayerSelfSetting(pHallSetSelfSettingNoti->nPlayerSelfSetting);

	WRITE_NOTICE_LOG("player set self setting{nRoleID=%d, nPlayerSelfSetting=%d}",pHallSetSelfSettingNoti->nRoleID,pHallSetSelfSettingNoti->nPlayerSelfSetting);
	return S_OK;
}
int32_t COfflineMessageEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}

	COfflineNoti *pOfflineNoti = dynamic_cast<COfflineNoti *>(pMsgBody);
	if(NULL == pOfflineNoti)
	{
		WRITE_ERROR_LOG("null pointer:{pOfflineNoti=0x%08x, nRoleID=%d}\n",pOfflineNoti,pMsgHead->nRoleID,pMsgHead->nRoomID);
		return E_NULLPOINTER;
	}

	WRITE_NOTICE_LOG("oh,shit!recv offline noti{nRoleID=%d}",pOfflineNoti->nRoleID);

	CPlayer *pPlayer = NULL;
	int32_t ret = g_PlayerMgt.GetPlayer(pOfflineNoti->nRoleID, pPlayer);
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_ERROR_LOG("get player object failed{RoleID=%d, ret=0x%08x}\n",pOfflineNoti->nRoleID, ret);
	}
	else
	{
		RoomID arrRoomID[MaxEnterRoomCount];
		int32_t nRoomCount = 0;
		pPlayer->GetAllEnterRoom(arrRoomID, MaxEnterRoomCount, nRoomCount);
		for(int32_t i = 0; i < nRoomCount; ++i)
		{
			CRoom *pRoom = NULL;
			ret = g_RoomMgt.GetRoom(arrRoomID[i], pRoom);
			if(ret < 0 || pRoom == NULL)
			{
				continue;
			}

			g_RoomMgt.DeletePlayer(arrRoomID[i], pOfflineNoti->nRoleID);
		}

		g_PlayerMgt.DestroyPlayer(pOfflineNoti->nRoleID);
	}

	//销毁相对应的玩家cache数据
	for(int32_t i = 0; i < MaxRoomServerCountPerRoomDispatcher; ++i)
	{
		CPlayerCache *pPlayerCache = NULL;
		int32_t ret = g_PlayerCacheMgt(i)->GetPlayerCache(pOfflineNoti->nRoleID, pPlayerCache);
		if(ret < 0 || pPlayerCache == NULL)
		{
			continue;
		}

		g_PlayerCacheMgt(i)->DestoryPlayerCache(pOfflineNoti->nRoleID);
	}

	return S_OK;
}
FRAME_ROOMDISPATCHER_NAMESPACE_BEGIN


int32_t CServerStartNoticeMessageEvent::OnSystemEvent(uint16_t nEventID, void *pParam)
{
	MessageHeadSS *pMsgHead = (MessageHeadSS *)pParam;
	if(NULL == pMsgHead)
	{
		WRITE_ERROR_LOG("null pointer:{nEventID=0x%08x}\n",nEventID);
		return E_NULLPOINTER;
	}

	WRITE_NOTICE_LOG("recv Server start noti!{nServerType=%d, nServerID=%d}\n", pMsgHead->nSourceType, pMsgHead->nSourceID);

	if(enmEntityType_Room != pMsgHead->nSourceType && enmEntityType_Media != pMsgHead->nSourceType)
	{
		WRITE_WARNING_LOG("start server is{nServerType=%d}\n", pMsgHead->nSourceType);
		return S_OK;
	}

	ServerID nStartServerID = pMsgHead->nSourceID;
	EntityType nStartEntityType = pMsgHead->nSourceType;

	ServerLoadInfo stInfo;
	stInfo.serverID = nStartServerID;
	stInfo.loadValue = 0;
	stInfo.nLastUpdateTime = CDateTime::CurrentDateTime().Seconds();

//	CServerLoadManager stServerLoadManager;
//	stServerLoadManager.AddServerLoad(stInfo);

	ServerLoadManagerMap& stMap = g_DataCenter.GetServerLoadManagerMap();
	stMap[nStartEntityType].AddServerLoad(stInfo);

	if(enmEntityType_Media == pMsgHead->nSourceType)
	{
		CMedia *pMedia = NULL;

		int32_t ret = g_MediaMgt.GetMedia(pMsgHead->nSourceID, pMedia);
		if(ret < 0 || pMedia == NULL)
		{
			ret = g_MediaMgt.CreateMedia(pMsgHead->nSourceID, pMedia);
			if(ret < 0 || pMedia == NULL)
			{
				WRITE_ERROR_LOG("creat media filed {nServerID=%d}!",pMsgHead->nSourceID);
				return ret;
			}
		}
	}

	return S_OK;
}
FRAME_HALLSERVER_NAMESPACE_BEGIN

int32_t CLauchRoomNoticeEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(g_ServerStatus != enmServerStatus_Running)
	{
		WRITE_ERROR_LOG("server is not ready!\n");
		return E_NULLPOINTER;
	}

	if(pMsgBody == NULL || pMsgHead == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgHead=0x%08x, pMsgBody=0x%08x}\n", pMsgHead, pMsgBody);
		return E_NULLPOINTER;
	}

	CLauchRoomNotice* pLauchRoomNotice = dynamic_cast<CLauchRoomNotice*>(pMsgBody);
	if(pLauchRoomNotice == NULL)
	{
		WRITE_ERROR_LOG("null pointer:pMsgBody transform to CLauchRoomNotice class failed![nMessageID=0x%08x, nRoleID=%d]\n",
				pMsgHead->nMessageID, pLauchRoomNotice->nRoleID);
		return E_NULLPOINTER;
	}
	CPlayer* pPlayer = NULL;
	int32_t nRet = g_PlayerMgt.GetPlayer(pLauchRoomNotice->nRoleID, pPlayer);
	if(nRet < 0 || pPlayer == NULL)
	{
		WRITE_NOTICE_LOG("lauchroomnotice:player is not online!{nRoomID=%d,nRoleID=%d}",
				pLauchRoomNotice->nRoomID, pLauchRoomNotice->nRoleID);
		return S_OK;
	}
	RoleRank nPreRoleRank = enmRoleRank_None;
	pPlayer->SetAdminRoleRank(pLauchRoomNotice->nRoomID, enmRoleRank_Host,nPreRoleRank);

	CRoom *pRoom = NULL;
	nRet = g_RoomMgt.GetRoom(pLauchRoomNotice->nRoomID, pRoom);
	if(0 > nRet || pRoom == NULL)
	{
		WRITE_ERROR_LOG("get room object error!{nRoomID=%d, nRet=0x%08x}\n", pLauchRoomNotice->nRoomID, nRet);
		return nRet;
	}
	if(nPreRoleRank == enmRoleRank_TempAdmin)
	{
		int32_t TemAdminCount = pRoom->GetTempAdminCount();
		if( TemAdminCount >= 1)
		{
			pRoom->SetTempAdminCount(--TemAdminCount);
		}
	}
	return S_OK;
}
int32_t CExitRoomNoticeMessageEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}

	CExitRoomNotice *pExitRoomNotice = dynamic_cast<CExitRoomNotice *>(pMsgBody);
	if(NULL == pExitRoomNotice)
	{
		WRITE_ERROR_LOG("null pointer:{pExitRoomNotice=0x%08x, nRoleID=%d, nRoomID=%d}\n",pExitRoomNotice,pMsgHead->nRoleID,pMsgHead->nRoomID);
		return E_NULLPOINTER;
	}

	CRoom *pRoom = NULL;
	int32_t ret = g_RoomMgt.GetRoom(pExitRoomNotice->nRoomID, pRoom);
	if(ret < 0 || pRoom == NULL)
	{
		WRITE_ERROR_LOG("It's not found room object!{nRoomID=%d, nRoleID=%d}\n", pExitRoomNotice->nRoomID, pExitRoomNotice->nRoleID);
		return E_NULLPOINTER;
	}

	CPlayer *pPlayer = NULL;
	ret = g_PlayerMgt.GetPlayer(pExitRoomNotice->nRoleID, pPlayer);
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_ERROR_LOG("It's not found player object!{nRoomID=%d, nRoleID=%d}\n", pExitRoomNotice->nRoomID, pExitRoomNotice->nRoleID);
		return E_NULLPOINTER;
	}

	g_RoomMgt.DeletePlayer(pExitRoomNotice->nRoomID, pExitRoomNotice->nRoleID);
	WRITE_NOTICE_LOG("player exit room{nRoomID=%d,nRoleID=%d}\n", pExitRoomNotice->nRoomID, pExitRoomNotice->nRoleID);

	//如果玩家是机器人(没有下线通知)
	if(pPlayer->GetPlayerType() == enmPlayerType_Rebot && pPlayer->GetCurEnterRoomCount() <= 0)
	{
		//销毁玩家
		g_PlayerMgt.DestroyPlayer(pExitRoomNotice->nRoleID);
		//销毁playercache
		g_PlayerCacheMgt(pMsgHead->nSourceID)->DestoryPlayerCache(pExitRoomNotice->nRoleID);
	}

	return S_OK;
}
int32_t CUpdateVipNotiEvent::UpdateMemVipLevel(RoleID nRoleID, VipLevel nVipLevel)
{
	int32_t nRet = S_OK;
	CPlayer* pPlayer = NULL;
	nRet = g_PlayerMgt.GetPlayer(nRoleID, pPlayer);
	if(0 > nRet || pPlayer == NULL)
	{
		WRITE_NOTICE_LOG("update vip level, cannot find role object!{nRoleID=%d, nRet=0x%08x}\n", nRoleID, nRet);
		return E_NULLPOINTER;
	}
	if(nVipLevel > enmVipLevel_King || nVipLevel <= enmVipLevel_NONE)
	{
		WRITE_ERROR_LOG("update vip level, wrong vip level!{nRoleID=%d, nVipLevel=%d}\n", nRoleID, nVipLevel);
		return E_NULLPOINTER;
	}

	pPlayer->SetVipLevel(nVipLevel);
	WRITE_DEBUG_LOG("update vip level, succeed to set vip level!{nRoleID=%d, nVipLevel=%d}\n", nRoleID, nVipLevel);
	return S_OK;
}
int32_t CItemRebulidEvent::SendCreatRoomNotice()
{
	int32_t nRoomCount = 0;
	CRoom *arrRoomObject[MaxRoomCountPerServer] = {NULL};
	int32_t ret = g_RoomMgt.GetAllRoom(arrRoomObject, MaxRoomCountPerServer, nRoomCount);
	if(ret < 0)
	{
		//todo
		return ret;
	}
	for(int32_t i = 0; i < nRoomCount; ++i)
	{
		if(arrRoomObject[i] == NULL)
		{
			continue;
		}
		//房间ID不合法的时候不创建
		if(arrRoomObject[i]->GetRoomID() == enmInvalidRoomID)
		{
			continue;
		}
		//发送创建房间通知
		CCreateRoomNotice stCreateRoomNotice;
		stCreateRoomNotice.nRegionType = arrRoomObject[i]->GetRegionType();
		stCreateRoomNotice.nRegionID = arrRoomObject[i]->GetRegionID();
		stCreateRoomNotice.strRegionName = arrRoomObject[i]->GetRegionName();
		stCreateRoomNotice.nChannelType = arrRoomObject[i]->GetChannelType();
		stCreateRoomNotice.nChannelID = arrRoomObject[i]->GetChannelID();
		stCreateRoomNotice.strChannelName = arrRoomObject[i]->GetChannelName();
		stCreateRoomNotice.nRoomType = arrRoomObject[i]->GetRoomType();
		stCreateRoomNotice.nRoomID = arrRoomObject[i]->GetRoomID();
		stCreateRoomNotice.strRoomName = arrRoomObject[i]->GetRoomName();
		stCreateRoomNotice.nServerID = g_FrameConfigMgt.GetFrameBaseConfig().GetServerID();
		arrRoomObject[i]->GetMemberList(stCreateRoomNotice.nMemberCount,stCreateRoomNotice.arrRoleID,stCreateRoomNotice.arrRoleRank,MaxAdminCountPerRoom);
		stCreateRoomNotice.nHostID = arrRoomObject[i]->GetHostID();
		stCreateRoomNotice.strHostName = arrRoomObject[i]->GetHostName();
		WRITE_NOTICE_LOG("rebulid itemserver:send rebulid creat room to item [roomid= %d]",arrRoomObject[i]->GetRoomID());
		SendMessageNotifyToServer(MSGID_RSMS_CREATE_ROOM_NOTICE, &stCreateRoomNotice, arrRoomObject[i]->GetRoomID(), enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_Item);
	}
	return S_OK;
}
int32_t CItemRebulidEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}
	int32_t ret = S_OK;
	WRITE_NOTICE_LOG("rebulid :recv need rebulid  noti serverType = %d",pMsgHead->nSourceType);
	CItemRebulidCtl &stItemRebulidCtl = GET_ITEMREBULIDCTL_INSTANCE();
	stItemRebulidCtl.SetItemRebulid(pMsgHead->nSourceType);
	//发送房间的创建通知
	if(pMsgHead->nSourceType == enmEntityType_Item)
	{
		ret = SendCreatRoomNotice();
		if(ret < 0)
		{
			stItemRebulidCtl.SetItemRebulidSuccess(pMsgHead->nSourceType);
			return ret;
		}
	}
	//获取所有玩家到item_rebulid_ctl中
	ret = GetNeedRebulidPlayer(pMsgHead->nSourceType);
	if(ret<0)
	{
		stItemRebulidCtl.SetItemRebulidSuccess(pMsgHead->nSourceType);
		return ret;
	}
	//创建定时器,超时则开始更新玩家
	ret = StartTimer(pMsgHead->nSourceType);
	if (ret < 0)
	{
		stItemRebulidCtl.SetItemRebulidSuccess(pMsgHead->nSourceType);
		return ret;
	}
	return S_OK;
}
int32_t CGetRoomInfoEvent::OnEventGetRoomInfo(MessageHeadSS *pMsgHead, IMsgBody* pMsgBody,const uint16_t nOptionLen , const void *pOptionData )
{
	int32_t ret = S_OK;
	if(pMsgBody == NULL || pMsgHead == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}
	WRITE_NOTICE_LOG("rcev player get room info req{nRoleID=%d, nRoomID=%d}\n",pMsgHead->nRoleID,pMsgHead->nRoomID);
	CPlayer *pPlayer = NULL;
	PlayerIndex nPlayerIndex = enmInvalidPlayerIndex;
	ret = g_PlayerMgt.GetPlayer(pMsgHead->nRoleID, pPlayer, nPlayerIndex);
	//没有此玩家
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_ERROR_LOG("player does no exist{nRoleID=%d}",pMsgHead->nRoleID);
		return ret;
	}
	//获取房间对象
	CRoom *pRoom = NULL;
	RoomIndex nRoomIndex = enmInvalidRoomIndex;
	ret = g_RoomMgt.GetRoom(pMsgHead->nRoomID, pRoom, nRoomIndex);
	if(ret < 0 || pRoom == NULL)
	{
		WRITE_ERROR_LOG("get room error!{ret=0x%08x} \n",ret);
		return ret;
	}
	//判断玩家是否在房间roomID中
	if(!(pRoom->IsPlayerInRoom(nPlayerIndex)))
	{
		WRITE_ERROR_LOG("player does no in room{nRoleID=%d, nRoomID=%d}",pMsgHead->nRoleID,pMsgHead->nRoomID);
		return E_RS_PLAYRENOTINROOM;
	}
	//发送回应道客户端
	SendResponseToUser(pMsgHead,pRoom,nOptionLen,pOptionData);

	return ret;
}
int32_t CItemRebulidEvent::OnSessionTimeOut(CFrameSession *pSession)
{
	if(pSession == NULL)
	{
		WRITE_ERROR_LOG("pSession NULL ret=0x%08x \n",E_NULLPOINTER);
		return E_NULLPOINTER;
	}
	CServerNeedRebulidSessionData * pData =(CServerNeedRebulidSessionData *)(pSession->GetSessionData());
    if(pData == NULL)
    {
    	WRITE_ERROR_LOG("pData NULL ret=0x%08x \n",E_NULLPOINTER);
    	return E_NULLPOINTER;
    }
    WRITE_NOTICE_LOG("rebulid:start send enter room motice %d",pData->nEntityType);

    int32_t ret = SendEnterRoomNotice(pData->nEntityType);
    if(ret < 0)
    {
    	CItemRebulidCtl &stItemRebulidCtl = GET_ITEMREBULIDCTL_INSTANCE();
    	stItemRebulidCtl.SetItemRebulidSuccess(pData->nEntityType);
    }
	return S_OK;
}
int32_t CFromRoomAddEvent::UpdateAdminInRoomOnlineTimeDay(const CAddAdmInRoomOnLineTimeNotice& msgbody, const RoleRank rolerank)
{
	if(0 >= msgbody.nRoomID || 0 > msgbody.nRoleID)
	{
		WRITE_ERROR_LOG( "argument invalid while update admin inroom online time! roleid=%d, roomid=%d, year=%d, month=%d, day=%d, addtime=%d\n",
				msgbody.nRoomID,
				msgbody.nRoleID,
				msgbody.nYear,
				msgbody.nMonth,
				msgbody.nDay,
				msgbody.nAddTime);
		return E_INVALID_ARGUMENTS;
	}

	int32_t ret = S_OK;

	char szSql[enmMaxSqlStringLength] = {0};

	//不满足管理条件,只更新InRoomTimeTotal字段
	if(enmRoleRank_TempAdmin >= rolerank || enmRoleRank_Super <= rolerank)
	{
		RoleRank writen_rolerank = 0;
		WRITE_NOTICE_LOG( "the rolerank is below tempAdmin or above super amdin! just write zero into db! roomid=%d, roleid=%d, rolerank=%d\n",
				msgbody.nRoomID, msgbody.nRoleID, rolerank);

		sprintf(szSql, "insert into vdc_time.`user_room_time_%04d_%02d_%02d`(`RoleID`, `RoomID`, `RoleRank`, `InRoomTimeTotal`) values(%d, %d, %d, %d)  \
						   on duplicate key update `InRoomTimeTotal`=`InRoomTimeTotal`+%d, `RoleRank`=%d",
				msgbody.nYear,
				msgbody.nMonth,
				msgbody.nDay,
				msgbody.nRoleID,
				msgbody.nRoomID,
				writen_rolerank,
				msgbody.nAddTime,
				msgbody.nAddTime,
				writen_rolerank);
	}
int32_t CItemRebulidEvent::SendEnterRoomNotice(EntityType nEntityType)
{
	int32_t ret = S_OK;
	CItemRebulidCtl &stItemRebulidCtl = GET_ITEMREBULIDCTL_INSTANCE();
	int32_t nPlayerCount = 0;
	RoleID arrRoleID[MaxRebulidCountPer];
	stItemRebulidCtl.GetRebulidRoleID(arrRoleID,MaxRebulidCountPer,nPlayerCount,nEntityType);

	for(int32_t i = 0;i < nPlayerCount;i++)
	{
		CPlayer *pPlayer = NULL;
		PlayerIndex nPlayerIndex = enmInvalidPlayerIndex;
		ret = g_PlayerMgt.GetPlayer(arrRoleID[i], pPlayer, nPlayerIndex);
		//没有此玩家
		if(ret < 0 || pPlayer == NULL)
		{
			WRITE_ERROR_LOG("rebulid itemserver:player does no exist{nRoleID=%d}",arrRoleID[i]);
			continue;
		}
		//进入房间通知
		CEnterRoomNotice stEnterRoomNotice;
		stEnterRoomNotice.nRoleID = pPlayer->GetRoleID();
		stEnterRoomNotice.strRoleName = pPlayer->GetRoleName();
		stEnterRoomNotice.nAccountID = pPlayer->GetAccountID();
		stEnterRoomNotice.nServerID = g_FrameConfigMgt.GetFrameBaseConfig().GetServerID();
		stEnterRoomNotice.nPlayerType = pPlayer->GetPlayerType();
		stEnterRoomNotice.nIdentityType = pPlayer->GetIdentityType();
		if(pPlayer->IsHideEnter())
		{
			stEnterRoomNotice.nEnterRoomType = enmEnterRoomType_Hid;
		}

		int32_t nEnterCount = 0;
		RoomID arrEnterRoomID[MaxEnterRoomCount];
		pPlayer->GetEnterRoomInfo(arrEnterRoomID,nEnterCount,MaxEnterRoomCount);

		for(int32_t j = 0;j < nEnterCount;j++)
		{
			CRoom *pRoom = NULL;
			RoomIndex nRoomIndex = enmInvalidRoomIndex;
			ret = g_RoomMgt.GetRoom(arrEnterRoomID[j], pRoom, nRoomIndex);
			if(ret < 0 || pRoom == NULL)
			{
				WRITE_ERROR_LOG("get room error!ret=0x%08x{roomid=%d}\n",ret,arrEnterRoomID[j]);
				continue;
			}
			stEnterRoomNotice.nRoomID = arrEnterRoomID[j];
			stEnterRoomNotice.nRoleRank = pRoom->GetRoleRank(pPlayer->GetRoleID());
			stEnterRoomNotice.nRoomType = pRoom->GetRoomType();
			WRITE_NOTICE_LOG("rebulid itemserver:send rebulid enter room notice to item {nRoomID=%d, nRoleID=%d}",arrEnterRoomID[j],pPlayer->GetRoleID());
			SendMessageNotifyToServer(MSGID_RSMS_ENTER_ROOM_NOTICE, &stEnterRoomNotice,arrEnterRoomID[j] , enmTransType_Broadcast, pPlayer->GetRoleID(), nEntityType);
		}
	}
	if(nPlayerCount == MaxRebulidCountPer)
	{
		WRITE_NOTICE_LOG("rebulid :start other timer to rebulid %d!",nEntityType );
		ret = StartTimer(nEntityType);
	}
	else
	{
		WRITE_NOTICE_LOG("rebulid :rebulid %d ok!",nEntityType);
		stItemRebulidCtl.SetItemRebulidSuccess(nEntityType);
	}
	return ret;
}
Example #14
0
int32_t CLockIPEvent::OnEventLockIP(MessageHeadSS *pMsgHead, IMsgBody* pMsgBody,const uint16_t nOptionLen , const void *pOptionData )
{
	int32_t ret = S_OK;
	if(pMsgBody == NULL || pMsgHead == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}
	CLockIpReq *pLockIpReq = dynamic_cast<CLockIpReq *>(pMsgBody);
	if(pLockIpReq == NULL)
	{
		WRITE_ERROR_LOG("pLockIpReq null  ret=0x%08x \n",E_NULLPOINTER);
		return E_NULLPOINTER;
	}
	WRITE_NOTICE_LOG("rcev player lock other ip req{nRoleID=%d, nRoomID=%d, nDestRoleID=%d}\n",pMsgHead->nRoleID,pMsgHead->nRoomID,pLockIpReq->nDestRoleID);
	CPlayer *pPlayer = NULL;
	PlayerIndex nPlayerIndex = enmInvalidPlayerIndex;
	ret = g_PlayerMgt.GetPlayer(pMsgHead->nRoleID, pPlayer, nPlayerIndex);
	//没有此玩家
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_ERROR_LOG("player does no exist{nSrcRoleID=%d}",pMsgHead->nRoleID);
		return ret;
	}
	//获取房间对象
	CRoom *pRoom = NULL;
	RoomIndex nRoomIndex = enmInvalidRoomIndex;
	ret = g_RoomMgt.GetRoom(pMsgHead->nRoomID, pRoom, nRoomIndex);
	if(ret < 0 || pRoom == NULL)
	{
		WRITE_ERROR_LOG("get room error!{ret=0x%08x}\n",ret);
		return ret;
	}
	//判断玩家是否在房间roomID中
	if(!(pRoom->IsPlayerInRoom(nPlayerIndex)))
	{
		WRITE_ERROR_LOG("player does no in room{nSrcRoleID=%d, nRoomID=%d}",pMsgHead->nRoleID,pMsgHead->nRoomID);
		return E_RS_PLAYRENOTINROOM;
	}

	//判断被封玩家情况
	CPlayer *pDestPlayer = NULL;
	PlayerIndex nDestPlayerIndex = enmInvalidPlayerIndex;
	ret = g_PlayerMgt.GetPlayer(pLockIpReq->nDestRoleID, pDestPlayer, nDestPlayerIndex);
	//没有此玩家
	if(ret < 0 || pDestPlayer == NULL)
	{
		WRITE_ERROR_LOG("add black player does no exist{nDestRoleID=%d}",pLockIpReq->nDestRoleID);
		return ret;
	}
	//判断玩家是否在房间roomID中
	if(!(pRoom->IsPlayerInRoom(nDestPlayerIndex)) && !(pRoom->IsRebotPlayerInRoom(pLockIpReq->nDestRoleID)))
	{
		WRITE_ERROR_LOG("player does no in room{nDestRoleID=%d, nRoomID=%d}",pLockIpReq->nDestRoleID,pMsgHead->nRoomID);
		return E_RS_PLAYRENOTINROOM;
	}
	RoleRank nSrcRoleRank = pRoom->GetRoleRank(pMsgHead->nRoleID);
	//室主及以下没有封IP的权限(超管才有)
	if(nSrcRoleRank <= enmRoleRank_Host)
	{
		// todo 发送权限不够回应
		SendResponseToUser(pMsgHead,enmLockIpResult_NO_Permission,nOptionLen,pOptionData);
		return E_RS_NOPERMISSIONS;
	}

	uint32_t nEndLockTime = (uint32_t)CTimeValue::CurrentTime().Seconds()+pLockIpReq->nTime;
	LockIpResult nLockIpResult = enmLockIpResult_Umknown;
	ret = LockPlayerIP(pRoom,nEndLockTime,nSrcRoleRank,pLockIpReq->nDestRoleID,nLockIpResult);
	//发送通知和回应
	SendResponseToUser(pMsgHead,nLockIpResult,nOptionLen,pOptionData);
	if(ret < 0)
	{
		WRITE_ERROR_LOG("lock player ip error{nDestRoleID=%d, ret=0x%08x}",pLockIpReq->nDestRoleID,ret);
		return ret;
	}
	SendNotifyToUser(pMsgHead->nRoomID,pMsgHead->nRoleID,pLockIpReq->nDestRoleID,pLockIpReq->strReason,pLockIpReq->nTime,nOptionLen,pOptionData);
	//退出房间
	ret = ExitRoom(pDestPlayer,nDestPlayerIndex,pRoom,pMsgHead->nMessageID);
	if(ret<0)
	{
		WRITE_ERROR_LOG("add player to lockIP because exit room filed{nDestRoleID=%d, ret=0x%08x}",pLockIpReq->nDestRoleID,ret);
		return ret;
	}
	WRITE_NOTICE_LOG("player lock other ip {nSrcRoleID=%d, nRoomID=%d, nDestRoleID=%d, nTime=%d}\n",pMsgHead->nRoleID,pMsgHead->nRoomID,pLockIpReq->nDestRoleID,pLockIpReq->nTime);
	return ret;
}
int32_t CLockRoomMessageEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	int32_t ret = S_OK;
	if(pMsgBody == NULL || pMsgHead == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}

	CLockRoomNoitfy *pLockRoomNoitfy = dynamic_cast<CLockRoomNoitfy *>(pMsgBody);
	if(NULL == pLockRoomNoitfy)
	{
		WRITE_ERROR_LOG("null pointer:{pLockRoomNoitfy=0x%08x}\n",pLockRoomNoitfy);
		return E_NULLPOINTER;
	}
	WRITE_NOTICE_LOG("recv room is locked by web{nRoomID=%d}",pLockRoomNoitfy->nRoomID);

	//获取房间
	CRoom *pRoom = NULL;
	RoomIndex nRoomIndex = enmInvalidRoomIndex;
	ret = g_RoomMgt.GetRoom(pLockRoomNoitfy->nRoomID, pRoom, nRoomIndex);
	if(ret < 0 || pRoom == NULL)
	{
		WRITE_NOTICE_LOG("room is not exit!{nRoomID=%d}",pLockRoomNoitfy->nRoomID);
		return E_NULLPOINTER;
	}
	//todo 通知房间里的人房间被封了
	CLockRoomNotifyToClient stLockRoomNotifyToClient;
	stLockRoomNotifyToClient.strReason = pLockRoomNoitfy->strLockRoomReason.GetString();
	stLockRoomNotifyToClient.nEndTime = pLockRoomNoitfy->nTimeUnlock;
	stLockRoomNotifyToClient.nLockDays = (pLockRoomNoitfy->nTimeUnlock-pLockRoomNoitfy->nTimeLock)/SECOND_PER_DAY;
	SendMessageNotifyToClient(MSGID_RSCL_SRV_ROOM_LOCKED_NOTI, &stLockRoomNotifyToClient, pLockRoomNoitfy->nRoomID, enmBroadcastType_All,
			enmInvalidRoleID,0,NULL, "send lock room notify");

	//踢出房间里的所有人
	PlayerIndex arrPlayerIndex[MaxUserCountPerRoom] = {enmInvalidPlayerIndex};
	int32_t nPlayerCount = 0;
	pRoom->GetAllPlayers(arrPlayerIndex, MaxUserCountPerRoom, nPlayerCount);
	for(int32_t i = 0; i < nPlayerCount; ++i)
	{
		CPlayer *pPlayer = NULL;
		g_PlayerMgt.GetPlayerByIndex(arrPlayerIndex[i], pPlayer);
		if(pPlayer == NULL)
		{
			WRITE_ERROR_LOG("player is not in this roomserver{nRoleID=%d}",pPlayer->GetRoleID());
			continue;
		}
		//玩家退房的相关操作
		//退房
		ret = ExitRoom(pPlayer,arrPlayerIndex[i],pRoom,pMsgHead->nMessageID);
		if(ret < 0)
		{
			WRITE_ERROR_LOG("kick player filed because exit room filed{nRoleID=%d, nRoomID=%d}",pPlayer->GetRoleID(),pLockRoomNoitfy->nRoomID);
			continue;
		}
	}
	//为了容错再次删除房间(exitroom 中有删除房间的操作)
	g_RoomMgt.RealDestroyRoom(pLockRoomNoitfy->nRoomID);
	WRITE_NOTICE_LOG("lock room ok !{nRoomID=%d}",pLockRoomNoitfy->nRoomID);

	CDestoryRoomNotice stDestoryRoomNotice;
	stDestoryRoomNotice.nRoomID = pLockRoomNoitfy->nRoomID;
	stDestoryRoomNotice.nServerID = g_FrameConfigMgt.GetFrameBaseConfig().GetServerID();
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_Item);
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_Hall);
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_Media);
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_Tunnel);
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_RoomDispatcher);
	SendMessageNotifyToServer(MSGID_RSMS_DESTORY_ROOM_NOTICE, &stDestoryRoomNotice, pLockRoomNoitfy->nRoomID, enmTransType_Broadcast, enmInvalidRoleID, enmEntityType_HallDataCenter);

	return S_OK;
}
int32_t CBuildPlayerDataNoticeMessageEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgBody=0x%08x, pMsgHead=0x%08x}\n",pMsgBody,pMsgHead);
		return E_NULLPOINTER;
	}

	CBuildPlayerDataNoti *pBuildPlayerDataNotice = dynamic_cast<CBuildPlayerDataNoti *>(pMsgBody);
	if(NULL == pBuildPlayerDataNotice)
	{
		WRITE_ERROR_LOG("pMsgBody transform to class child failed{ret=0x%08x}\n",E_NULLPOINTER);
		return E_NULLPOINTER;
	}

	WRITE_DEBUG_LOG("recv BuildPlayerDataNotice{nPlayerCount=%d}\n",pBuildPlayerDataNotice->nPlayerCount);

	for(int32_t i = 0; i < pBuildPlayerDataNotice->nPlayerCount; ++i)
	{
		CPlayer *pLocalPlayer = NULL;
		PlayerIndex nLocalPlayerIndex = enmInvalidPlayerIndex;
		int32_t ret = g_PlayerMgt.GetPlayer(pBuildPlayerDataNotice->arrRoleID[i], pLocalPlayer, nLocalPlayerIndex);
		//本地roomserver上没有这个玩家
		if(ret < 0 || pLocalPlayer == NULL)
		{
			ret = g_PlayerMgt.CreatePlayer(pBuildPlayerDataNotice->arrRoleID[i], pLocalPlayer, nLocalPlayerIndex);
			if(ret < 0 || pLocalPlayer == NULL)
			{
				WRITE_ERROR_LOG("null pointer:{pLocalPlayer=0x%08x, pMsgHead=0x%08x}\n",pLocalPlayer);
				continue;
			}

			uint32_t nStartPos = pLocalPlayer->GetStartPos();
			uint32_t nEndPos = pLocalPlayer->GetEndPos();

			uint32_t nPlayerDataSize = nEndPos - nStartPos;
			if(nPlayerDataSize >= pBuildPlayerDataNotice->arrPlayerDataSize[i])
			{
				memcpy(((uint8_t *)pLocalPlayer) + nStartPos, pBuildPlayerDataNotice->arrPlayerData[i], pBuildPlayerDataNotice->arrPlayerDataSize[i]);
			}

			RoomID arrRoomID[MaxEnterRoomCount];
			int32_t nEnterRoomCount = 0;
			pLocalPlayer->GetAllEnterRoom(arrRoomID, MaxEnterRoomCount, nEnterRoomCount);
			WRITE_DEBUG_LOG("building player data:{nEnterCount=%d}\n",nEnterRoomCount);
			for(int32_t j = 0; j < nEnterRoomCount; ++j)
			{
				CRoom *pRoom = NULL;
				RoomIndex nRoomIndex = enmInvalidRoomIndex;
				ret = g_RoomMgt.GetRoom(arrRoomID[j], pRoom, nRoomIndex);
				if(ret < 0 || nRoomIndex == enmInvalidRoomIndex)
				{
					WRITE_WARNING_LOG("building player data:but it's not found room object,or room is not rebulid!{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i],arrRoomID[j]);
					continue;
				}

				if(pRoom->IsPlayerInRoom(nLocalPlayerIndex)||pRoom->IsRebotPlayerInRoom(pBuildPlayerDataNotice->arrRoleID[i]))
				{
					WRITE_NOTICE_LOG("building player data:player in this room{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i], arrRoomID[j]);
					continue;
				}

				//将玩家添加到房间对象中去
				if(pLocalPlayer->IsReboot())
				{
					pRoom->AddRebotPlayer(pBuildPlayerDataNotice->arrRoleID[i]);
				}
				else
				{
					pRoom->AddPlayer(nLocalPlayerIndex, pLocalPlayer->GetVipLevel(), pLocalPlayer->IsHideEnter());
				}
				WRITE_NOTICE_LOG("building player data:player rebulid in room{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i],arrRoomID[j]);
			}
		}
		else
		{
			CPlayer stPlayer;
			CPlayer *pRemotePlayer = &stPlayer;

			uint32_t nStartPos = pRemotePlayer->GetStartPos();
			uint32_t nEndPos = pRemotePlayer->GetEndPos();

			uint32_t nPlayerDataSize = nEndPos - nStartPos;
			if(nPlayerDataSize >= pBuildPlayerDataNotice->arrPlayerDataSize[i])
			{
				memcpy(((uint8_t *)pRemotePlayer) + nStartPos, pBuildPlayerDataNotice->arrPlayerData[i], pBuildPlayerDataNotice->arrPlayerDataSize[i]);
			}

			PlayerRoomInfo arrPlayerRoomInfo[MaxEnterRoomCount];
			int32_t nRoomInfoCount = 0;
			pRemotePlayer->GetPlayerRoomInfo(arrPlayerRoomInfo, MaxEnterRoomCount, nRoomInfoCount);

			//只合并目前本地服务器上已有的房间数据
			int32_t nEnterRoomCount = nRoomInfoCount;
			nRoomInfoCount = 0;
			for(int32_t j = 0; j < nEnterRoomCount; ++j)
			{
				CRoom *pRoom = NULL;
				RoomIndex nRoomIndex = enmInvalidRoomIndex;
				ret = g_RoomMgt.GetRoom(arrPlayerRoomInfo[j].nRoomID, pRoom, nRoomIndex);
				if(ret < 0 || pRoom == NULL)
				{
					WRITE_WARNING_LOG("building player data:but it's not found room object,or room is not rebulid!{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i],arrPlayerRoomInfo[j].nRoomID);
					continue;
				}
				//将玩家添加到房间对象中去(修改于2012.6.5)
				if(pRoom->IsPlayerInRoom(nLocalPlayerIndex)||pRoom->IsRebotPlayerInRoom(pBuildPlayerDataNotice->arrRoleID[i]))
				{
					WRITE_NOTICE_LOG("building player data:player in this room{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i], arrPlayerRoomInfo[j].nRoomID);
					continue;
				}
				if(pRemotePlayer->IsReboot())
				{
					pRoom->AddRebotPlayer(pBuildPlayerDataNotice->arrRoleID[i]);
				}
				else
				{
					pRoom->AddPlayer(nLocalPlayerIndex, pRemotePlayer->GetVipLevel(), pRemotePlayer->IsHideEnter());
				}

				arrPlayerRoomInfo[nRoomInfoCount] = arrPlayerRoomInfo[j];
				++nRoomInfoCount;
				WRITE_NOTICE_LOG("building player data:player rebulid in room{nRoleID=%d, nRoomID=%d}\n", pBuildPlayerDataNotice->arrRoleID[i],arrPlayerRoomInfo[j].nRoomID);
			}
			//合并player
			pLocalPlayer->MergePlayerRoomInfo(arrPlayerRoomInfo, nRoomInfoCount);
		}
	}

	return S_OK;
}