⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmpacket.cpp

📁 Soul的源代码,类似于劲舞团之类的游戏
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	return *this;
}

CMPacket& CMPacket::operator << ( CMString arg )
{
	return ( *this << arg.getBuffer() );
}

CMPacket& CMPacket::operator >> ( CMString& arg )
{
	TCHAR buff[2048];

	*this >> buff;
	arg = buff;

	return *this;
}

CMPacket& CMPacket::operator << ( CMPacket& arg )
{
	unsigned int idValue = arg.GetID();
	unsigned int size = arg.GetDataFieldSize();

	WriteData( &idValue, sizeof( unsigned int ) );
	WriteData( &size, sizeof( unsigned int ) );
	WriteData( arg.m_cDataField, size );

	return *this;
}

// 捞芭 静瘤富磊 绊摹绊 结具凳.....!@#$@#$@#$
CMPacket& CMPacket::operator >> ( CMPacket& arg )
{
	int idValue, size;
	char buffer[PACKETBUFFERSIZE];

	ReadData( &idValue, sizeof( int ) );
	ReadData( &size, sizeof( int ) );

	ReadData( buffer, size );

	arg.SetID( idValue );
	arg.WriteData( buffer, size );

	return *this;
}

CMPacket& CMPacket::operator << ( bool arg )
{
	WriteData( &arg, sizeof( bool ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( bool& arg )
{
	if(ReadData( &arg, sizeof( bool ) ) == FALSE)
		return m_NullPacketClass;


	return *this;
}

CMPacket& CMPacket::operator << ( byte arg )
{
	WriteData( &arg, sizeof( byte ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( byte& arg )
{
	if(ReadData( &arg, sizeof( byte ) ) == FALSE)
		return m_NullPacketClass;


	return *this;
}


CMPacket& CMPacket::operator << ( DATE arg )
{
	WriteData( &arg, sizeof( DATE ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( DATE& arg )
{
	if(ReadData( &arg, sizeof( DATE ) ) == FALSE)
		return m_NullPacketClass;


	return *this;
}

CMPacket& CMPacket::operator << ( TIMESTAMP_STRUCT arg )
{
	WriteData( &arg, sizeof( TIMESTAMP_STRUCT ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( TIMESTAMP_STRUCT& arg )
{
	if(ReadData( &arg, sizeof( TIMESTAMP_STRUCT ) ) == FALSE)
		return m_NullPacketClass;


	return *this;
}

CMPacket& CMPacket::operator << ( CCHARPACK& arg )
{
	WriteData( arg.m_char, arg.m_iSize);

	return *this;
}
CMPacket& CMPacket::operator >> ( CCHARPACK& arg )
{
	if(ReadData( arg.m_char,arg.m_iSize) == FALSE)
		return m_NullPacketClass;


	return *this;
}

CMPacket& CMPacket::operator << ( SOCKET arg )
{
	WriteData( &arg, sizeof( SOCKET ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( SOCKET& arg )
{
	if(ReadData( &arg, sizeof( SOCKET ) ) == FALSE)
		return m_NullPacketClass;


	return *this;
}

CMPacket& CMPacket::operator << ( void* arg )
{
	long iArg = (long) arg;
	WriteData( &arg, sizeof( void* ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( void* arg )
{
	if(ReadData( arg, sizeof( void* ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( short arg )
{
	WriteData( &arg, sizeof( short ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( short& arg )
{
	if(ReadData( &arg, sizeof( short ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( float arg )
{
	WriteData( &arg, sizeof( float ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( float& arg )
{
	//try
	//{
	if(ReadData( &arg, sizeof( float ) ) == FALSE)
		return m_NullPacketClass;

	//}
	//catch (InvalidPacketException* e) {
	//	delete e;
	//}

	return *this;
}


CMPacket& CMPacket::operator << ( int arg )
{
	WriteData( &arg, sizeof( int ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( int& arg )
{
	if(ReadData( &arg, sizeof( int ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( long arg )
{
	WriteData( &arg, sizeof( long ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( long& arg )
{
	if(ReadData( &arg, sizeof( long ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( DWORD arg )
{
	WriteData( &arg, sizeof( DWORD ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( DWORD& arg )
{
	if(ReadData( &arg, sizeof( DWORD ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( WORD arg )
{
	WriteData( &arg, sizeof( WORD ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( WORD& arg )
{
	if(ReadData( &arg, sizeof( WORD ) ) == FALSE)
		return m_NullPacketClass;

	return *this;
}

CMPacket& CMPacket::operator << ( __int64 arg )
{
	WriteData( &arg, sizeof( __int64 ) );

	return *this;
}

CMPacket& CMPacket::operator >> ( __int64& arg )
{

	if(ReadData( &arg, sizeof( __int64 ) ) == FALSE)
		return m_NullPacketClass;

	return* this;
}


//-------------------------------------------------------------------------------------------------------
//	Name		 :: BOOL PackEncode(char* MemBuf = NULL)
//	Create Date	 :: 2004/ 02/05
//	Description	 :: 菩哦阑 鞠龋拳 矫挪促.
//	param		 ::	
//	Return Value :: 
//	Bug	Report	 ::	
//-------------------------------------------------------------------------------------------------------
void CMPacket::PackEncode(char* MemBuf)
{
	HEADTMP tmpHead;
	LPHEADERINFO headA;

	// 林家蔼捞 甸绢坷搁 弊林家蔼阑 鞠龋拳 矫挪促. 酒聪搁 郴何 皋葛府甫 鞠龋拳 矫挪促.
	if(MemBuf != NULL)
		headA = (LPHEADERINFO) MemBuf;
	else 
		headA = (LPHEADERINFO)m_pPacketBuffer;

	if(headA->HeadInfo.sProtocolEncode == true)
	{
		headA->HeadInfo.sProtocolEncode = true;				// 鞠龋拳啊 等促搁 亲惑 true蔼捞 技泼登绢具 茄促.
		//	磊扁 磊府俊辑 磊扁 磊府肺 持绰促 鞘夸 绝焙..
		tmpHead.Tmp_1	= headA->headTmp1.ProtocolID_1;		//鞠龋拳甫 窍看绰啊甫 魄窜窍扁困秦 盖 菊俊 笼持菌促.. 
		tmpHead.Tmp_2	= headA->headTmp1.GameType_1;
		tmpHead.Tmp_3	= headA->headTmp1.DataSize_1;
		tmpHead.Tmp_4	= headA->headTmp1.ReplayDefence_1;
		tmpHead.Tmp_5	= headA->headTmp1.DataSize_2;
		tmpHead.Tmp_6	= headA->headTmp1.GameType_2;
		tmpHead.Tmp_7	= headA->headTmp1.ProtocolID_2;
		tmpHead.Tmp_8	= headA->headTmp1.ReplayDefence_2;
		tmpHead.Tmp_9   = headA->headTmp1.DataSize_3;
		tmpHead.Tmp_10	= headA->headTmp1.GameType_3;
		tmpHead.Tmp_11	= headA->headTmp1.ProtocolID_3;
		tmpHead.Tmp_12	= headA->headTmp1.ReplayDefence_3;
		tmpHead.Tmp_13	= headA->headTmp1.DataSize_4;
		tmpHead.Tmp_14	= headA->headTmp1.GameType_4;
		tmpHead.Tmp_15	= headA->headTmp1.ProtocolID_4;
		tmpHead.Tmp_16	= headA->headTmp1.ReplayDefence_4;
		memcpy(m_pPacketBuffer,&tmpHead,8);
	}
}


//-------------------------------------------------------------------------------------------------------
//	Name		 :: BOOL PackDecode(char* MemBuf)
//	Create Date	 :: 2004/ 02/05
//	Description	 :: 鞠龋拳 等 菩哦阑 八荤 茄促
//	param		 ::	
//	Return Value :: 
//				FALSE	: 菩哦捞 鞠龋拳 屈侥苞 嘎瘤 臼促搁 
//				TRUE	: 菩哦阑 汗龋拳俊 己傍.
//	Bug	Report	 ::	
//-------------------------------------------------------------------------------------------------------
BOOL CMPacket::PackDecode(char* MemBuf)
{
	HEADERINFO headA = {0,};
	LPHEADERINFO tmpHead = (LPHEADERINFO) MemBuf;
	
	// 鞠龋拳啊 登绢 乐促搁..
	if(tmpHead->HeadInfo.sProtocolEncode == true)
	{
		headA.headTmp1.DataSize_1		= tmpHead->headTmp2.Tmp_3;
		headA.headTmp1.DataSize_2		= tmpHead->headTmp2.Tmp_5;
		headA.headTmp1.DataSize_3		= tmpHead->headTmp2.Tmp_9;
		headA.headTmp1.DataSize_4		= tmpHead->headTmp2.Tmp_13;
		headA.headTmp1.GameType_1		= tmpHead->headTmp2.Tmp_2;
		headA.headTmp1.GameType_2		= tmpHead->headTmp2.Tmp_6;
		headA.headTmp1.GameType_3		= tmpHead->headTmp2.Tmp_10;
		headA.headTmp1.GameType_4		= tmpHead->headTmp2.Tmp_14;
		headA.headTmp1.ProtocolID_1	= tmpHead->headTmp2.Tmp_1;
		headA.headTmp1.ProtocolID_2	= tmpHead->headTmp2.Tmp_7;
		headA.headTmp1.ProtocolID_3	= tmpHead->headTmp2.Tmp_11;
		headA.headTmp1.ProtocolID_4	= tmpHead->headTmp2.Tmp_15;
		headA.headTmp1.ReplayDefence_1 = tmpHead->headTmp2.Tmp_4;
		headA.headTmp1.ReplayDefence_2 = tmpHead->headTmp2.Tmp_8;
		headA.headTmp1.ReplayDefence_3 = tmpHead->headTmp2.Tmp_12;
		headA.headTmp1.ReplayDefence_4 = tmpHead->headTmp2.Tmp_16;;

		if( headA.HeadInfo.sProtocolEncode != headA.HeadInfo.sGameType % 2)
		{
			////秦欧 啊瓷己捞 臭促..
			//CMSingleton<CMDebug>::getInstance()->output("%s(%d)秦欧 菩哦? \n",__FILE__,__LINE__);
			return FALSE;
		}
		memcpy(MemBuf,&headA,8);

		return TRUE;
	}
	else
		if( tmpHead->HeadInfo.sProtocolEncode != tmpHead->HeadInfo.sGameType % 2)
		{
			////秦欧 啊瓷己捞 臭促..
			//CMSingleton<CMDebug>::getInstance()->output("%s(%d)秦欧 菩哦? \n",__FILE__,__LINE__);
			return FALSE;
		}

	return TRUE;
}


//-------------------------------------------------------------------------------------------------------
//	Name		 :: GetHeaderInfo(char* MemBuf,unsigned short &sId,unsigned short *sGameType,unsigned short &sDataSize)
//	Create Date	 :: 2003/12/29
//	Description	 :: MemBuf俊 皋葛府林家甫 楷搬秦林绊 弊皋葛府俊 庆歹 备炼眉甫 
//																某胶泼窍咯 沥焊甫 哗郴绢霖促.
//	param		 ::	
//			char* MemBuf				:	皋葛府蔼阑 持绢霖促.
//			unsigned short &sId			:	庆歹狼 ID甫 府畔茄促.
//			unsigned short &sDataSize	:	菩哦狼 单捞鸥狼 辨捞甫 府畔茄促.
//	Return Value :: void 鸥涝
//	Bug	Report	 ::
//-------------------------------------------------------------------------------------------------------
void CMPacket::GetHeaderInfo(char* MemBuf,unsigned short *sId,unsigned short *sGameType,unsigned short *sDataSize,unsigned short *sRandomID)
{
//	HEADERINFO pHeaderInfo;
	LPHEADERB pHead ;
	pHead = (LPHEADERB) MemBuf;
	if(pHead->sProtocolEncode == true)
	{

	}
	*sId = pHead->sProtocolID;
	*sDataSize = pHead->sDataSize;
	*sGameType = pHead->sGameType;
	*sRandomID = pHead->sReplayDefence;
	//*sId = *(( unsigned short* )( ( char* )MemBuf + HEAD_ID_POISTION ));
	//*sDataSize = *(( unsigned short* )(( char* )MemBuf + HEAD_SIZE_POISTION));
}

//-------------------------------------------------------------------------------------------------------
//	Name		 :: GetHeaderInfo(char* MemBuf,unsigned short &sId,unsigned short &sDataSize)
//	Create Date	 :: 2003/12/29
//	Description	 :: MemBuf俊 皋葛府林家甫 楷搬秦林绊 弊皋葛府俊 庆歹 备炼眉甫 
//																某胶泼窍咯 沥焊甫 哗郴绢霖促.
//	param		 ::	
//			char* MemBuf				:	皋葛府蔼阑 持绢霖促.
//			unsigned short &sId			:	庆歹狼 ID甫 府畔茄促.
//			unsigned short &sDataSize	:	菩哦狼 单捞鸥狼 辨捞甫 府畔茄促.
//	Return Value :: void 鸥涝
//	Bug	Report	 ::
//-------------------------------------------------------------------------------------------------------
void CMPacket::GetHeaderInfo(char* MemBuf,unsigned short *sId,unsigned short *sDataSize,unsigned short *sRandomID)
{
//	HEADERINFO pHeaderInfo;
	LPHEADERB pHead ;
	pHead = (LPHEADERB) MemBuf;
	if(pHead->sProtocolEncode == true)
	{

	}
	*sId = pHead->sProtocolID;
	*sDataSize = pHead->sDataSize;
	*sRandomID = pHead->sReplayDefence;
	//*sId = *(( unsigned short* )( ( char* )MemBuf + HEAD_ID_POISTION ));
	//*sDataSize = *(( unsigned short* )(( char* )MemBuf + HEAD_SIZE_POISTION));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -