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); }
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); } }