本文整理汇总了C++中PacketStream::getBytePosition方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::getBytePosition方法的具体用法?C++ PacketStream::getBytePosition怎么用?C++ PacketStream::getBytePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketStream
的用法示例。
在下文中一共展示了PacketStream::getBytePosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendPunchPackets
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();
}
示例2: disconnect
void NetInterface::disconnect(NetConnection *conn, NetConnection::TerminationReason reason, const char *reasonString)
{
// If we're still connecting...
if(conn->getConnectionState() == NetConnection::NotConnected ||
conn->getConnectionState() == NetConnection::AwaitingChallengeResponse ||
conn->getConnectionState() == NetConnection::AwaitingConnectResponse ||
conn->getConnectionState() == NetConnection::SendingPunchPackets ||
conn->getConnectionState() == NetConnection::ComputingPuzzleSolution)
{
conn->onConnectTerminated(reason, reasonString);
removePendingConnection(conn);
}
// If we're already connected
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.writeEnum(reason, NetConnection::TerminationReasons);
out.writeString(reasonString);
if(theParams.mUsingCrypto)
{
SymmetricCipher theCipher(theParams.mSharedSecret);
out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);
}
out.sendto(mSocket, conn->getNetAddress());
}
removeConnection(conn);
}
}
示例3: sendConnectAccept
void NetInterface::sendConnectAccept(NetConnection *conn)
{
TNLLogMessageV(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());
}