From 494727e1e5f0e459153e8845168545ad4a72e598 Mon Sep 17 00:00:00 2001 From: Björn Hagemeister Date: Mon, 26 May 2014 18:34:36 +0200 Subject: Several changes: Fixed segmentaion fault, which occured after streaming to all clients. Added sessionName as command line argument to client, so that it connects immediatly after running to given sessionName. If pvsclient shows connected status also display IP-Adress of the running pvsmanager. --- src/client/connectwindow/connectwindow.cpp | 32 +++++++++++++++++++++--------- src/client/connectwindow/connectwindow.h | 3 ++- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'src/client/connectwindow') diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp index 4e92570..c8f7efd 100644 --- a/src/client/connectwindow/connectwindow.cpp +++ b/src/client/connectwindow/connectwindow.cpp @@ -97,7 +97,7 @@ void ConnectWindow::updateState() { _ui->btn_connection->setEnabled(true); _ui->btn_connection->setText(tr("&Disconnect")); - _ui->lblStatus->setText(tr("Connected.")); + _ui->lblStatus->setText(tr("Connected to %1").arg(_connection->getPeerAdress())); _ui->lineEditName->setEnabled(false); _ui->stackedWidget->setCurrentIndex(1); return; @@ -175,7 +175,7 @@ void ConnectWindow::timerEvent(QTimerEvent* event) _salt2[i] = qrand() & 0xff; } _packet.reset(); - _packet.setField(_HASH, genSha1(&_nameBytes, &salt1, &iplist)); + _packet.setField(_HASH, genSha1(&_sessionNameBytes, &salt1, &iplist)); _packet.setField(_SALT1, salt1); _packet.setField(_SALT2, _salt2); _packet.setField(_IPLIST, iplist); @@ -227,6 +227,24 @@ void ConnectWindow::showEvent(QShowEvent* event) _ui->lineEditName->setFocus(); } +/** + * Public function connect to session. + * Check if currently connected to server, + * if not --> connect to given sessionName. + * @param sessionName + */ +void ConnectWindow::connectToSession(const QByteArray sessionName) +{ + if (_connected || _state != Idle) + return; + + _discoveryInterval = 800; + _sessionNameBytes = sessionName; + _timerDiscover = startTimer(_discoveryInterval); + _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0; + this->setState(Scanning); +} + /* * Slots */ @@ -255,11 +273,7 @@ void ConnectWindow::onBtnConnection() else { // Connect (scan for session) - _discoveryInterval = 800; - _nameBytes = _ui->lineEditName->text().toUtf8(); - _timerDiscover = startTimer(_discoveryInterval); - _hashErrorCount = _hashSslErrorCount = _certErrorCount = _ipErrorCount = 0; - this->setState(Scanning); + connectToSession(_ui->lineEditName->text().toUtf8()); } } @@ -303,7 +317,7 @@ void ConnectWindow::onUdpReadyRead() continue; } // If so, check if the submitted hash seems valid - if (genSha1(&_nameBytes, &_salt2, &iplist, &port, &cert) != hash) + if (genSha1(&_sessionNameBytes, &_salt2, &iplist, &port, &cert) != hash) { // did not match local session name, or other data was spoofed ++_hashErrorCount; @@ -312,7 +326,7 @@ void ConnectWindow::onUdpReadyRead() continue; } // Otherwise it's a valid reply, try to connect - _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert); + _connection = new ServerConnection(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _sessionNameBytes, cert); connect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState))); connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*))); } diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h index 299a339..9319e45 100644 --- a/src/client/connectwindow/connectwindow.h +++ b/src/client/connectwindow/connectwindow.h @@ -63,7 +63,7 @@ private: int _hashErrorCount, _hashSslErrorCount, _certErrorCount, _ipErrorCount; int _discoveryInterval; - QByteArray _nameBytes; + QByteArray _sessionNameBytes; QByteArray _salt2; QUdpSocket _discoverySocket; NetworkMessage _packet; @@ -76,6 +76,7 @@ public: virtual ~ConnectWindow(); void setConnected(const bool connected); + void connectToSession(const QByteArray sessionName); protected: /* -- cgit v1.2.3-55-g7522