From 9f479b8f76238a03bce5d13aee14efd34e659c6e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 30 Oct 2022 20:34:23 +0100 Subject: Clean up and modernize code - static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use and , but specific includes instead --- src/server/net/client.cpp | 52 +++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'src/server/net/client.cpp') diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index 977eb84..08dfc9a 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -9,46 +9,46 @@ #include "../serverapp/serverapp.h" #include "../../shared/settings.h" #include "../../shared/util.h" + #include #include #include +#include +#include #define CHALLENGE_LEN 20 int Client::_clientIdCounter = 0; -Client::Client(QTcpSocket* socket) : _socket(socket) +Client::Client(QTcpSocket* socket) + : _socket(socket) { assert(socket != nullptr); - _authed = 0; - _projectionSource = 0; _desiredSource = NO_SOURCE; - _isActiveVncClient = false; - _vncPort = 0; - _isTutor = false; - _locked = false; - _wantsAttention = false; - + _socket->setParent(this); _id = ++_clientIdCounter; //_ip = _socket->peerAddress().toString(); qDebug("*** Client %s created.", qPrintable(_socket->peerAddress().toString())); // Connect important signals - connect(_socket, SIGNAL(disconnected()), - this, SLOT(disconnect())); - connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), - this, SLOT(disconnect())); - connect(_socket, SIGNAL(sslErrors(const QList &)), - this, SLOT(disconnect())); - connect(_socket, SIGNAL(readyRead()), - this, SLOT(onDataArrival())); + connect(_socket, &QTcpSocket::disconnected, + this, &Client::disconnect); + connect(_socket, &QTcpSocket::errorOccurred, + this, &Client::disconnect); + auto *ssl = qobject_cast(_socket); + if (ssl != nullptr) { + connect(ssl, QOverload &>::of(&QSslSocket::sslErrors), + this, &Client::disconnect); + } + connect(_socket, &QTcpSocket::readyRead, + this, &Client::onDataArrival); // Send challenge _challenge.resize(CHALLENGE_LEN); for (int i = 0; i < CHALLENGE_LEN; ++i) { - _challenge[i] = char(qrand() & 0xff); + _challenge[i] = char(slxrand() & 0xff); } - NetworkMessage msgChlng; - msgChlng.setField(_ID, _CHALLENGE); - msgChlng.setField(_CHALLENGE, _challenge); - msgChlng.writeMessage(_socket); + NetworkMessage msgChallenge; + msgChallenge.setField(_ID, _CHALLENGE); + msgChallenge.setField(_CHALLENGE, _challenge); + msgChallenge.writeMessage(_socket); // give client 3 seconds to complete handshake _timerIdAuthTimeout = startTimer(3000); _timerPingTimeout = startTimer(3000); @@ -58,7 +58,6 @@ Client::Client(QTcpSocket* socket) : _socket(socket) Client::~Client() { qDebug() << "*** Client" << _host << " destroyed."; - _socket->deleteLater(); } void Client::timerEvent(QTimerEvent* event) @@ -302,7 +301,7 @@ void Client::stopVncClient() * Checks if client and manager runs on same machine. * @return Return true, if pvsmanager is running on client. */ -bool Client::isManagerMachine() +bool Client::isManagerMachine() const { foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) if (address != QHostAddress(QHostAddress::LocalHost) @@ -334,3 +333,8 @@ void Client::disconnect() this->deleteLater(); emit disconnected(); } + +QString Client::ip() const +{ + return _socket->peerAddress().toString(); +} -- cgit v1.2.3-55-g7522