コード例 #1
0
ファイル: AuthSession.cpp プロジェクト: Joincheng/lithtech
WONStatus AuthSession::Encrypt(ByteBufferPtr &theMsg)
{
	mLastUseTime = time(NULL);

	if(mAuthType==AUTH_TYPE_NONE || mAuthType==AUTH_TYPE_PERSISTENT_NOCRYPT)
		return WS_Success;

	WriteBuffer aMsg(mLengthFieldSize);
	aMsg.AppendByte(12); // encrypted message

	WriteBuffer aSeqBuf;
	const char *aBuf = theMsg->data() + mLengthFieldSize;
	unsigned short aLen = theMsg->length() - mLengthFieldSize;

	if(mAuthType==AUTH_TYPE_SESSION)
	{
		aMsg.AppendShort(mId);
		aSeqBuf.AppendShort(++mOutSeq);
		aSeqBuf.AppendBytes(aBuf,aLen);
		aBuf = aSeqBuf.data();
		aLen = aSeqBuf.length();
	}

	ByteBufferPtr anEncrypt = mKey.Encrypt(aBuf,aLen);
	if(anEncrypt.get()==NULL)
		return WS_AuthSession_EncryptFailure;
	
	aMsg.AppendBytes(anEncrypt->data(),anEncrypt->length());
	theMsg = aMsg.ToByteBuffer();
	return WS_Success;
}
コード例 #2
0
WONStatus PeerAuthServer::GetComplete(WONStatus theStatus, ByteBufferPtr &theComplete)
{
	mState = STATE_NOT_STARTED; // reset state now
	
	WriteBuffer aComplete(mLengthFieldSize);
	aComplete.AppendLong(203);					// Auth peer to peer service
	aComplete.AppendLong(53);					// Complete

	if(theStatus!=WS_Success)
	{
		aComplete.AppendShort(WS_CommServ_InvalidParameters); // failure status
		aComplete.AppendShort(1); // num errors
		aComplete.AppendString(WONStatusToString(theStatus));
	}
	else
	{
		aComplete.AppendShort(WS_Success);
		WriteBuffer anEncryptBuf;
		anEncryptBuf.AppendShort(mSecretA.GetKeyLen());
		anEncryptBuf.AppendBytes(mSecretA.GetKey(),mSecretA.GetKeyLen());

			
		ByteBufferPtr anEncrypt = mClientCertificate->GetPubKey().Encrypt(anEncryptBuf.data(),anEncryptBuf.length());
		if(anEncrypt.get()==NULL)
			return WS_PeerAuthServer_FailedToEncryptWithClientPubKey;

		aComplete.AppendShort(anEncrypt->length());
		aComplete.AppendBytes(anEncrypt->data(),anEncrypt->length());
		mSession = new AuthSession(mAuthType, 0, mSecretB, mLengthFieldSize);
	}
	
	theComplete = aComplete.ToByteBuffer();
	return WS_Success;
}
コード例 #3
0
ファイル: mavlink_serial.cpp プロジェクト: byu-magicc/fcu_io2
void MavlinkSerial::async_write_end(const boost::system::error_code &error, std::size_t bytes_transferred)
{
  if (error)
  {
    close();
    return;
  }

  mutex_lock lock(mutex_);
  if (write_queue_.empty())
  {
    write_in_progress_ = false;
    return;
  }

  WriteBuffer *buffer = write_queue_.front();
  buffer->pos += bytes_transferred;
  if (buffer->nbytes() == 0)
  {
    write_queue_.pop_front();
    delete buffer;
  }

  if (write_queue_.empty())
    write_in_progress_ = false;
  else
    do_async_write(false);
}
コード例 #4
0
ファイル: AddEntityOp.cpp プロジェクト: Joincheng/lithtech
void AddServiceOp::SetNetAddrPort(unsigned short thePort)
{
	WriteBuffer theBuf;
	theBuf.AppendShort( htons(thePort) );

	SetNetAddr(theBuf.ToByteBuffer());
}
コード例 #5
0
void StagingLogic::SendReadyRequest(bool isReady)
{
	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_ReadyRequest);
	aMsg.AppendBool(isReady);
	SendGameMessageToCaptain(aMsg.ToByteBuffer());
}
コード例 #6
0
ファイル: Buffer.cpp プロジェクト: Asele/nupic.core
 NTA_Int32 staticWriteByte(NTA_WriteBufferHandle handle, NTA_Byte value)
 {
   NTA_CHECK(handle != NULL);
   
   WriteBuffer * wb = reinterpret_cast<WriteBuffer *>(handle);
   return wb->write(value);
 }
コード例 #7
0
ファイル: Buffer.cpp プロジェクト: Asele/nupic.core
 const Byte * staticGetData(NTA_WriteBufferHandle handle)
 {
   NTA_CHECK(handle != NULL);
   
   WriteBuffer * wb = reinterpret_cast<WriteBuffer *>(handle);
   return wb->getData();
 }
コード例 #8
0
ファイル: Buffer.cpp プロジェクト: Asele/nupic.core
 NTA_Size staticWriteBufferGetSize(NTA_WriteBufferHandle handle)
 {
   NTA_CHECK(handle != NULL);
   
   WriteBuffer * wb = reinterpret_cast<WriteBuffer *>(handle);
   return wb->getSize();
 }
コード例 #9
0
WONStatus PeerAuthServer::GetChallenge1(ByteBufferPtr &theChallenge)
{
	WriteBuffer aChallenge(mLengthFieldSize);

	aChallenge.AppendLong(203);					// Auth peer to peer service
	aChallenge.AppendLong(51);					// Challenge1

	mSecretB.Create(8);
	WriteBuffer aChallengeSecret;
	aChallengeSecret.AppendShort(mSecretB.GetKeyLen());
	aChallengeSecret.AppendBytes(mSecretB.GetKey(),mSecretB.GetKeyLen());

	ByteBufferPtr anEncrypt = mClientCertificate->GetPubKey().Encrypt(aChallengeSecret.data(),aChallengeSecret.length());
	if(anEncrypt.get()==NULL)
		return WS_PeerAuthServer_FailedToEncryptWithClientPubKey;

	aChallenge.AppendShort(anEncrypt->length());
	aChallenge.AppendBytes(anEncrypt->data(),anEncrypt->length());

	if(mUseAuth2)
		aChallenge.AppendBuffer(mPeerData->GetCertificate2()->GetRawBuf(),2);
	else
		aChallenge.AppendBuffer(mPeerData->GetCertificate()->GetRawBuf(),2);

	theChallenge = aChallenge.ToByteBuffer();
	return WS_Success;
}
コード例 #10
0
ファイル: ColladaManager.cpp プロジェクト: 2asoft/0ad
	bool Convert(const VfsPath& daeFilename, const VfsPath& pmdFilename, CColladaManager::FileType type)
	{
		// To avoid always loading the DLL when it's usually not going to be
		// used (and to do the same on Linux where delay-loading won't help),
		// and to avoid compile-time dependencies (because it's a minor pain
		// to get all the right libraries to build the COLLADA DLL), we load
		// it dynamically when it is required, instead of using the exported
		// functions and binding at link-time.
		if (!dll.IsLoaded())
		{
			if (!TryLoadDLL())
				return false;

			if (!LoadSkeletonDefinitions())
			{
				dll.Unload(); // Error should have been logged already
				return false;
			}
		}

		// Set the filename for the logger to report
		set_logger(ColladaLog, const_cast<void*>(static_cast<const void*>(&daeFilename)));

		// We need to null-terminate the buffer, so do it (possibly inefficiently)
		// by converting to a CStr
		CStr daeData;
		{
			CVFSFile daeFile;
			if (daeFile.Load(m_VFS, daeFilename) != PSRETURN_OK)
				return false;
			daeData = daeFile.GetAsString();
		}

		// Do the conversion into a memory buffer
		// We need to check the result, as archive builder needs to know if the source dae
		//	was sucessfully converted to .pmd/psa
		int result = -1;
		WriteBuffer writeBuffer;
		switch (type)
		{
		case CColladaManager::PMD:
			result = convert_dae_to_pmd(daeData.c_str(), ColladaOutput, &writeBuffer);
			break;
		case CColladaManager::PSA:
			result = convert_dae_to_psa(daeData.c_str(), ColladaOutput, &writeBuffer);
			break;
		}

		// don't create zero-length files (as happens in test_invalid_dae when
		// we deliberately pass invalid XML data) because the VFS caching
		// logic warns when asked to load such.
		if (writeBuffer.Size())
		{
			Status ret = m_VFS->CreateFile(pmdFilename, writeBuffer.Data(), writeBuffer.Size());
			ENSURE(ret == INFO::OK);
		}

		return (result == 0);
	}
コード例 #11
0
ByteBufferPtr LobbyGame::GetJoinGameRequest()
{
	WriteBuffer aBuf;
	aBuf.AppendByte(LobbyGameMsg_JoinRequest);
	aBuf.AppendShort(mPing);
	GetJoinGameRequestHook(aBuf);
	return aBuf.ToByteBuffer();
}
コード例 #12
0
ファイル: Buffer.cpp プロジェクト: Asele/nupic.core
 NTA_Int32 staticWriteString(NTA_WriteBufferHandle handle, const NTA_Byte * value, NTA_Size size)
 {
   NTA_CHECK(handle != NULL);
   NTA_CHECK(value != NULL);
   
   WriteBuffer * wb = reinterpret_cast<WriteBuffer *>(handle);
   return wb->writeString(value, size);
 }
コード例 #13
0
void DataTypeFixedString::serializeBinary(const Field & field, WriteBuffer & ostr) const
{
	const String & s = get<const String &>(field);
	ostr.write(s.data(), std::min(s.size(), n));
	if (s.size() < n)
		for (size_t i = s.size(); i < n; ++i)
			ostr.write(0);
}
コード例 #14
0
void StagingLogic::SendDissolveGame()
{
	if(!IAmCaptain())
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_DissolveGame);
	BroadcastGameMessage(aMsg.ToByteBuffer());
}
コード例 #15
0
ファイル: Buffer.cpp プロジェクト: Asele/nupic.core
 NTA_Int32 staticWriteReal64Array(NTA_WriteBufferHandle handle, const NTA_Real64 * value, NTA_Size size)
 {
   NTA_CHECK(handle != NULL);
   NTA_CHECK(value != NULL);
   NTA_CHECK(size > 0);
   
   WriteBuffer * wb = reinterpret_cast<WriteBuffer *>(handle);
   return wb->write(value, size);
 }
コード例 #16
0
ファイル: connection.cpp プロジェクト: Genilson23/emu
void Connection::queueSendTo(const boost::asio::ip::udp::endpoint &endpoint, WriteBuffer &writeBuffer)
{
    socket_.async_send_to(boost::asio::buffer(&writeBuffer.getPayload()[0], writeBuffer.getPayload().getSize()),
                          endpoint,
                          strand_.wrap(std::bind(&Connection::sendToHandler,
                                       this,
                                       endpoint,
                                       std::placeholders::_1,
                                       std::placeholders::_2)));
}
コード例 #17
0
ByteBufferPtr LobbyGame::HandleJoinGameRequest(ReadBuffer &theMsg, LobbyClient *theClient)
{
	WriteBuffer aBuf;
	aBuf.AppendByte(LobbyGameMsg_JoinReply);
	aBuf.AppendShort(0); // reserve space for status

	short aStatus  = HandleJoinGameRequest(theMsg,theClient,aBuf);
	aBuf.SetShort(1,aStatus);

	return aBuf.ToByteBuffer();
}
コード例 #18
0
ファイル: player.cpp プロジェクト: popkc/FreeSanGuoSha
unique_ptr<Card> PlayerServer::judge()
{
	auto card = move(GAME->drawCards(1).front());
	WriteBuffer wb;
	wb << card->id;
	GAME->notify(100, Notify_JudgeStart, wb);
	TRIEV(t_Judge, &card);
	wb.clear();
	wb << card->id;
	GAME->notify(100, Notify_JudgeEnd, wb);
	return card;
}
コード例 #19
0
SuccinctVector::SuccinctVector(WriteBuffer& buffer, usint block_bytes, usint universe_size) :
  BitVector()
{
  if(buffer.ownsData())
  {
    this->initializeFrom(buffer.stealData(), block_bytes, universe_size);
  }
  else
  {
    this->initializeUsing(buffer.rawData(), block_bytes, universe_size);
  }
}
コード例 #20
0
ByteBufferPtr ElGamal::Sign(const void* theMessage, int theMessageLen) const
{
    if(!IsPrivate())
        return NULL;

    MD5Digest anMD5;
    anMD5.update(theMessage, theMessageLen);
    RawBuffer aDigest = anMD5.digest();

    BigInteger M;
    if(!EncodeDigest(aDigest,M))
        return NULL;

    BigInteger ab[2];

    if(!BogusSign(M,ab))
        return NULL;

    WriteBuffer aSignature;

    int qLen = q.byteLength();
    RawBuffer a,b;
    ab[0].toBinary(a);
    ab[1].toBinary(b);

    if(a.length()==qLen)
        aSignature.AppendBytes(a.data(),a.length());
    else if(a.length()>qLen)
        aSignature.AppendBytes(a.data()+a.length()-qLen,qLen);
    else
    {
        for(int i=a.length(); i<qLen; i++)
            aSignature.AppendByte(0);

        aSignature.AppendBytes(a.data(),a.length());
    }


    if(b.length()==qLen)
        aSignature.AppendBytes(b.data(),b.length());
    else if(b.length()>qLen)
        aSignature.AppendBytes(b.data()+b.length()-qLen,qLen);
    else
    {
        for(int i=b.length(); i<qLen; i++)
            aSignature.AppendByte(0);

        aSignature.AppendBytes(b.data(),b.length());
    }

    return aSignature.ToByteBuffer();
}
コード例 #21
0
void StagingLogic::NotifyPingChange(LobbyGame *theGame)
{
	if(mGame.get()==NULL || IAmCaptain())
		return;
	
	if(!theGame->IsSameGame(mGame))
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_PingChangedRequest);
	aMsg.AppendShort(theGame->GetPing());
	SendGameMessageToCaptain(aMsg.ToByteBuffer());
}
コード例 #22
0
void StagingLogic::KickClient(LobbyClient *theClient, bool isBan)
{
	if(theClient==NULL || mGame.get()==NULL || !IAmCaptain())
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_ClientKicked);
	aMsg.AppendShort(theClient->GetClientId());
	aMsg.AppendBool(isBan);
	BroadcastGameMessage(aMsg.ToByteBuffer());

	LobbyStagingPrv::NetKickClient(theClient,isBan);
}
コード例 #23
0
void RegionImpl::getParameterArray(const std::string& name, Int64 index, Array & array)
{
  WriteBuffer wb;
  getParameterFromBuffer(name, index, wb);
  ReadBuffer rb(wb.getData(), wb.getSize(), false /* copy */);
  size_t count = array.getCount();
  void *buffer = array.getBuffer();

  for (size_t i = 0; i < count; i++)
  {
    int rc;
    switch (array.getType())
    {

    case NTA_BasicType_Byte:
      rc = rb.read(((Byte*)buffer)[i]);
      break;
    case NTA_BasicType_Int32:
      rc = rb.read(((Int32*)buffer)[i]);
      break;
    case NTA_BasicType_UInt32:
      rc = rb.read(((UInt32*)buffer)[i]);
      break;
    case NTA_BasicType_Int64:
      rc = rb.read(((Int64*)buffer)[i]);
      break;
    case NTA_BasicType_UInt64:
      rc = rb.read(((UInt64*)buffer)[i]);
      break;
    case NTA_BasicType_Real32:
      rc = rb.read(((Real32*)buffer)[i]);
      break;
    case NTA_BasicType_Real64:
      rc = rb.read(((Real64*)buffer)[i]);
      break;
    default:
      NTA_THROW << "Unsupported basic type " << BasicType::getName(array.getType())
                << " in getParameterArray for parameter " << name;
      break;
    }

    if (rc != 0)
    {
      NTA_THROW << "getParameterArray -- failure to get parameter '"
                << name << "' on node of type " << getType();
    }
  }
  return;
}
コード例 #24
0
void UpdateVersionOp::RunHook()
{
	SetMessageType(DBProxyMsgType::DBProxyPatchServer);
	SetSubMessageType(mMsgType);

	// Pack the message data
	WriteBuffer requestData;
	requestData.AppendString(mProductName);

	mVersionData->WriteToBuffer(requestData, VersionData::WriteFlag_AppendDescripURL | VersionData::WriteFlag_AppendState);
	
	// Pack and call base class implementation
	SetProxyRequestData(requestData.ToByteBuffer());
	DBProxyOp::RunHook();
}
コード例 #25
0
void StagingLogic::HandleReadyRequest(ReadBuffer &theMsg, LobbyClient *theSender)
{
	if(!IAmCaptain() || !theSender->IsPlayer())
		return;

	bool isReady = theMsg.ReadBool();
	if(theSender->IsPlayerReady()==isReady) // no change needed
		return;

	WriteBuffer aMsg;
	aMsg.AppendByte(LobbyGameMsg_PlayerReady);
	aMsg.AppendShort(theSender->GetClientId());
	aMsg.AppendBool(isReady);
	BroadcastGameMessage(aMsg.ToByteBuffer());
}
コード例 #26
0
void QueryBannedKeyOp::RunHook()
{
	SetMessageType(DBProxyAccount);
	SetSubMessageType(MSGTYPE);
	mKeyList.clear();

	// Stores the message data
	WriteBuffer requestData;
	requestData.AppendWString(mCommunityName);
	requestData.AppendString(mProductName);

	// Copy buffer into the class
	SetProxyRequestData(requestData.ToByteBuffer());

	DBProxyOp::RunHook();
}
コード例 #27
0
void RemoteBlockReader::sendStatus() {
    ClientReadStatusProto status;

    if (verify) {
        status.set_status(Status::DT_PROTO_CHECKSUM_OK);
    } else {
        status.set_status(Status::DT_PROTO_SUCCESS);
    }

    WriteBuffer buffer;
    int size = status.ByteSize();
    buffer.writeVarint32(size);
    status.SerializeToArray(buffer.alloc(size), size);
    sock->writeFully(buffer.getBuffer(0), buffer.getDataSize(0), writeTimeout);
    sentStatus = true;
}
コード例 #28
0
ファイル: CConsole.cpp プロジェクト: 2asoft/0ad
void CConsole::SaveHistory()
{
	WriteBuffer buffer;
	const int linesToSkip = (int)m_deqBufHistory.size() - m_MaxHistoryLines;
	std::deque<std::wstring>::reverse_iterator it = m_deqBufHistory.rbegin();
	if(linesToSkip > 0)
		std::advance(it, linesToSkip);
	for (; it != m_deqBufHistory.rend(); ++it)
	{
		CStr8 line = CStrW(*it).ToUTF8();
		buffer.Append(line.data(), line.length());
		static const char newline = '\n';
		buffer.Append(&newline, 1);
	}
	g_VFS->CreateFile(m_sHistoryFile, buffer.Data(), buffer.Size());
}
コード例 #29
0
void TcpSocketRxComponent::writeOutput()
{
  std::size_t size;

  try
  {
    if(!connected_)
    {
      //Listen for connection if necessary
      acceptor_->accept(*socket_);
      connected_ = true;
    }

    //Get data from socket
    //size = socket_->receive(boost::asio::buffer(d_buffer, x_bufferSize));
    size = boost::asio::read(*socket_, boost::asio::buffer(buffer_, bufferSize_x));
  }
  catch(boost::system::system_error &e)
  {
    LOG(LERROR) << "Error listening on socket: " << e.what();
    boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
    return;
  }

  //Check that we've an integer number of data types in the datagram
  float f = size/(float)sizeof(T);
  float intpart, rem;
  rem = modf(f, &intpart);
  if(rem != 0)
  {
    LOG(LERROR) << "Did not receive an integer number of elements. Input size = " << size;
  }
  int numT = (int)intpart;

  //Get the output buffer
  WriteBuffer< T >* outBuf = castToType<T>(outputBuffers[0]);
  DataSet<T>* writeDataSet = NULL;
  outBuf->getWriteData(writeDataSet, numT);

  //Copy data into output
  T* bufT = (T*)buffer_;
  copy(bufT, bufT+numT, writeDataSet->data.begin());

  //Release the buffer
  outBuf->releaseWriteData(writeDataSet);
}
コード例 #30
0
ファイル: AuthContext.cpp プロジェクト: Joincheng/lithtech
void AuthContext::AppendLoginSecrets(WriteBuffer &theBuf) 
{
	AutoCrit aCrit(mDataCrit);
	SecretList::iterator anItr = mSecretList.begin();

	unsigned long aLenPos = theBuf.length();
	unsigned char aNumSecrets = 0;
	theBuf.SkipBytes(1);
	while(anItr!=mSecretList.end() && aNumSecrets<256)
	{
		theBuf.AppendBytes(anItr->mSecret->data(), anItr->mSecret->length());
		aNumSecrets++;
		++anItr;
	}

	theBuf.SetByte(aLenPos,aNumSecrets);
}