Skip to content

Commit

Permalink
fix silent cxn fail if you successfully connect but only after a cxn …
Browse files Browse the repository at this point in the history
…failure
  • Loading branch information
yuxshao committed May 31, 2021
1 parent ac27271 commit 18d50a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
23 changes: 10 additions & 13 deletions src/network/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/network/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion todo
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18d50a4

Please sign in to comment.