Example #1
0
static int TestEncryptDecrypt(const Crypto& cryptoA, const Crypto& cryptoB)
{
	std::string content= cryptoA.GeneratePassword(std::string("0123456789abcdefghijklmnopqrstuvABCDEFGHIJKLMNOPQRSTUVWXYZ"), 256000);
	auto encrypted = cryptoA.Encrypt(std::vector<BYTE>(content.begin(), content.end()), true);
	auto decrypted = cryptoB.Decrypt(encrypted, true);
	auto sameCount = 0;

	for (auto index = 0 ; index != content.length() ; ++index)
	{
		sameCount += content[index] == encrypted[index] ? 1 : 0;

		if (content[index] != decrypted[index])
		{
			std::wcout << L"Crypto::Encrypt decrypted content error" << std::endl;
			return 1;
		}
	}

	if (sameCount == content.length())
	{
		std::wcout << L"Crypto::Encrypt encrypted content error" << std::endl;
		return 1;
	}

	return 0;
}
Example #2
0
// Our thread to handle incoming packets
void *recv_thread( void *arg ) {
	int s = *(int*) arg;
	struct sockaddr_in si_other;
	socklen_t slen = sizeof( si_other );
	int ret;
	unsigned char buffer[512];

	Crypto crypto;

	while( !exit_bot ) {
		ret = recvfrom( s, buffer, 512, 0, (struct sockaddr*)&si_other, &slen );
		if( ret == -1 ) {
			printf( "Recvfrom error\n" );
			return 0;
		}
		//printf( "Length of packet: %i\n", ret );
		//printf( "Received packet from %s:%d\n", inet_ntoa( si_other.sin_addr ), ntohs( si_other.sin_port ));
		crypto.Decrypt( buffer, ret );

		//printf( "recveived packet: " );
		//for( int i = 0; i < ret; i++ ) {
		//	printf( "%02X ", buffer[ i ] );
		//}
		//printf( "\n" );

		if( buffer[0] == 0x25 ) { // Ping Response
			ping_success = true;
		} else if( buffer[0] == 0x0F ) {
			login_success = true;
		// Get the player id for the first player
			player_id = *(uint16*)&buffer[41]; //1 = first, 41 = second
			printf( "[%s] Player ID: %i\n", currentDateTime().c_str(), player_id );
		} else if( buffer[0] == 0x1F ) { // Enter world response
			InitialLoginData ild = *(InitialLoginData*)&buffer[1];

			printf( "X/Y: %i, %i | MapID: %i | Player ID: %i\n ", ild.positionX, ild.positionY, ild.mapId, ild.serverId );

			loggedin = true;
		} else if( buffer[0] == 0x03 ) { // Update packet
			handleUpdatePacket( buffer, ret );
		} else if( buffer[0] == 0x1e ) { // Quest Log
			QuestLog q = *(QuestLog*)&buffer[1];

			if( q.curkills == q.reqkills || q.curkills == 100 ) {
				finished_quest = true;
			}
			if( q.curquest != 87 ) {
				finished_quest = true;
				missing_quest = true;
			} else {
				have_quest = true;
			}

			lastQL = q;

			printf( "[%s] QuestLog Requested: %i kills of %i\n", currentDateTime().c_str(), q.curkills, q.reqkills );
		} else if( buffer[0] == 0x0C ) { // Logout and misc?
			if( buffer[1] == 0x15 ) { // Logout
				login_success = false;
				loggedin = false;
				finished_quest = true;
				missing_quest = true;

				printf( "[%s] Player has logged out\n", currentDateTime().c_str());
			} else {
				//printf( "[%s] Recived 0x0C Packet Type\n", currentDateTime().c_str());
				//FILE *o = fopen( "in-packets.log", "a+" );
				//for( int i = 0; i < ret; i++ ) {
				//	fprintf( o, "%02X ", buffer[ i ] );
				//}
				//fprintf( o, "\n" );
				//fclose( o );
			}
		}
	}

	return 0;
}