Exemplo n.º 1
0
void CGameSocket::RecvCompressedData(char* pBuf)
{
	int index = 0;
	short sCompLen;
	sCompLen = GetShort(pBuf, index);

	Parsing(sCompLen, pBuf+index);
}
Exemplo n.º 2
0
bool CUdpSocket::PacketProcess(int len)
{
	BYTE		*pTmp;
	bool		foundCore;
	MYSHORT		slen;
	int length;

	if( len <= 0 ) return false;

	pTmp = new BYTE[len+1];

	memcpy( pTmp, m_pRecvBuf, len );

	foundCore = FALSE;

	int	sPos=0, ePos = 0;

	for (int i = 0; i < len && !foundCore; i++)
	{
		if (i+2 >= len) break;

		if (pTmp[i] == PACKET_START1 && pTmp[i+1] == PACKET_START2)
		{
			sPos = i+2;

			slen.b[0] = pTmp[sPos];
			slen.b[1] = pTmp[sPos + 1];

			length = slen.w;

			if( length <= 0 ) goto cancelRoutine;
			if( length > len ) goto cancelRoutine;

			ePos = sPos+length + 2;

			if( (ePos + 2) > len ) goto cancelRoutine;

			if (pTmp[ePos] == PACKET_END1 && pTmp[ePos+1] == PACKET_END2)
			{
				Parsing( (char*)(pTmp+sPos+2), length );
				foundCore = TRUE;
				break;
			}
			else 
				goto cancelRoutine;
		}
	}

	delete[] pTmp;

	return foundCore;

cancelRoutine:	
	delete[] pTmp;
	return foundCore;
}
Exemplo n.º 3
0
void benchmark(llvm::TimerGroup &Group, llvm::StringRef Name,
               llvm::StringRef JSONText) {
  llvm::Timer BaseLine((Name + ": Loop").str(), Group);
  BaseLine.startTimer();
  char C = 0;
  for (llvm::StringRef::iterator I = JSONText.begin(),
                                 E = JSONText.end();
       I != E; ++I) { C += *I; }
  BaseLine.stopTimer();
  volatile char DontOptimizeOut = C; (void)DontOptimizeOut;

  llvm::Timer Parsing((Name + ": Parsing").str(), Group);
  Parsing.startTimer();
  llvm::SourceMgr SM;
  llvm::JSONParser Parser(JSONText, &SM);
  if (!Parser.validate()) {
    llvm::errs() << "Parsing error in JSON parser benchmark.\n";
    exit(1);
  }
  Parsing.stopTimer();
}
Exemplo n.º 4
0
void CHelp::GetHelpContent(char* section,char* key,char* ImageKey)
{
	DWORD dwSaveSize = 100;
	char  szSaveStr[100];
	char  szImageDir[100];
	DWORD dwReturn,dwFileSize=0,dwRead = 0;
	HANDLE hFile = NULL;
	char *HelpContent;

	ZeroMemory(m_HelpContent,sizeof(m_HelpContent));
	ZeroMemory(szImageDir,sizeof(szImageDir));

	dwReturn = GetPrivateProfileString(section,key,"Error",szSaveStr,1024,HELP_CONTENT);

	if(dwReturn == 0) return;
	dwReturn = GetPrivateProfileString(section,ImageKey,"Error",szImageDir,1024,HELP_CONTENT);
	if(dwReturn == 0) return;

	LoadGuideImage(szImageDir);

	hFile = CreateFile( szSaveStr, GENERIC_READ, FILE_SHARE_READ,
                        NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL , NULL );

	if(hFile == INVALID_HANDLE_VALUE) return ;

	dwFileSize = GetFileSize(hFile,NULL);

	HelpContent = new char[dwFileSize];
	ZeroMemory(HelpContent,sizeof(char)*dwFileSize);

	ReadFile(hFile,HelpContent,dwFileSize,&dwRead,NULL);
	CloseHandle(hFile);

	Parsing(HelpContent);

	delete[] HelpContent;	

}
Exemplo n.º 5
0
void CIOCPSocket2::ReceivedData(int length)
{
	if (length <= 0 || length >= MAX_PACKET_SIZE) return;

	int len = 0;
	char *pData;

	// read received bytes into our circular buffer
	m_pBuffer->PutData(m_pRecvBuff, length); 

	// go over our circular buffer to try and find any KO packets, so we can parse them
	while (PullOutCore(pData, len))
	{
		if (pData)
		{
			// found a packet - it's parse time!
			Parsing(len, pData);

			delete [] pData;
			pData = NULL;
		}
	}
}
Exemplo n.º 6
0
Pop3Adaptor::Pop3Adaptor(char *fileName) :msgToDele(0){
	UserFile = fileName;
	ifstream inputData(fileName);
	Parsing(inputData);
	inputData.close();
}
Exemplo n.º 7
0
void CIOCPSocket2::ReceivedData(int length)
{
	if (length <= 0 || length >= MAX_PACKET_SIZE) 
		return;

	// Add the new packet data to the buffer
	m_pBuffer->PutData(m_pRecvBuff, length);

	do
	{
		// if we haven't started reading the packet, let's start now...
		if (m_remaining == 0)
		{
			// do we have enough data to start reading?
			if (m_pBuffer->GetSize() < 5)
				return; // wait for more data

			// pull the first 2 bytes from the stream, should be our header.
			uint16 header;
			m_pBuffer->GetData((char *)&header, sizeof(header));
			m_pBuffer->HeadIncrease(sizeof(header));

			// not our header? uh oh.
			if (header != 0x55aa)
			{
				TRACE("[SID=%d] Invalid header (%X)\n", m_Sid, header);
				Close();
				return;
			}

			// next 2 bytes should be the packet length
			m_pBuffer->GetData((char *)&m_remaining, sizeof(m_remaining));
			m_pBuffer->HeadIncrease(sizeof(m_remaining));
		}

		// is the packet just too big to do anything with? well, screw them.
		if (m_remaining > MAX_PACKET_SIZE)
		{
			TRACE("[SID=%d] Packet too big (or broken packet) at %d bytes\n", m_Sid, m_remaining);
			Close();
			return;
		}

		// Do we have all the data in our buffer yet?
		// If not, we'll wait and try again (in the case of fragmented packets)... but we're not going to wait too long, mind.
		if (m_pBuffer->GetSize() < m_remaining)
		{
			TRACE("[SID=%d] Don't have enough data to read packet, tried %d times so far\n", m_Sid, m_retryAttempts);
			if (++m_retryAttempts > 3)
			{
				TRACE("[SID=%d] Too many attempts to retrieve packet, user is laggy or screwing with us.\n", m_Sid);
				Close();
			}
			return;
		}

		// We have all of the packet! Yay us!
		m_retryAttempts = 0;

		// this is really horrible, but it'll suffice for testing
		uint8 in_stream[MAX_PACKET_SIZE], out_stream[MAX_PACKET_SIZE];

		m_pBuffer->GetData((char *)in_stream, m_remaining);
		m_pBuffer->HeadIncrease(m_remaining);

		// Is the packet encrypted? If so, decrypt it first.
		if (m_CryptionFlag)
		{
			int result = jct.JvDecryptionWithCRC32(m_remaining, in_stream, out_stream);
			if (m_remaining < 4 // invalid packet (server packets have a checksum)
				|| result < 0 // invalid checksum 
				|| ++m_Rec_val != *(uint32 *)(out_stream)) // invalid sequence ID
			{
				TRACE("[SID=%d] m_remaining(%d) < 4, invalid CRC(%d) or invalid sequence (%d != %d)\n", m_Sid, m_remaining, result, m_Rec_val, *(uint32 *)(out_stream));
				Close();
				return;
			}

			m_remaining -= 4;
			memcpy(in_stream, &out_stream[4], m_remaining); // sigh..
			// TRACE("[SID=%d] Decrypted packet %X (len=%d)\n", m_Sid, *in_stream,  m_remaining);
		}

		uint16 footer;
		m_pBuffer->GetData((char *)&footer, sizeof(footer));
		m_pBuffer->HeadIncrease(sizeof(footer));

		if (footer != 0xaa55)
		{
			TRACE("[SID=%d] Invalid packet footer, received %X\n", m_Sid, footer); // LAST ONE!?
			Close();
			return;
		}

		// found a packet - it's parse time!
		Parsing(m_remaining, (char *)in_stream);
		m_remaining = 0;
	}
	while (!m_pBuffer->isEmpty());
}