summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Schneider2014-11-28 14:54:54 +0100
committerManuel Schneider2014-11-28 14:54:54 +0100
commit303dfd7c1798f4aa211653d1bc66a9998cbe6ceb (patch)
treec3c105a29bdac1ade88a06e7ae264028dbab1150
parentRemove redundant flags (diff)
downloadpvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.tar.gz
pvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.tar.xz
pvs2-303dfd7c1798f4aa211653d1bc66a9998cbe6ceb.zip
Reset debug timeouts, fix autoconnect, remove magic numbers
-rw-r--r--src/client/connectwindow/connectwindow.cpp10
-rw-r--r--src/client/connectwindow/connectwindow.h2
-rw-r--r--src/client/net/serverconnection.cpp7
-rw-r--r--src/client/net/serverconnection.h3
-rw-r--r--src/client/net/serverdiscovery.cpp13
-rw-r--r--src/client/net/serverdiscovery.h11
-rw-r--r--src/server/net/client.cpp3
7 files changed, 27 insertions, 22 deletions
diff --git a/src/client/connectwindow/connectwindow.cpp b/src/client/connectwindow/connectwindow.cpp
index 6f75e29..b84f22c 100644
--- a/src/client/connectwindow/connectwindow.cpp
+++ b/src/client/connectwindow/connectwindow.cpp
@@ -42,8 +42,8 @@ ConnectWindow::ConnectWindow(QWidget *parent) : QWidget(parent)
connect(_ui->btn_hide, SIGNAL(clicked()), this, SLOT(onBtnHide()));
// React on discovery signal
- connect(&_serverDiscovery, SIGNAL(serverDetected(QString,quint16,QByteArray,QByteArray)),
- this, SLOT(onServerDetected(QString,quint16,QByteArray,QByteArray)));
+ connect(&_serverDiscovery, SIGNAL(serverDetected(QString,quint16,QByteArray,QByteArray,bool)),
+ this, SLOT(onServerDetected(QString,quint16,QByteArray,QByteArray,bool)));
this->updateUserInterface();
}
@@ -220,9 +220,9 @@ void ConnectWindow::onBtnHide()
* @param sessionName
* @param certHash
*/
-void ConnectWindow::onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash)
+void ConnectWindow::onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect)
{
- _connection = new ServerConnection(host, port, sessionName, certHash);
+ _connection = new ServerConnection(host, port, sessionName, certHash, autoConnect);
connect(_connection, SIGNAL(stateChange(ConnectWindow::ConnectionState)), this, SLOT(onConnectionStateChange(ConnectWindow::ConnectionState)));
connect(_connection, SIGNAL(destroyed(QObject*)), this, SLOT(onConnectionClosed(QObject*)));
connect(_connection, SIGNAL(disconnected()), this, SLOT(onConnectionDisconnected()));
@@ -235,7 +235,6 @@ void ConnectWindow::onServerDetected(const QString& host, const quint16 port, co
*/
void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state)
{
- qDebug() << "STATE!"<< state;
bool reset = (_state == Scanning);
if (state == InvalidSslHash)
++_hashSslErrorCount;
@@ -244,7 +243,6 @@ void ConnectWindow::onConnectionStateChange(ConnectWindow::ConnectionState state
this->updateUserInterface();
if (reset) {
- qDebug() << "RESET!!"<< state;
_state = Scanning;
}
if (state == Connected)
diff --git a/src/client/connectwindow/connectwindow.h b/src/client/connectwindow/connectwindow.h
index 92d0a4c..ab59e00 100644
--- a/src/client/connectwindow/connectwindow.h
+++ b/src/client/connectwindow/connectwindow.h
@@ -82,7 +82,7 @@ protected slots:
void onConnectionClosed(QObject* connection);
void onConnectionDisconnected();
// void onUdpReadyRead();
- void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash);
+ void onServerDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
signals:
void disconnect();
diff --git a/src/client/net/serverconnection.cpp b/src/client/net/serverconnection.cpp
index 7954c34..46cba79 100644
--- a/src/client/net/serverconnection.cpp
+++ b/src/client/net/serverconnection.cpp
@@ -18,8 +18,8 @@
#define CHALLENGE_LEN 20
-ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash) :
- QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash)
+ServerConnection::ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect) :
+ QObject(NULL), _timerDelete(0), _jpegQuality(80), _authed(0), _sessionName(sessionName), _certHash(certHash), _autoConnect(autoConnect)
{
_socket = new QSslSocket();
_blank = new BlankScreen();
@@ -132,7 +132,8 @@ void ServerConnection::handleMsg()
}
// Check challenge response
QByteArray serverhash(_fromServer.getFieldBytes(_HASH));
- if (serverhash != genSha1(&_sessionName, &_myChallenge))
+ if (serverhash != genSha1(&_sessionName, &_myChallenge)
+ && !_autoConnect)
{
qDebug("invalid. STOP.");
emit stateChange(ConnectWindow::InvalidSslHash);
diff --git a/src/client/net/serverconnection.h b/src/client/net/serverconnection.h
index a45d434..6d53c52 100644
--- a/src/client/net/serverconnection.h
+++ b/src/client/net/serverconnection.h
@@ -17,6 +17,7 @@ private:
int _timerId, _timerDelete, _timerConnectionCheck;
int _jpegQuality;
int _authed;
+ bool _autoConnect;
qint64 _lastData;
NetworkMessage _fromServer, _toServer;
@@ -29,7 +30,7 @@ private:
void handleMsg();
public:
- ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash);
+ ServerConnection(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void disconnectFromServer();
~ServerConnection();
const inline bool isConnected() const
diff --git a/src/client/net/serverdiscovery.cpp b/src/client/net/serverdiscovery.cpp
index 0062561..5dba327 100644
--- a/src/client/net/serverdiscovery.cpp
+++ b/src/client/net/serverdiscovery.cpp
@@ -10,7 +10,10 @@
/***************************************************************************//**
* Ctor
*/
-ServerDiscovery::ServerDiscovery(QObject *parent) : QObject(parent)
+ServerDiscovery::ServerDiscovery(QObject *parent)
+ : QObject(parent),
+ _minDiscoveryInterval(500),
+ _maxDiscoveryInterval(5000)
{
_hashErrorCount = 0;
_ipErrorCount = 0;
@@ -29,7 +32,7 @@ ServerDiscovery::ServerDiscovery(QObject *parent) : QObject(parent)
connect(&_discoverySocket, SIGNAL(readyRead()), this, SLOT(onUdpReadyRead()));
/* Setup the discovery timer */
- _discoveryTimer.setInterval(500);
+ _discoveryTimer.setInterval(_minDiscoveryInterval);
_discoveryTimer.setSingleShot(true);
//
connect(&_discoveryTimer, SIGNAL(timeout()), this, SLOT(doDiscovery()));
@@ -65,7 +68,7 @@ void ServerDiscovery::start(const QByteArray& sessionName, QString mgrIP)
_hashErrorCount = _ipErrorCount = 0;
// reset anbd start the discovery timer
- _discoveryTimer.setInterval(500);
+ _discoveryTimer.setInterval(_minDiscoveryInterval);
_discoveryTimer.start();
}
@@ -131,7 +134,7 @@ void ServerDiscovery::doDiscovery()
}
// Start the timer again with a larger interval
- if (_discoveryTimer.interval() < 5000)
+ if (_discoveryTimer.interval() < _maxDiscoveryInterval)
_discoveryTimer.setInterval(_discoveryTimer.interval() * 2);
_discoveryTimer.start();
}
@@ -189,7 +192,7 @@ void ServerDiscovery::onUdpReadyRead()
<< addr.toString() + ":" + QString::fromUtf8(port) + "/" + _nameBytes;
// Tell that a server hs been found
- emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert);
+ emit serverDetected(addr.toString(), (quint16)QString::fromUtf8(port).toInt(), _nameBytes, cert, (_mgrIP == addr));
// Stop the discovery
this->stop();
diff --git a/src/client/net/serverdiscovery.h b/src/client/net/serverdiscovery.h
index fee9fd0..a41c946 100644
--- a/src/client/net/serverdiscovery.h
+++ b/src/client/net/serverdiscovery.h
@@ -24,9 +24,11 @@ class ServerDiscovery : public QObject
inline bool isActive(){ return _discoveryTimer.isActive(); }
private:
- QTimer _discoveryTimer;
- int _hashErrorCount;
- int _ipErrorCount;
+ QTimer _discoveryTimer;
+ const int _minDiscoveryInterval;
+ const int _maxDiscoveryInterval;
+ int _hashErrorCount;
+ int _ipErrorCount;
QByteArray _nameBytes;
QByteArray _salt2;
QUdpSocket _discoverySocket;
@@ -37,9 +39,8 @@ class ServerDiscovery : public QObject
static const int UDPBUFSIZ = 9000;
static const int SALT_LEN = 18;
-public:
signals:
- void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash);
+ void serverDetected(const QString& host, const quint16 port, const QByteArray& sessionName, const QByteArray& certHash, bool autoConnect);
void error(ErrorType e, int count);
public slots:
diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp
index f575196..433d967 100644
--- a/src/server/net/client.cpp
+++ b/src/server/net/client.cpp
@@ -252,7 +252,8 @@ void Client::handleMsg()
{
QByteArray hash(_fromClient.getFieldBytes(_HASH));
QByteArray challenge(_fromClient.getFieldBytes(_CHALLENGE));
- if (genSha1(&Global::sessionNameArray(), &_challenge) != hash)
+ if (genSha1(&Global::sessionNameArray(), &_challenge) != hash
+ && !(Global::getRooms()[Global::getCurrentRoom()].contains(_socket->peerAddress().toString())))
{ // Challenge reply is invalid, drop client
NetworkMessage msgErr;
msgErr.buildErrorMessage("Challenge reply invalid.");