FRAME_HALLSERVER_NAMESPACE_BEGIN

int32_t CFetchRoleOnlineStatusEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody == NULL || pMsgHead == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgHead=0x%08x, pMsgBody=0x%08x}\n", pMsgHead, pMsgBody);
		return E_NULLPOINTER;
	}
	CGetOnlineStatusResp stResp;
	if(g_ServerStatus != enmServerStatus_Running)
	{
		WRITE_ERROR_LOG("server is not ready!\n");
		stResp.nResult = enmFetchRoleOnlineStatusResult_Unknown;
		SendMessageResponse(MSGID_GET_ONLINE_STATUS_RESP, pMsgHead, &stResp, enmTransType_P2P);
		return E_NULLPOINTER;
	}
	CGetOnlineStatusReq* pGetOnlineStatusReq = dynamic_cast<CGetOnlineStatusReq*>(pMsgBody);
	if(pGetOnlineStatusReq == NULL)
	{
		WRITE_ERROR_LOG("null pointer:pMsgBody transform to CGetOnlineStatusReq class failed![nMessageID=0x%08x, nSourceType=%d, nSourceID=%d]\n",
				pMsgHead->nMessageID, pMsgHead->nSourceType, pMsgHead->nSourceID);

		stResp.nResult = E_NULLPOINTER;
		SendMessageResponse(MSGID_GET_ONLINE_STATUS_RESP, pMsgHead, &stResp, enmTransType_P2P);

		return E_NULLPOINTER;
	}

	int32_t nFetchCount = pGetOnlineStatusReq->nPlayerCount;
	stResp.nResult = S_OK;

	WRITE_DEBUG_LOG("fetch online status:web get role online status!{nPlayerCount=%d}",nFetchCount);

	for(int i = 0; i < nFetchCount; i++)
	{
		RoleID nRoleID = enmInvalidRoleID;
		CPlayer* pPlayer = NULL;
		nRoleID = pGetOnlineStatusReq->arrRoleID[i];
		stResp.arrRoleID[i] = nRoleID;
		stResp.nPlayerCount++;
		int ret = g_PlayerMgt.GetPlayer(nRoleID, pPlayer);
		if(ret < 0 || pPlayer == NULL)
		{
			stResp.arrStatus[i] = 0;
		}
		else
		{
			stResp.arrStatus[i] = 1;
		}
		if(i >= MaxGetPlayerOnlineStatusNum - 1)
		{
			break;
		}
	}

	SendMessageResponse(MSGID_GET_ONLINE_STATUS_RESP, pMsgHead, &stResp, enmTransType_P2P);
	return S_OK;
}
Пример #2
0
/*
 *  封玩家IP
 */
int32_t CLockIPEvent::LockPlayerIP(CRoom *pRoom,const uint32_t nEndLockTime,RoleRank nSrcRoleRank,RoleID nLockIPRoleID,LockIpResult &nLockIpResult)
{
	int32_t ret = S_OK;
	if(NULL == pRoom)
	{
		WRITE_ERROR_LOG("pRoom null ret=0x%08x \n",E_NULLPOINTER);
		return E_NULLPOINTER;
	}
	CPlayer *pPlayer = NULL;
	PlayerIndex nPlayerIndex = enmInvalidPlayerIndex;
	ret = g_PlayerMgt.GetPlayer(nLockIPRoleID, pPlayer, nPlayerIndex);
	//没有被 封玩家
	if(ret < 0 || pPlayer == NULL)
	{
		WRITE_ERROR_LOG("player does no exist{nLockIPRoleID=%d}",nLockIPRoleID);
		return ret;
	}
	if(!(pPlayer->IsReboot()))
	{
		ret = pRoom->AddLockIPList(pPlayer->GetConnInfo().nAddress,nEndLockTime);
		if(ret<0)
		{
			WRITE_ERROR_LOG("add player to lockIP filed because  add to lockIpList error{nLockIPRoleID=%d}",nLockIPRoleID);
			return ret;
		}
	}
	nLockIpResult = enmLockIpResult_OK;
	return ret;
}
Пример #3
0
FRAME_GATESERVER_NAMESPACE_BEGIN

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

	CHallServerIsRuningNoti *pHallServerIsRuningNoti = dynamic_cast<CHallServerIsRuningNoti *>(pMsgBody);
	if(NULL == pHallServerIsRuningNoti)
	{
		WRITE_ERROR_LOG("null pointer:{pHallServerIsRuningNoti=0x%08x}\n",pHallServerIsRuningNoti);
		return E_NULLPOINTER;
	}

	//发送登出通知到hallserver
	for(uint32_t i = 0;i<g_PlayerMgt.m_arrNeedLogout.size();i++)
	{
		SendLogoutMessage(g_PlayerMgt.m_arrNeedLogout.at(i));
	}

	g_bHallServerIsRuning = true;
	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 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;
}
Пример #6
0
void DumpMemWithByte(char* szBinaryBuf, int32_t& binaryBufLen, const char* szTmpBuf, const int32_t nBufLen, const char* szContent)
{
	if(NULL == szTmpBuf)
	{
		WRITE_ERROR_LOG("Error: the tmpbuf is null!\n");
		return;
	}

	if(nBufLen >= enmMaxMemcacheValueLen)
	{
		WRITE_ERROR_LOG("Error: the tmebuf size is too large! more than max memcache value length! max memcache value length is %d, but the tmpbuf size is: %d\n", enmMaxMemcacheValueLen, nBufLen);
		return;
	}
	
	binaryBufLen = 0;
	sprintf(szBinaryBuf + binaryBufLen, "%s", szContent);
	binaryBufLen = (int32_t)strlen(szBinaryBuf);

	for(int32_t i=0; i<nBufLen; ++i)
	{
		if(i % 8 == 0)
		{
			sprintf(szBinaryBuf + binaryBufLen, "\n");
			binaryBufLen = (int32_t)strlen(szBinaryBuf);
		}
		sprintf(szBinaryBuf + strlen(szBinaryBuf), "%02X", szTmpBuf[i]);
	}
}
Пример #7
0
int32_t CHallRunMessageEvent::SendLogoutMessage(RoleID nRoleID)
{
	int32_t nRet = S_OK;
	CPlayer *pPlayer = NULL;
	nRet = g_PlayerMgt.GetPlayer(nRoleID,pPlayer);
	if(nRet < 0)
	{
		WRITE_ERROR_LOG("creat player object error!{nRoleID=%d, nRet=0x%08x}",nRoleID,nRet);
		return nRet;
	}
	ConnInfo *pConnInfo = pPlayer->GetConnInfo();
	if(pConnInfo == NULL)
	{
		WRITE_ERROR_LOG("null pointer:{stConnInfo=0x%08x}\n",pConnInfo);
		return E_NULLPOINTER;
	}

	uint32_t nOffset = 0;
	uint8_t arrOptionData[MaxOptionDataSize];
	nRet = pConnInfo->MessageEncode(arrOptionData, MaxOptionDataSize, nOffset);
	if(nRet < 0)
	{
		WRITE_ERROR_LOG("encode connuin failed!{nRet=0x%08x}\n", nRet);
		return nRet;
	}

	PlayerLogout(nRoleID,pPlayer->GetLogoutReason(),nOffset,arrOptionData);
	return nRet;
}
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;
}
Пример #9
0
int32_t CFromRoomAddEvent::OnMessage_AddInRoomTime(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody, const uint16_t nOptionLen , const void *pOptionData)
{
	if(pMsgHead == NULL || pMsgBody == NULL)
	{
		WRITE_ERROR_LOG("null pointer: roomserver add in roomtime!{pMsgHead=0x%08X, pMsgBody=0x%08X}\n",
				pMsgHead, pMsgBody);
		return E_NULLPOINTER;
	}
	int32_t ret = S_OK;

	//	int32_t threadindex =         需要获取线程ID
	CAddAdmInRoomOnLineTimeNotice* pTmpBody = dynamic_cast<CAddAdmInRoomOnLineTimeNotice*>(pMsgBody);
	if(pTmpBody == NULL)
	{
		WRITE_ERROR_LOG("get msg body failed!");
		return E_NULLPOINTER;
	}
	RoleRank rolerank = pTmpBody->nRoleRank;
	//时间类
	CDateTime dt = CDateTime::CurrentDateTime();
	char szDateTime[enmMaxTimeStringLength] = {0};
	dt.ToDateTimeString(szDateTime);

	//更新管理员在房间时长日表
	ret = UpdateAdminInRoomOnlineTimeDay(*pTmpBody, rolerank);
	if(0 > ret)
	{
		WRITE_ERROR_LOG( "update admin in room online time failed, operation time: %s, roleid=%d, roomid=%d, addtime=%d,  msgid=0x%08X\n",
				szDateTime,
				pTmpBody->nRoleID,
				pTmpBody->nRoomID,
				pTmpBody->nAddTime,

				pMsgHead->nMessageID);
		return ret;
	}
//	WRITE_DEBUG_LOG( "update admin in room online time success! operation time: %s, roleid=%d, roomid=%d, addtime=%d, msgid=0x%08X\n",
//			szDateTime,
//			pTmpBody->nRoleID,
//			pTmpBody->nRoomID,
//			pTmpBody->nAddTime,
//			pMsgHead->nMessageID);

	//更新管理员在房间时长总表(更新两张表, 一张跟房间号相关, 一张无关)
	ret = UpdateAdminInRoomOnlineTimeTotal(pTmpBody->nRoleID, pTmpBody->nRoomID, pTmpBody->nAddTime, rolerank);
	if(0 > ret)
	{
		WRITE_ERROR_LOG( "add admin inroom online total time failed! errorcode=0x%08X\n", ret);
		return ret;
	}
	//WRITE_DEBUG_LOG( "add admin inroom online total time success!\n");

	return S_OK;
}
int32_t CCreateRoomNoticeMessageEvent::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;
	}

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

	WRITE_DEBUG_LOG("recv CreateRoomNotice{RoomID=%d,ServerID=%d}\n", pCreateRoomNotice->nRoomID, pCreateRoomNotice->nServerID);

	CRoom *pRoom = NULL;
	int32_t ret = g_RoomMgt.GetRoom(pCreateRoomNotice->nRoomID, pRoom);
	if(ret < 0 || pRoom == NULL)
	{
		WRITE_DEBUG_LOG("It's not found room object by roomid, so we'll create it{nRoomID=%d, nServerID=%d}\n", pCreateRoomNotice->nRoomID, pCreateRoomNotice->nServerID);
		ret = g_RoomMgt.CreateRoom(pCreateRoomNotice->nRoomID, pRoom);
		if(ret < 0 || pRoom == NULL)
		{
			WRITE_ERROR_LOG("create room object failed by roomid!{nRoomID=%d, nServerID=%d, ret=0x%08x}\n", pCreateRoomNotice->nRoomID, pCreateRoomNotice->nServerID, ret);
			return E_NULLPOINTER;
		}
	}
	pRoom->SetRegionID(pCreateRoomNotice->nRegionID);
	pRoom->SetChannelID(pCreateRoomNotice->nChannelID);
	pRoom->SetRoomID(pCreateRoomNotice->nRoomID);
	pRoom->SetRoomName(pCreateRoomNotice->strRoomName.GetString());
	pRoom->SetRoomServerID(pCreateRoomNotice->nServerID);
	pRoom->SetHostID(pCreateRoomNotice->nHostID);

	CRoomCache *pRoomCache = NULL;
	ret = g_RoomCacheMgt.GetRoomCache(pCreateRoomNotice->nRoomID, pRoomCache);
	if(ret < 0 || pRoomCache == NULL) //表示没有创建房间
	{
		ret = g_RoomCacheMgt.CreateRoomCache(pCreateRoomNotice->nRoomID, pRoomCache);
		if(ret < 0 || pRoomCache == NULL)
		{
			WRITE_ERROR_LOG("create roomCache filed{nRoomID=%d, ret=0x%08x}",pMsgHead->nRoomID,pCreateRoomNotice->nRoomID);
			return E_NULLPOINTER;
		}
	}
	pRoomCache->SetRoomID(pMsgHead->nRoomID);
	pRoomCache->SetServerID(pMsgHead->nSourceID);

	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;
}
FRAME_HALLSERVER_NAMESPACE_BEGIN
int32_t CUpdateVipNotiEvent::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	// check the server status
	if(g_ServerStatus != enmServerStatus_Running)
	{
		WRITE_ERROR_LOG("server is not ready!\n");
		return E_NULLPOINTER;
	}

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

	CUpdateMemVipLevelNotify* pUpdateVipLevelNoti = dynamic_cast<CUpdateMemVipLevelNotify*>(pMsgBody);
	if(pUpdateVipLevelNoti == NULL)
	{
		WRITE_ERROR_LOG("null pointer: pMsgBody transform to CUpdateMemVipLevelNotify class failed!"
				"{nMessageID=0x%08x, nRoleID=%d}\n",
				pMsgHead->nMessageID, pMsgHead->nRoleID);
		return E_NULLPOINTER;
	}

	switch(pMsgHead->nMessageID)
	{
		case MSGID_SSRS_UPDATELEVEL_NOTI:
		{
			WRITE_INFO_LOG("receive update vip notify!{nRoleID=%d, nVipLevel=%d}\n",
					pUpdateVipLevelNoti->nRoleID, pUpdateVipLevelNoti->nVipLevel);

			nRet = UpdateMemVipLevel(pUpdateVipLevelNoti->nRoleID, pUpdateVipLevelNoti->nVipLevel);
			if(0 > nRet)
			{
				WRITE_ERROR_LOG("update vip notify, update vip error!{nRoleID=%d, nVipLevel=%d, nRet=0x%08x}\n",
						pUpdateVipLevelNoti->nRoleID, pUpdateVipLevelNoti->nVipLevel, nRet);
				return E_UNKNOWN;
			}
		}
		break;
		default:
		WRITE_ERROR_LOG("update vip notify, get wrong message!{nMessageID=0x%08x}\n", pMsgHead->nMessageID);
		break;
	}
	return S_OK;
}
Пример #14
0
int32_t CDefaultMessageHandler::OnMessageEvent(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody,
		const uint16_t nOptionLen, const void *pOptionData)
{
	if(pMsgBody==NULL || pMsgHead==NULL)
	{
		WRITE_ERROR_LOG("null pointer:{pMsgHead=0x%08x, pMsgBody=0x%08x}\n", pMsgHead, pMsgBody);
		return E_NULLPOINTER;
	}

	WRITE_DEBUG_LOG("default message handler!\n");

//	CCreateRoomNotice *pCreateRoomNotice = dynamic_cast<CCreateRoomNotice *>(pMsgBody);
//	if(NULL == pCreateRoomNotice)
//	{
//		WRITE_ERROR_LOG("null pointer:pMsgBody transform child failed!\n");
//		return E_NULLPOINTER;
//	}

	CTestSession stSession;

	stSession.SetSessionData(111, 123, 0, this);

	g_Frame.SendMessageRequest(0x110401, pMsgBody, &stSession);

	return S_OK;
}
Пример #15
0
int32_t CFromRoomAddEvent::InsertPlayerIntoRoomBlackList(const RoleID roleid, const RoomID roomid, const char* szDateTime, const RoleID operatorID)
{
	//生成SQL语句
	char szSql[enmMaxSqlStringLength] = {0};

	//sprintf(szSql, "insert into player_historyonlinetimebystage (`RoleID`,`StartTime`,`EndTime`,`TotalTime`) values (%d,%d,%d,%d) on duplicate key update `TotalTime` = %d", roleID, starttime,endtime, nowtotaltime,nowtotaltime);

	sprintf(szSql, "insert into vdc_room.room_black_list(`RoomID`, `RoleID`,`AdderID`, `JoinTime`) values (%d, %d, %d, '%s') on duplicate key update `AdderID`=%d, `JoinTime` = '%s'" ,
			roomid, roleid, operatorID, szDateTime, operatorID, szDateTime);

	uint64_t nAffectedRows = 0;
	int32_t nRet = MYSQLREADENGINE.ExecuteUpdate(szSql, nAffectedRows);
	if (0 > nRet)
	{
		WRITE_ERROR_LOG( "execute update room black list failed! roomid=%d, roleid=%d, errorcode=0x%08X,  sql=%s\n",
				roomid, roleid, nRet,  szSql);
		return nRet;
	}
	//WRITE_DEBUG_LOG( "execute update room black list success!  roomid=%d, roleid=%d, sql=%s\n",roomid, roleid, szSql);

	if ( (1 != nAffectedRows) && (2!= nAffectedRows) )
	{
		nRet = E_UNKNOWN;
	}

	return S_OK;
}
Пример #16
0
//原型:memcached_return memcached_set(memcached_st* ptr, const char* ptr, size_t key_length, const char* value, size_t value_length, time_t expiration, uint32_t flags);
int32_t CVDCMemcache::MemcacheSet(memcached_st* memc, const char* szKey, const size_t keyLen, const char* szValue, const size_t valueLen, const time_t expiration)
{
	DB_MUTEX_GUARD(cf_mutex, m_dbcrit);
	memcached_return rc;
	rc = memcached_set(memc, szKey, keyLen, szValue, valueLen, expiration, (uint32_t)0);
	if(rc != MEMCACHED_SUCCESS)
	{
		//16号错误码:NOT FOUND   46号错误码:operation in process
		if(16 == rc || 46==rc)
		{
			WRITE_WARNING_LOG( "warning: operation is in process! szKey=%s, keylen=%d, expiration=%d, errorcode=%d, errordesc=%s\n",
				szKey,
				(int32_t)keyLen,
				(int32_t)expiration,
				rc,
				memcached_strerror(m_memc,rc));
			return S_OK;
		}
		WRITE_ERROR_LOG( "Error: set memcache failed! szKey=%s, keyLen=%d, szValue=%s, valuelen=%d, expirtation=%d, errorcode=%d, errordesc=%s\n",
			szKey,
			(int32_t)keyLen,
			szValue,
			(int32_t)valueLen,
			(int32_t)expiration,
			rc,
			memcached_strerror(memc, rc));

		return E_MEMCACHED_SET;
	}

	//WRITE_DEBUG_LOG( "set memcached success! szKey=%s, keylen=%d\n", szKey, (int32_t)keyLen);

	return S_OK;
}
Пример #17
0
FRAME_DBPROXY_NAMESPACE_BEGIN

int32_t CFromRoomAddEvent:: OnMessage_AddBlacklist(MessageHeadSS * pMsgHead, IMsgBody* pMsgBody, const uint16_t nOptionLen, const void *pOptionData )
{
	if(pMsgHead == NULL || pMsgBody == NULL)
	{
		WRITE_ERROR_LOG("null pointer: roomserver add black list!{pMsgHead=0x%08X, pMsgBody=0x%08X}\n",
				pMsgHead, pMsgBody);
		return E_NULLPOINTER;
	}
	int32_t ret = S_OK;

	//	int32_t threadindex =         需要获取线程ID
	CAddPlayerToBlackReq* pTmpBody = dynamic_cast<CAddPlayerToBlackReq*>(pMsgBody);
	if(pTmpBody == NULL)
	{
		WRITE_ERROR_LOG("get msg body failed!");
		return E_NULLPOINTER;
	}
	CAddPlayerToBlackResp set_rolerank;

	MessageHeadSS resphead;
	ObtainRespHead(pMsgHead, resphead,MSGID_DBRS_ADD_BLACK_RESP);

	set_rolerank.nResult = S_OK;
	g_Frame.PostMessage(&resphead, &set_rolerank, nOptionLen, (const char*)pOptionData);
	DumpMessage("", &resphead, &set_rolerank, nOptionLen, (const char*)pOptionData);

	//时间类
	CDateTime dt = CDateTime::CurrentDateTime();
	char szDateTime[enmMaxTimeStringLength] = {0};
	dt.ToDateTimeString(szDateTime);


	ret = InsertPlayerIntoRoomBlackList(pTmpBody->nRoleID, pTmpBody->nRoomID, szDateTime, pMsgHead->nRoleID);
	if(0 > ret)
	{
		WRITE_ERROR_LOG("Error: process roomserver add black list request failed! errorcode=0x%08X\n",
				ret);

		return ret;
	}
	WRITE_DEBUG_LOG( "process roomserver add black success! \n");


	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;
}
Пример #19
0
int32_t GetMsgHeadIdxFromRecvBuf(const uint8_t* pBuffer, const int32_t nLength, int32_t& msgHeadIdx)
{
	if(pBuffer == NULL || nLength <= 0)
	{
		WRITE_ERROR_LOG("Error: get msghead index from recv buffer failed!\n");
		return E_INVALID_ARG_IN_GET_MSGHEAD_IDX;
	}

	//TODO: 从流格式的数据中得到消息头的索引,并赋值给msgHeadIdx

	return  S_OK;
}
Пример #20
0
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::StartTimer(EntityType nEntityType)
{
	CFrameSession *pSession = NULL;
	int32_t ret = g_Frame.CreateSession(0, enmSessionType_RebulidItemDaly, this, enmRebulidItemDelayPeriod, pSession);
	if(ret < 0 || pSession == NULL)
	{
		WRITE_ERROR_LOG("rebulid :start timer failed serverType = %d!",nEntityType);
		return ret;
	}
	CServerNeedRebulidSessionData *pData = new(pSession->GetSessionData())CServerNeedRebulidSessionData();
	pData->nEntityType = nEntityType;

	return S_OK;
}
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;
}
Пример #23
0
//原型: char* memcached_get(memcached_st* ptr, const char* key, size_t keylen, size_t* valuelen, uint32_t* flags, memcached_return* error);
int32_t CVDCMemcache::MemcacheGet(memcached_st* memc, const char* szKey, const size_t keyLen, char*& szValue, size_t& valueLen)
{
	DB_MUTEX_GUARD(cf_mutex, m_dbcrit);
	memcached_return rc;
	szValue = memcached_get(memc, szKey, keyLen, &valueLen, 0, &rc);
	if(rc != MEMCACHED_SUCCESS)
	{
		WRITE_ERROR_LOG( "Error: get memcache object failed! szKey=%s, keylen=%d, szValue=%s, valuelen=%d, errorcode=%d, errordesc=%s\n", szKey, (int32_t)keyLen, szValue, (int32_t)valueLen, rc, memcached_strerror(memc, rc));
		return E_MEMCACHED_GET;
	}

	//WRITE_DEBUG_LOG( "get memcache object success! szKey=%s, keylen=%d\n", szKey, (int32_t)keyLen);

	return S_OK;
}
Пример #24
0
FRAME_GATESERVER_NAMESPACE_BEGIN

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

	CExitRoomNotice_Public *pExitRoomNotice = dynamic_cast<CExitRoomNotice_Public *>(pMsgBody);
	if(NULL == pExitRoomNotice)
	{
		WRITE_ERROR_LOG("null pointer:pMsgBody transform to CExitRoomNotice class failed![nMessageID=0x%08x, nRoleID=%d]\n",
				pMsgHead->nMessageID, pMsgHead->nRoleID);
		return E_NULLPOINTER;
	}

	CRoom *pRoom = NULL;
	nRet = g_RoomMgt.GetRoom(pExitRoomNotice->nRoomID,pRoom);
	if(pRoom == NULL || nRet < 0)
	{
		WRITE_ERROR_LOG("get pRoom error {nRoomID=%d, nRet=0x%08x}\n",pExitRoomNotice->nRoomID,nRet);
		return nRet;
	}

	pRoom->DeletePlayer(pExitRoomNotice->nRoleID);

	if(pRoom->GetUserCount() == 0)
	{
		g_RoomMgt.DestroyRoom(pExitRoomNotice->nRoomID);
	}
	return S_OK;
}
Пример #25
0
int32_t CDefaultMessageHandler::OnSessionTimeOut(CFrameSession *pSession)
{
	if(pSession == NULL)
	{
		WRITE_ERROR_LOG("null pointer:pSession!\n");
		return E_NULLPOINTER;
	}

	switch(pSession->GetSessionType())
	{
	default:
		break;
	}

	return S_OK;
}
Пример #26
0
int32_t CLockIPEvent::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;
	}
	switch(pMsgHead->nMessageID)
	{
		case MSGID_CLRS_LOCK_IP_REQ:
		OnEventLockIP(pMsgHead,pMsgBody,nOptionLen,pOptionData);
		break;
		default:
		break;
	}
	return S_OK;
}
Пример #27
0
FRAME_HALLSERVER_NAMESPACE_BEGIN

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

	switch(pSession->GetSessionType())
	{
	default:
		break;
	}

	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;
}
Пример #29
0
//原型:memcached_return memcached_delete(memcached_st* ptr, const char* key, size_t keylen, time_t expiration);
int32_t CVDCMemcache::MemcacheDel(memcached_st* memc, const char* szKey, const size_t keyLen, time_t expiration)
{
	DB_MUTEX_GUARD(cf_mutex, m_dbcrit);
	int32_t ret = S_OK;
	memcached_return rc;
	ret = MemcacheIfKeyExist(memc, szKey, keyLen);
	if(0 > ret)
	{
		WRITE_WARNING_LOG( "key not exist in memcache! so cannot delete it! just ignore! key=%s, keylen=%d\n",
			szKey,
			keyLen);
		return S_OK;
	}
	//WRITE_DEBUG_LOG( "key exist in cache! need to delete! key=%s, keylen=%d\n",szKey,keyLen);

	rc = memcached_delete(memc, szKey, keyLen, expiration);
	if(rc != MEMCACHED_SUCCESS)
	{
		//errno 15: STORED
		if(15 == rc)
		{
			WRITE_WARNING_LOG( "warning: object stored! szKey=%s, keylen=%d, errorcode=%d, errordesc=%s\n",
				szKey,
				(int32_t)keyLen,
				rc,
				memcached_strerror(memc, rc));
			return S_OK;
		}
		WRITE_ERROR_LOG( "Error: delete memcache object failed! szKey=%s, keyLen=%d, time expiration=%d, errocode=%d, errordesc=%s\n",
			szKey,
			(int32_t)keyLen,
			(int32_t)expiration,
			rc,
			memcached_strerror(memc, rc));
		return E_MEMCACHED_DELETE;
	}
	//WRITE_DEBUG_LOG( "delete memcache object success! szKey=%s, keylen=%d\n", szKey, (int32_t)keyLen);

	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;
}