diff --git a/src/network/Client.cpp b/src/network/Client.cpp index 82b66251..40e0d30d 100644 --- a/src/network/Client.cpp +++ b/src/network/Client.cpp @@ -15,7 +15,8 @@ Client::Client(QObject *parent) m_local(new LocalClientSession(this)), m_write_stream((QIODevice *)m_socket), m_read_stream((QIODevice *)m_socket), - m_received_hello(false) { + m_received_hello(false), + m_hello_username("") { connect(m_socket, &QTcpSocket::readyRead, this, &Client::tryToRead); connect(m_socket, &QTcpSocket::disconnected, this, &Client::handleDisconnect); connect(m_socket, &QTcpSocket::errorOccurred, @@ -33,6 +34,11 @@ Client::Client(QObject *parent) connect(m_local, &LocalClientSession::receivedAction, this, &Client::receivedAction); + connect(m_socket, &QTcpSocket::connected, [this]() { + qDebug() << "Sending hello to server"; + m_write_stream << ClientHello(m_hello_username); + }); + m_write_stream.setVersion(QDataStream::Qt_5_5); m_read_stream.setVersion(QDataStream::Qt_5_5); } @@ -54,17 +60,7 @@ HostAndPort Client::currentlyConnectedTo() { void Client::connectToServer(QString hostname, quint16 port, QString username) { m_local->disconnect(); m_socket->abort(); - - // Guarded on connection in case the connection fails. In the past not having - // this has caused me problems - QMetaObject::Connection *const conn = new QMetaObject::Connection; - *conn = connect(m_socket, &QTcpSocket::connected, [this, conn, username]() { - qDebug() << "Sending hello to server"; - m_write_stream << ClientHello(username); - disconnect(*conn); - delete conn; - }); - + m_hello_username = username; m_socket->connectToHost(hostname, port); } @@ -164,7 +160,8 @@ void Client::tryToStart() { if (!hello.isValid()) { qWarning("Invalid hello response. Disconnecting."); emit errorOccurred( - tr("Invalid hello response from server. Are you running the same version of ptcollab as the server?")); + tr("Invalid hello response from server. Are you running the same " + "version of ptcollab as the server?")); m_socket->disconnectFromHost(); return; } diff --git a/src/network/Client.h b/src/network/Client.h index 9bd4c86c..9abc54a2 100644 --- a/src/network/Client.h +++ b/src/network/Client.h @@ -33,6 +33,7 @@ class Client : public QObject { QDataStream m_write_stream, m_read_stream; bool m_received_hello; bool m_suppress_disconnect; + QString m_hello_username; qint64 m_uid; void tryToRead(); void tryToStart(); diff --git a/todo b/todo index 0e23a400..d7ad8578 100644 --- a/todo +++ b/todo @@ -449,9 +449,11 @@ playback 3. render volume option 4. dialog for copy options +5/31 +1. fix silent cxn fail if you connect after a connection failure + Todo by priority ---------------- - - connecting after getting connection refused causes desync via invalid variant index - show other's midi inputs if you're either following the or they're not playing - midi input: mute the unit regularly if you're recording, also record silence? Maybe idk - Unit view, at least for drums