Esempio n. 1
0
    // ---------------------------------------------------------------------
    // Audio CaptureRecorder Test
    //
    void runAVInputReaderRecorderTest()
    {
        PacketStream stream;

        // Create the Encoder Options
        av::EncoderOptions options;
        options.ofile = "audio_test.mp4";
        options.duration = 5; //time(0) +
        options.oformat = av::Format("AAC", "aac",
            av::AudioCodec("AAC", "aac", 2, 44100, 96000, "fltp"));
            //av::AudioCodec("MP3", "libmp3lame", 2, 44100, 128000, "s16p"));

        // Attach the Audio Capture
        av::AVInputReader::Ptr reader(new av::AVInputReader());
        reader->openAudioDevice(0,
            options.oformat.audio.channels,
            options.oformat.audio.sampleRate);
        reader->getEncoderFormat(options.iformat);

        // Attach the Audio Capture
        stream.attachSource<av::AVInputReader>(reader, true);

        // Attach the Audio Encoder
        auto encoder = new av::AVPacketEncoder(options);
        encoder->initialize();
        stream.attach(encoder, 5, true);

        stream.start();
        scy::pause();
        stream.stop();
    }
Esempio n. 2
0
STDMETHODIMP
BasicPacketFlow::HandleSubscribe(INT32 lRuleNumber, UINT16 unStreamNumber)
{
    PacketStream* pStream = &m_pStreams[unStreamNumber];
    HX_ASSERT(pStream->m_bStreamRegistered);

    INT32 ret = pStream->SubscribeRule(lRuleNumber,
                                       m_bInitialSubscriptionDone,
                                       m_bIsMulticast,
                                       m_pFlowMgr);

    if (ret >= 0)
    {
        m_bSubscribed = TRUE;
	
	if (m_pRateManager)
	{
	    IHXPacketFlowControl* pRateMgrFlowControl = NULL;
	    if (HXR_OK == m_pRateManager->QueryInterface(IID_IHXPacketFlowControl,
							 (void**)&pRateMgrFlowControl))
	    {
		pRateMgrFlowControl->HandleSubscribe(lRuleNumber, unStreamNumber);
		HX_RELEASE(pRateMgrFlowControl);
	    }
	}
    }

    return HXR_OK;
}
Esempio n. 3
0
    // ---------------------------------------------------------------------
    // Audio CaptureRecorder Test
    //
    void runAudioStreamRecorderTest()
    {
        PacketStream stream;

        // Create the Encoder Options
        av::EncoderOptions options;
        options.ofile = "audio_test.mp3";
        //options.stopAt = time(0) + 5;
        options.oformat = av::Format("MP3", "mp3",
            av::AudioCodec("MP3", "libmp3lame", 2, 44100, 128000, "s16p"));

        // Create the Audio Capture
        av::Device dev;
        auto& media = av::MediaFactory::instance();
        media.devices().getDefaultAudioInputDevice(dev);
        InfoL << "Default audio capture " << dev.id << endl;
        av::AudioCapture::Ptr audioCapture = media.createAudioCapture(0, //dev.id
            options.oformat.audio.channels,
            options.oformat.audio.sampleRate);
        audioCapture->getEncoderFormat(options.iformat);

        // Attach the Audio Capture
        stream.attachSource<av::AudioCapture>(audioCapture, true);

        // Attach the Audio Encoder
        //auto encoder = new av::AVPacketEncoder(options);
        //encoder->initialize();
        //stream.attach(encoder, 5, true);

        //CaptureRecorder enc(audioCapture, options);

        stream.start();
        scy::pause();
        stream.stop();
    }
void Game::SendFinishRace()
{
	PacketStream PS;

	ENUM_Event e = FINISHEDRACE;
	PS.writeInt(e);

	e = ENDOFMESSAGE;
	PS.writeInt(e);

	// get the data from the stream
	char data[100];
	PS.toCharArray(data);

	// send the data
	Net::GetInstance()->SendData(data,"127.0.0.1",m_sendToPort);

	// increment num packets sent
	m_numPacketsSent++;

	m_raceFinished = true;
	if(m_host)
	{
		m_hostWon = true;
	}
	else
	{
		m_hostWon = false;
	}
}
Esempio n. 5
0
void GameNetInterface::sendQuery(const Address &theAddress, const Nonce &clientNonce, U32 identityToken)
{
   PacketStream packet;
   packet.write(U8(Query));
   clientNonce.write(&packet);
   packet.write(identityToken);
   packet.sendto(mSocket, theAddress);
}
Esempio n. 6
0
// Send ping to the server.  If server has different PROTOCOL_VERSION, the packet will be ignored.  This prevents players
// from seeing servers they are incompatible with.
void GameNetInterface::sendPing(const Address &theAddress, const Nonce &clientNonce)
{
   PacketStream packet;
   packet.write(U8(Ping));
   clientNonce.write(&packet);
   packet.write(CS_PROTOCOL_VERSION);
   packet.sendto(mSocket, theAddress);
}
Esempio n. 7
0
void* routingPacket(void* buffin)
{
	PacketBufferV* buff = (PacketBufferV*) buffin;
	int npix_idx = 0;
	int nsamp_idx = 0;
	// load packet type (once per thread)
	PacketStream* ps;
	pthread_mutex_lock(&lockp);
	try {
		ps = new PacketStream(configFileName.c_str());
	} catch (PacketException* e)
	{
		cout << "Error during routingPacket: ";
		cout << e->geterror() << endl;
	}
	pthread_mutex_unlock(&lockp);
	
	ByteStreamPtr localBuffer[PACKET_NUM];
	int npix[PACKET_NUM];
	int nsamp[PACKET_NUM];
	for(int n=0; n<NTIMES; n++)
	{
		// copy PACKET_NUM packets data locally
		pthread_mutex_lock(&lockp);
		for(int m=0; m<PACKET_NUM; m++)
		{
			ByteStreamPtr rawPacket = buff->getNext();
			localBuffer[m] = rawPacket;
			
		}
		pthread_mutex_unlock(&lockp);
		
		for(int m=0; m<PACKET_NUM; m++)
		{
			ByteStreamPtr rawPacket = localBuffer[m];
			Packet *p = ps->getPacket(rawPacket);
			// get npixel and nsamples
			if(p->getPacketID() > 0) {
				sizeMB += (p->size() / 1000000.0);
				//do something with the packet
				;
			}
#ifdef DEBUG
			else {
				cout << "Warning: no packet recognized" << endl;
			}
#endif
			
#ifdef DEBUG
			std::cout << "tot size (MB) " << sizeMB << std::endl;
#endif
		}
	}
	delete ps;
	return 0;
}
void LoginServerSession::parseInputPacket()
{
	PacketStream * ps = NULL;
	int msg_length = 0;
//	try
	{
		msg_length = m_input_msg_block.length();
		while(true)
		{
			if (m_input_msg_block.length() < sizeof(Header))
			{
				break;
			}

			ps = new PacketStream();
			memcpy(ps->re_head(), m_input_msg_block.rd_ptr(), ps->head_size());
			if (m_input_msg_block.length() >= ps->head_size() + ps->body_size())
			{
				m_input_msg_block.rd_ptr(ps->head_size());
				if (ps->body_size() > 0)
				{
					memcpy(ps->re_body(), m_input_msg_block.rd_ptr(), ps->body_size());
					m_input_msg_block.rd_ptr(ps->body_size());
				}
				else
				{
					// do nothing
				}

//				ManageStat::instance()->statClientInputTraffic(ps->stream_size(), 1);
				ManageClientValidation::instance()->handlePackage(ps);
				msg_length = m_input_msg_block.length();
			}
			else
			{
				delete ps;
				break;
			}
		}

		if (m_input_msg_block.rd_ptr() != m_input_msg_block.base())
		{
			msg_length = m_input_msg_block.length();
			if (msg_length > 0)
			{
				memcpy(m_input_msg_block.base(), m_input_msg_block.rd_ptr(), msg_length);
			}
			m_input_msg_block.rd_ptr(m_input_msg_block.base());
			m_input_msg_block.wr_ptr(m_input_msg_block.base() + msg_length);
		}
	}
	//catch (...)
	//{
	//	GATE_LOG_ERROR(ACE_TEXT("Raise unknown exception in LoginServerSession::parseInputPacket, last error is <%d>\n"), ACE_OS::last_error());
	//}
}
Esempio n. 9
0
void NetInterface::sendConnectChallengeResponse(const Address &addr, Nonce &clientNonce, bool wantsKeyExchange, bool wantsCertificate)
{
   PacketStream out;
   out.write(U8(ConnectChallengeResponse));
   clientNonce.write(&out);
   
   U32 identityToken = computeClientIdentityToken(addr, clientNonce);
   out.write(identityToken);

   // write out a client puzzle
   Nonce serverNonce = mPuzzleManager.getCurrentNonce();
   U32 difficulty = mPuzzleManager.getCurrentDifficulty();
   serverNonce.write(&out);
   out.write(difficulty);

   if(out.writeFlag(mRequiresKeyExchange || (wantsKeyExchange && !mPrivateKey.isNull())))
   {
      if(out.writeFlag(wantsCertificate && !mCertificate.isNull()))
         out.write(mCertificate);
      else
         out.write(mPrivateKey->getPublicKey());
   }
   TNLLogMessageV(LogNetInterface, ("Sending Challenge Response: %8x", identityToken));

   out.sendto(mSocket, addr);
}
Esempio n. 10
0
int main(int argc, char** argv)
{
    Logger::instance().add(new ConsoleChannel("debug", Level::Trace)); // Debug
    {
        // Create a PacketStream to pass packets
        // from device captures to the encoder
        PacketStream stream;

        av::EncoderOptions options;
        options.ofile = OUTPUT_FILENAME;
        options.oformat = OUTPUT_FORMAT;
        options.iformat.audio.enabled = false; // enabled if available
        options.iformat.video.enabled = false; // enabled if available

        // Create a device manager instance to enumerate system devices
        av::Device device;
        av::DeviceManager devman;

        // Create and attach the default video capture
        av::VideoCapture video;
        if (devman.getDefaultCamera(device)) {
            LInfo("Using video device: ", device.name)
            video.openVideo(device.id, { 640, 480 });
            video.getEncoderFormat(options.iformat);
            stream.attachSource(&video, false, true);
        }

        // Create and attach the default audio capture
        av::AudioCapture audio;
        if (devman.getDefaultMicrophone(device)) {
            LInfo("Using audio device: ", device.name)
            audio.openAudio(device.id, { 2, 44100 });
            audio.getEncoderFormat(options.iformat);
            stream.attachSource(&audio, false, true);
        }

        // Create and attach the multiplex encoder
        av::MultiplexPacketEncoder encoder(options);
        encoder.init();
        stream.attach(&encoder, 5, false);

        // Start the stream
        stream.start();

        // Keep recording until Ctrl-C is pressed
        LInfo("Recording video: ", OUTPUT_FILENAME)
        waitForShutdown([](void* opaque) {
            reinterpret_cast<PacketStream*>(opaque)->stop();
        }, &stream);
    }

    // Logger::destroy();
    return 0;
}
Esempio n. 11
0
void NetInterface::checkIncomingPackets()
{
   PacketStream stream;
   NetError error;
   Address sourceAddress;

   mCurrentTime = Platform::getRealMilliseconds();

   // read out all the available packets:
   while((error = stream.recvfrom(mSocket, &sourceAddress)) == NoError)
      processPacket(sourceAddress, &stream);
}
Esempio n. 12
0
void NetInterface::sendConnectReject(ConnectionParameters *conn, const Address &theAddress, const char *reason)
{
   if(!reason)
      return; // if the stream is NULL, we reject silently

   PacketStream out;
   out.write(U8(ConnectReject));
   conn->mNonce.write(&out);
   conn->mServerNonce.write(&out);
   out.writeString(reason);
   out.sendto(mSocket, theAddress);
}
Esempio n. 13
0
bool StreamManager::closeStream(const std::string& name, bool whiny) 
{
	assert(!name.empty());

	DebugL << "Close stream: " << name << endl;
	PacketStream* stream = get(name, whiny);
	if (stream) {
		stream->close();
		return true;
	}
	return false;
}
void NetInterface::sendConnectReject(ConnectionParameters *conn, const Address &theAddress, NetConnection::TerminationReason reason)
{
   //if(!reason)
   //   return; // if the stream is NULL, we reject silently

   PacketStream out;
   out.write(U8(ConnectReject));
   conn->mNonce.write(&out);
   conn->mServerNonce.write(&out);
   out.writeEnum(reason, NetConnection::TerminationReasons);
   out.writeString("");
   out.sendto(mSocket, theAddress);
}
Esempio n. 15
0
bool AskService::SubmitQuestion(IAnswer *answerCB, char16* nickname, char16* password, char16* questionText, int32 numberOfPhotos, int32 responseType, ArrayOfString *customResponses, int32 durationType, bool isPrivate)
{
    if (!StartRequest(answerCB, AskService::EPS_SUBMITQUESTION))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(16);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);
    isOk = isOk &&  str->WriteWString(questionText);
    isOk = isOk &&  str->WriteInt32(numberOfPhotos);
    isOk = isOk &&  str->WriteInt32(responseType);
    isOk = isOk &&  customResponses->WriteToStream(str);
    isOk = isOk &&  str->WriteInt32(durationType);
    isOk = isOk &&  str->WriteInt8((int8)isPrivate);

    return isOk && EndRequest();

}
int LoginServerSession::processWrite(PacketStreamQue_t & output_packet_que)
{
	m_output_msg_block.crunch();

	PacketStream * packet = NULL;

	while (output_packet_que.size() > 0)
	{
		packet = output_packet_que.front();
		if (packet->stream_size() <= m_output_msg_block.space())
		{
			m_output_msg_block.copy(packet->stream(), packet->stream_size());

			delete packet;
			packet = NULL;
			output_packet_que.pop();
		}
		else
		{
			break;
		}
	}

	if (m_output_msg_block.length() == 0)
	{
		return 1;
	}

	int send_n = this->peer().send(m_output_msg_block.rd_ptr(), m_output_msg_block.length());

	if (send_n > 0)
	{
		m_output_msg_block.rd_ptr(send_n);
	}
	else
	{
		int last_error = ACE_OS::last_error();
		if ((EWOULDBLOCK == last_error) || (EINTR == last_error) || (EAGAIN == last_error))
		{
			// ok
			return 1;
		}
		else
		{
			return 2;
		}
	}

	return 0;
}
Esempio n. 17
0
void NetInterface::sendConnectChallengeRequest(NetConnection *conn)
{
   TNLLogMessageV(LogNetInterface, ("Sending Connect Challenge Request to %s", conn->getNetAddress().toString()));
   PacketStream out;
   out.write(U8(ConnectChallengeRequest));
   ConnectionParameters &params = conn->getConnectionParameters();
   params.mNonce.write(&out);
   out.writeFlag(params.mRequestKeyExchange);
   out.writeFlag(params.mRequestCertificate);
 
   conn->mConnectSendCount++;
   conn->mConnectLastSendTime = getCurrentTime();
   out.sendto(mSocket, conn->getNetAddress());
}
void NetInterface::sendConnectAccept(NetConnection *conn)
{
   logprintf(LogConsumer::LogNetInterface, "Sending Connect Accept - connection established.");

   PacketStream out;
   out.write(U8(ConnectAccept));
   ConnectionParameters &theParams = conn->getConnectionParameters();

   theParams.mNonce.write(&out);
   theParams.mServerNonce.write(&out);
   U32 encryptPos = out.getBytePosition();
   out.setBytePosition(encryptPos);

   out.write(conn->getInitialSendSequence());
   conn->writeConnectAccept(&out);

   if(theParams.mUsingCrypto)
   {
      out.write(SymmetricCipher::KeySize, theParams.mInitVector);
      SymmetricCipher theCipher(theParams.mSharedSecret);
      out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);
   }

   out.sendto(mSocket, conn->getNetAddress());
}
void ClientStrategyCenter::clientClosedNotifyGS(ClientSession * client_session)
{
	//client already send rolechoose message to gs
	if (client_session->getClientLoginGS())
	{
		//client_session->setClientLogout(true);
		client_session->setNotFindGS(true);
		typed::protocol::cmsg_player_leave_map leave_map;
		leave_map.set_leave_type(1);

		PacketStream * ps = new PacketStream(CMSG_PLAYER_LEAVE_MAP, client_session->getRoleGuid(), leave_map.SerializeAsString());
		ps->setRoleLocation(client_session->getRoleLocation());
		ps->setLineNO(client_session->getLineNo());
		RouteClientPackage::instance()->putInputPackage(ps);
	}
}
Esempio n. 20
0
void Tool::packetdump(char **argv)
{
	PacketStream packetfile;
	const char *path = *argv;
	Encoded buffer;
	Info info;
	ssize_t count;
	
	packetfile.open(argv);

	if(!packetfile.isOpen())
	{
		cerr << "audiotool: " << path << ": unable to access" << endl;
		exit(-1);
	}

	if(!packetfile.isStreamable())
	{
		cerr << "audiotool: " << path << ": missing needed codec" << endl;
		exit(-1);
	}

	packetfile.getInfo(&info);

	buffer = new unsigned char[maxFramesize(info)];

	while((count = packetfile.getPacket(buffer)) > 0)
		cout << "-- " << count << endl;			

	delete[] buffer;
	packetfile.close();		
	exit(0);
}
Esempio n. 21
0
STDMETHODIMP
BasicPacketFlow::HandleUnSubscribe(INT32 lRuleNumber, UINT16 unStreamNumber)
{
    PacketStream* pStream = &m_pStreams[unStreamNumber];
    HX_ASSERT(pStream->m_bStreamRegistered);

    if (lRuleNumber >= pStream->m_lNumRules)
	return HXR_OK;

    pStream->m_pRules[lRuleNumber].m_bRuleOn = FALSE;

    if (!m_bInitialSubscriptionDone)
    {
        return HXR_OK;
    }

    if (pStream->m_pRules[lRuleNumber].m_bWaitForSwitchOffFlag)
    {
        pStream->m_pRules[lRuleNumber].m_PendingAction = ACTION_OFF;
    }
    else if (pStream->m_pRules[lRuleNumber].m_bBitRateReported)
    {
        
        // Update delivery rate
	if (m_pRateManager)
	{
	    IHXPacketFlowControl* pRateMgrFlowControl = NULL;
	    if (HXR_OK == m_pRateManager->QueryInterface(IID_IHXPacketFlowControl,
							 (void**)&pRateMgrFlowControl))
	    {
		pRateMgrFlowControl->HandleUnSubscribe(lRuleNumber, unStreamNumber);
		HX_RELEASE(pRateMgrFlowControl);
	    }
	}
        
	INT32 lChange = (-1) * (INT32)pStream->m_pRules[lRuleNumber].m_ulAvgBitRate;
        ASSERT(pStream->m_bGotSubscribe);
        pStream->ChangeDeliveryBandwidth(lChange);
        m_pFlowMgr->ChangeDeliveryBandwidth(
            lChange, !m_bIsMulticast && !pStream->m_bNullSetup);
        pStream->m_pRules[lRuleNumber].m_bBitRateReported = FALSE;
    }

    return HXR_OK;
}
Esempio n. 22
0
void NetInterface::disconnect(NetConnection *conn, NetConnection::TerminationReason reason, const char *reasonString)
{
   if(conn->getConnectionState() == NetConnection::AwaitingChallengeResponse ||
      conn->getConnectionState() == NetConnection::AwaitingConnectResponse)
   {
      conn->onConnectTerminated(reason, reasonString);
      removePendingConnection(conn);
   }
   else if(conn->getConnectionState() == NetConnection::Connected)
   {
      conn->setConnectionState(NetConnection::Disconnected);
      conn->onConnectionTerminated(reason, reasonString);
      if(conn->isNetworkConnection())
      {
         // send a disconnect packet...
         PacketStream out;
         out.write(U8(Disconnect));
         ConnectionParameters &theParams = conn->getConnectionParameters();
         theParams.mNonce.write(&out);
         theParams.mServerNonce.write(&out);
         U32 encryptPos = out.getBytePosition();
         out.setBytePosition(encryptPos);
         out.writeString(reasonString);

         if(theParams.mUsingCrypto)
         {
            SymmetricCipher theCipher(theParams.mSharedSecret);
            out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);
         }
         out.sendto(mSocket, conn->getNetAddress());
      }
      removeConnection(conn);
   }
}
Esempio n. 23
0
int main(int argc, const char **argv)
{
   if(argc < 2)
   {
      printf("Usage: tnlping <remoteAddress> [sourceAddress]\n\n"
      "Example 1: Simple usage expecting port 28000\n   tnlping 192.168.1.2\n\n"
      "Example 2: Advanced usage with specific port\n   tnlping 192.168.1.2:28001\n\n");
      return 1;
   }
   
   U8 randData[sizeof(U32) + sizeof(S64)];
   *((U32 *) randData) = Platform::getRealMilliseconds();
   *((S64 *) (randData + sizeof(U32))) = Platform::getHighPrecisionTimerValue();
   TNL::Random::addEntropy(randData, sizeof(randData));

   Address remoteAddress(argv[1]);
   Address sourceAddress(argc > 2 ? argv[2] : "IP:Any:0");

   Nonce clientNonce;
   clientNonce.getRandom();

   Socket sourceSocket(sourceAddress);

   PacketStream out;
   out.write(U8(NetInterface::ConnectChallengeRequest));
   clientNonce.write(&out);
   out.writeFlag(false);
   out.writeFlag(false);

   for(U32 tryCount = 0; tryCount < 5; tryCount++)
   {
      U32 time = Platform::getRealMilliseconds();
      out.sendto(sourceSocket, remoteAddress);
      for(;;)
      {
         PacketStream incoming;
         Address incomingAddress;
         if(incoming.recvfrom(sourceSocket, &incomingAddress) == NoError)
         {
            U8 packetType;
            Nonce theNonce;
            incoming.read(&packetType);
            theNonce.read(&incoming);
            if(packetType == NetInterface::ConnectChallengeResponse && theNonce == clientNonce)
            {
               printf("TNL Service is UP (pingtime = %d)\n", Platform::getRealMilliseconds() - time);
               return 0;
            }
         }
         Platform::sleep(1);
         if(Platform::getRealMilliseconds() - time > 1000)
            break;
      }
   }
   
   printf("TNL Service is DOWN\n");
   
   return 1;
}
Esempio n. 24
0
bool AskService::GetQuestionIDs(IAnswer *answerCB, char16* nickname, char16* password)
{
    if (!StartRequest(answerCB, AskService::EPS_GETQUESTIONIDS))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(12);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);

    return isOk && EndRequest();

}
Esempio n. 25
0
bool SnapUpService::GetCollections(IAnswer *answerCB, char16* nickname, char16* password)
{
    if (!StartRequest(answerCB, SnapUpService::EPS_GETCOLLECTIONS))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(25);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);

    return isOk && EndRequest();

}
Esempio n. 26
0
    void testVideoCaptureStream()
    {
        DebugL << "Starting" << endl;

        av::VideoCapture::Ptr capture = MediaFactory::instance().createVideoCapture(0);
        {
            PacketStream stream;
            stream.emitter += packetDelegate(this, &Tests::onVideoCaptureStreamFrame);
            stream.attachSource<av::VideoCapture>(capture, true);
            stream.start();

            std::puts("Press any key to continue...");
            std::getchar();
        }

        assert(capture->emitter.ndelegates() == 0);

        DebugL << "Complete" << endl;
    }
Esempio n. 27
0
void NetInterface::sendPunchPackets(NetConnection *conn)
{
   ConnectionParameters &theParams = conn->getConnectionParameters();
   PacketStream out;
   out.write(U8(Punch));

   if(theParams.mIsInitiator)
      theParams.mNonce.write(&out);
   else
      theParams.mServerNonce.write(&out);

   U32 encryptPos = out.getBytePosition();
   out.setBytePosition(encryptPos);

   if(theParams.mIsInitiator)
      theParams.mServerNonce.write(&out);
   else
   {
      theParams.mNonce.write(&out);
      if(out.writeFlag(mRequiresKeyExchange || (theParams.mRequestKeyExchange && !mPrivateKey.isNull())))
      {
         if(out.writeFlag(theParams.mRequestCertificate && !mCertificate.isNull()))
            out.write(mCertificate);
         else
            out.write(mPrivateKey->getPublicKey());
      }
   }
   SymmetricCipher theCipher(theParams.mArrangedSecret);
   out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);

   for(S32 i = 0; i < theParams.mPossibleAddresses.size(); i++)
   {
      out.sendto(mSocket, theParams.mPossibleAddresses[i]);

      TNLLogMessageV(LogNetInterface, ("Sending punch packet (%s, %s) to %s",
         ByteBuffer(theParams.mNonce.data, Nonce::NonceSize).encodeBase64()->getBuffer(),
         ByteBuffer(theParams.mServerNonce.data, Nonce::NonceSize).encodeBase64()->getBuffer(),
         theParams.mPossibleAddresses[i].toString()));
   }
   conn->mConnectSendCount++;
   conn->mConnectLastSendTime = getCurrentTime();
}
Esempio n. 28
0
bool AskService::CompleteQuestion(IAnswer *answerCB, char16* nickname, char16* password, char16* askQuestionID)
{
    if (!StartRequest(answerCB, AskService::EPS_COMPLETEQUESTION))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(8);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);
    isOk = isOk &&  str->WriteWString(askQuestionID);

    return isOk && EndRequest();

}
Esempio n. 29
0
bool AskService::SkipQuestion(IAnswer *answerCB, char16* nickname, char16* password, int32 questionID)
{
    if (!StartRequest(answerCB, AskService::EPS_SKIPQUESTION))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(15);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);
    isOk = isOk &&  str->WriteInt32(questionID);

    return isOk && EndRequest();

}
Esempio n. 30
0
bool AskService::GetResponse(IAnswer *answerCB, char16* nickname, char16* password, int32 questionID)
{
    if (!StartRequest(answerCB, AskService::EPS_GETRESPONSE))
    {
        return false;
    }

    PacketStream *str = pServer->GetStream();
    bool isOk = true;

    isOk = isOk && str->WriteInt32(13);//request id

  
    isOk = isOk &&  str->WriteWString(nickname);
    isOk = isOk &&  str->WriteWString(password);
    isOk = isOk &&  str->WriteInt32(questionID);

    return isOk && EndRequest();

}