示例#1
0
BOOL	DBThread::ProcessCacheCommand()
{
    PlayerID_t PlayerID ;

    _MY_TRY
    {
        BOOL ret = FALSE ;

        Packet* pPacket = NULL ;


        ret = RecvPacket( pPacket, PlayerID);


        if( !ret )
            return TRUE ;

        Player* pPlayer = g_pPlayerPool->GetPlayer( PlayerID ) ;
        if( pPlayer )
        {
            pPacket->Execute(pPlayer) ;
        }
        else
        {
            pPacket->Execute(NULL);
        }

        g_pPacketFactoryManager->RemovePacket( pPacket ) ;

        return TRUE;
    }

    _MY_CATCH
    {
        g_pLog->FastSaveLog(LOG_FILE_0,"DBThread::ProcessCacheCommand Get Errors,TID=%d,PlayerID =%d",getTID(),PlayerID);
        return TRUE;
    }


}
示例#2
0
/**
 *处理接入的数据包,解密包,分解包,执行包的操作
 *\return 返回操作是否成功
 */
bool Player::ProcessCommand( bool option )
{
	bool ret = false;

	CHAR header[PACKET_HEADER_SIZE];
	PacketID_t packetID;
	UINT packetuint = 0;
	UINT packetSize = 0;
	UINT packetIndex = 0;
	UINT packetTick = 0;
	//Packet* pPacket = NULL;

	if( IsDisconnect())
		return true;

	if(option)
	{
	}

	for( ;; )
	{
		CHAR compart[PACK_COMPART_SIZE]={0};
		if(!m_pSocketInputStream->Find(compart))
			break;

		if(!m_pSocketInputStream->Peek(&header[0], PACKET_HEADER_SIZE))
		{
			break;
		}

		memcpy( &packetID, &header[0], sizeof(PacketID_t) );
		memcpy( &packetTick, &header[sizeof(PacketID_t)], sizeof(UINT) );
		memcpy( &packetuint, &header[sizeof(UINT) + sizeof(PacketID_t)], sizeof(UINT) );
		packetSize = GET_PACKET_LEN(packetuint);
		packetIndex = GET_PACKET_INDEX(packetuint);

		std::cout<<" PacketID:"<<packetID<<" packetTick:"<<packetTick<<" packetuint:"<<packetuint<<" packetSize:"<<packetSize<<" packetIndex:"<<packetIndex<<std::endl;

		if(packetID >= (PacketID_t)PACKET_MAX)
		{
			Assert(false);
			return false;
		}
		//消息解密
		//
		//

		if( m_pSocketInputStream->Length()<PACKET_HEADER_SIZE+packetSize)
		{
			g_pLog->log_debug("%u,%u,m_pSocketInputStream->Length < ...",0,0);
			break;
		}

		Packet* pPacket = g_pPacketFactoryManager->CreatePacket(packetID);
		if(pPacket == NULL)
		{
			Assert(false);
			return false;
		}

		std::cout<<"Create packet success\n";

		pPacket->SetPacketIndex(packetIndex);

		ret = m_pSocketInputStream->ReadPacket(pPacket);
		if(ret==false)
		{
			Assert(false);
			g_pPacketFactoryManager->RemovePacket(pPacket);

			return false;
		}

		bool bNeedRemove = true;

		//this->ResetKick( );
		
		//执行包操作
		UINT uret = pPacket->Execute( this );
		if(uret == PACKET_EXE_ERROR)
		{
			if(pPacket)
				g_pPacketFactoryManager->RemovePacket(pPacket);

			return false;
		}
		else if(uret == PACKET_EXE_BREAK)
		{
			if(pPacket)
				g_pPacketFactoryManager->RemovePacket(pPacket);

			break;
		}
		else if(uret==PACKET_EXE_CONTINUE)
		{//继续解析剩下消息
		}
		else if(uret==PACKET_EXE_NOTREMOVE)
		{//继续解析剩下消息,不回收
			bNeedRemove = false;
		}
		else if(uret==PACKET_EXE_NOTREMOVE_ERROR)
		{
			return false;
		}
		else
		{
			Assert(false);
		}


		if(pPacket && bNeedRemove)
			g_pPacketFactoryManager->RemovePacket(pPacket);
	}


	return true;
}