コード例 #1
0
ファイル: packet.cpp プロジェクト: leandrodiogenes/icarus-emu
bool PACKET::PackRecv() 
{
	if ((packet_len = recv(sockstruct->socket, packet_buf, PACKET_LEN, 0)) == SOCKET_ERROR)
		return false;

	if (packet_len == 0)
	{
		Disconnect();
		return false;
	}

	int nError = WSAGetLastError();
	if (nError != WSAEWOULDBLOCK && nError != 0)
	{
		log::Error(fg, "PCKHandler: Recv packet error: %d \n", nError);
		Disconnect();
		return false;
	}

	offset = 0;
	buf_use_packed = packet_buf;

	real_packet_size = readUW();
	opcode = readUW();
	int cryptflag1 = readUB();
	int cryptflag2 = readUB();
//	offset -= 2;
	packet_len = real_packet_size - offset;

	
	char key[] = { 0xc1, 0xa1, 0xb2, 0xc4, 0x4b, 0x3f, 0x1b, 0x41 };
	int step_key = 0;
	if (cryptflag1 == 2)
	{
		for (int i = 0; i < packet_len; i++)
		{
			buf_use_packed[i + offset] ^= key[step_key];
			++step_key;
			if (step_key == sizeof(key))
				step_key = 0;
		}
	}

	return true;
}
コード例 #2
0
ファイル: packet.cpp プロジェクト: JamShan/IEMU
//====================================================================================
// Получаем пакет от клиента
//
bool PACKET::PackRecv() 
{
	if ((packet_len = recv(sockstruct->socket, packet_buf, PACKET_LEN, 0)) == SOCKET_ERROR)
		return false;

	if (packet_len == 0)
	{
		Disconnect();
		return false;
	}

	int nError = WSAGetLastError();
	if (nError != WSAEWOULDBLOCK && nError != 0)
	{
		Disconnect();
		return false;
	}

	offset = 0;
	buf_use_packed = packet_buf;
	real_packet_size = readUW();
	opcode = readUW();
	cryptflag = readUB();
	int8 cryptflag2 = readUB();
	packet_len = real_packet_size - offset;

	char key[] = { 0xcb, 0x1e, 0xbd, 0x4c, 0xbf, 0x8f, 0xb9, 0x4a };
	int step_key = 0;
	if (cryptflag == 2)
	{
		for (int i = 0; i < packet_len; i++)
		{
			buf_use_packed[i + offset] ^= key[step_key];
			++step_key;
			if (step_key == sizeof(key))
				step_key = 0;
		}
	}
	return true;


//	return false;
}