本文整理汇总了C++中PacketStream::sendto方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::sendto方法的具体用法?C++ PacketStream::sendto怎么用?C++ PacketStream::sendto使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketStream
的用法示例。
在下文中一共展示了PacketStream::sendto方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendConnectAccept
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());
}
示例2: sendConnectChallengeResponse
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);
}
示例3: disconnect
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);
}
}
示例4: handleQuery
static void handleQuery(Game *game, const Address &remoteAddress, Socket &socket, BitStream *stream)
{
TNLAssert(game->isServer(), "Expected this to be a server!");
Nonce nonce;
U32 clientIdentityToken;
nonce.read(stream);
stream->read(&clientIdentityToken);
if(clientIdentityToken == computeSimpleToken(nonce))
{
PacketStream queryResponse;
queryResponse.write(U8(GameNetInterface::QueryResponse));
nonce.write(&queryResponse);
queryResponse.writeStringTableEntry(game->getSettings()->getHostName());
queryResponse.writeStringTableEntry(game->getSettings()->getHostDescr());
queryResponse.write(game->getPlayerCount());
queryResponse.write(game->getMaxPlayers());
queryResponse.write(game->getRobotCount());
queryResponse.writeFlag(game->isDedicated());
queryResponse.writeFlag(game->isTestServer());
queryResponse.writeFlag(game->getSettings()->getServerPassword() != "");
queryResponse.write(game->getClientId()); // older 019 ignore this or won't read this
queryResponse.sendto(socket, remoteAddress);
}
}
示例5: main
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;
}
示例6: sendQuery
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);
}
示例7: sendPing
// 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);
}
示例8: sendConnectReject
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);
}
示例9: sendConnectReject
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);
}
示例10: sendConnectChallengeRequest
void NetInterface::sendConnectChallengeRequest(NetConnection *conn)
{
TNLLogMessageV(LogNetInterface, ("Sending Connect Challenge Request to %s", conn->getNetAddress().toString()));
PacketStream out;
out.write(U8(ConnectChallengeRequest));
ConnectionParameters ¶ms = conn->getConnectionParameters();
params.mNonce.write(&out);
out.writeFlag(params.mRequestKeyExchange);
out.writeFlag(params.mRequestCertificate);
conn->mConnectSendCount++;
conn->mConnectLastSendTime = getCurrentTime();
out.sendto(mSocket, conn->getNetAddress());
}
示例11: sendConnectRequest
void NetInterface::sendConnectRequest(NetConnection *conn)
{
PacketStream out;
ConnectionParameters &theParams = conn->getConnectionParameters();
const char *destDescr;
if(theParams.mIsLocal)
destDescr = "local in-process server";
else
destDescr = conn->getNetAddress().toString();
logprintf(LogConsumer::LogNetInterface, "Sending connect request to %s", destDescr);
out.write(U8(ConnectRequest));
theParams.mNonce.write(&out);
theParams.mServerNonce.write(&out);
out.write(theParams.mClientIdentity);
out.write(theParams.mPuzzleDifficulty);
out.write(theParams.mPuzzleSolution);
U32 encryptPos = 0;
if(out.writeFlag(theParams.mUsingCrypto))
{
out.write(theParams.mPrivateKey->getPublicKey());
encryptPos = out.getBytePosition();
out.setBytePosition(encryptPos);
out.write(SymmetricCipher::KeySize, theParams.mSymmetricKey);
}
out.writeFlag(theParams.mDebugObjectSizes);
out.write(conn->getInitialSendSequence());
out.writeString(conn->getClassName());
conn->writeConnectRequest(&out);
if(encryptPos)
{
// if we're using crypto on this connection,
// then write a hash of everything we wrote into the packet
// key. Then we'll symmetrically encrypt the packet from
// the end of the public key to the end of the signature.
SymmetricCipher theCipher(theParams.mSharedSecret);
out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);
}
conn->mConnectSendCount++;
conn->mConnectLastSendTime = getCurrentTime();
out.sendto(mSocket, conn->getNetAddress());
}
示例12: 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();
}
示例13: sendArrangedConnectRequest
void NetInterface::sendArrangedConnectRequest(NetConnection *conn)
{
TNLLogMessageV(LogNetInterface, ("Sending Arranged Connect Request"));
PacketStream out;
ConnectionParameters &theParams = conn->getConnectionParameters();
out.write(U8(ArrangedConnectRequest));
theParams.mNonce.write(&out);
U32 encryptPos = out.getBytePosition();
U32 innerEncryptPos = 0;
out.setBytePosition(encryptPos);
theParams.mServerNonce.write(&out);
if(out.writeFlag(theParams.mUsingCrypto))
{
out.write(theParams.mPrivateKey->getPublicKey());
innerEncryptPos = out.getBytePosition();
out.setBytePosition(innerEncryptPos);
out.write(SymmetricCipher::KeySize, theParams.mSymmetricKey);
}
out.writeFlag(theParams.mDebugObjectSizes);
out.write(conn->getInitialSendSequence());
conn->writeConnectRequest(&out);
if(innerEncryptPos)
{
SymmetricCipher theCipher(theParams.mSharedSecret);
out.hashAndEncrypt(NetConnection::MessageSignatureBytes, innerEncryptPos, &theCipher);
}
SymmetricCipher theCipher(theParams.mArrangedSecret);
out.hashAndEncrypt(NetConnection::MessageSignatureBytes, encryptPos, &theCipher);
conn->mConnectSendCount++;
conn->mConnectLastSendTime = getCurrentTime();
out.sendto(mSocket, conn->getNetAddress());
}
示例14: handlePing
static void handlePing(Game *game, const Address &remoteAddress, Socket &socket, BitStream *stream, S32 clientId)
{
TNLAssert(game->isServer(), "Expected this to be a server!");
Nonce clientNonce;
clientNonce.read(stream);
U32 protocolVersion;
stream->read(&protocolVersion);
if(protocolVersion != CS_PROTOCOL_VERSION) // Ignore pings from incompatible versions
return;
U32 clientIdentityToken = computeSimpleToken(clientNonce);
PacketStream pingResponse;
pingResponse.write(U8(GameNetInterface::PingResponse));
clientNonce.write(&pingResponse);
pingResponse.write(clientIdentityToken);
pingResponse.write(clientId); // older 019 ignore this or won't read this
pingResponse.sendto(socket, remoteAddress);
}