From 3d82bfc698165bb20f3c38d42f2b77ab855c1edf Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Thu, 29 Sep 2016 15:40:18 +0200 Subject: astyle. --- src/server/net/client.cpp | 116 ++++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 75 deletions(-) (limited to 'src/server/net/client.cpp') diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index 84c45a9..5cd5c30 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -33,13 +33,13 @@ Client::Client(QSslSocket* socket) : _socket(socket) qDebug("*** Client %s created.", qPrintable(_socket->peerAddress().toString())); // Connect important signals connect(_socket, SIGNAL(disconnected()), - this, SLOT(disconnect())); + this, SLOT(disconnect())); connect(_socket, SIGNAL(error(QAbstractSocket::SocketError)), - this, SLOT(disconnect())); + this, SLOT(disconnect())); connect(_socket, SIGNAL(sslErrors(const QList &)), - this, SLOT(disconnect())); + this, SLOT(disconnect())); connect(_socket, SIGNAL(readyRead()), - this, SLOT(onDataArrival())); + this, SLOT(onDataArrival())); // Send challenge _challenge.resize(CHALLENGE_LEN); for (int i = 0; i < CHALLENGE_LEN; ++i) @@ -64,23 +64,18 @@ Client::~Client() /******************************************************************************/ void Client::timerEvent(QTimerEvent* event) { - if (event->timerId() == _timerPingTimeout) - { - if (_pingTimeout < QDateTime::currentMSecsSinceEpoch()) - { + if (event->timerId() == _timerPingTimeout) { + if (_pingTimeout < QDateTime::currentMSecsSinceEpoch()) { qDebug() << "Client" << _socket->peerAddress().toString() << "has a ping timeout."; killTimer(_timerPingTimeout); this->disconnect(); } - } - else if (event->timerId() == _timerIdAuthTimeout) - { + } else if (event->timerId() == _timerIdAuthTimeout) { // Client did not send login request within 3 seconds killTimer(_timerIdAuthTimeout); _timerIdAuthTimeout = 0; this->disconnect(); - } - else + } else killTimer(event->timerId()); } @@ -90,8 +85,7 @@ void Client::sendMessage(NetworkMessage& message) if (_socket->state() != QAbstractSocket::ConnectedState) return; message.writeMessage(_socket); - if (!message.writeComplete()) - { + if (!message.writeComplete()) { qCritical() << "SendMessage to client " << _name << "@" << _socket->peerAddress().toString() << " failed!"; } } @@ -99,8 +93,7 @@ void Client::sendMessage(NetworkMessage& message) /******************************************************************************/ void Client::requestThumb(const int width, const int height) { - if (_socket->state() != QAbstractSocket::ConnectedState) - { + if (_socket->state() != QAbstractSocket::ConnectedState) { qDebug("requestThumb called in bad state"); return; } @@ -115,25 +108,21 @@ void Client::requestThumb(const int width, const int height) void Client::onDataArrival() { // - if (_socket->state() != QAbstractSocket::ConnectedState) - { + if (_socket->state() != QAbstractSocket::ConnectedState) { qDebug("dataArrival called in bad state"); return; } bool ret; - while (_socket->bytesAvailable() > 0) - { + while (_socket->bytesAvailable() > 0) { ret = _fromClient.readMessage(_socket); // let the message read data from socket - if (ret == NM_READ_FAILED) // error parsing msg, disconnect client! - { + if (ret == NM_READ_FAILED) { // error parsing msg, disconnect client! this->disconnect(); return; } if (ret == NM_READ_INCOMPLETE) return; - if (_fromClient.readComplete()) // message is complete - { + if (_fromClient.readComplete()) { // message is complete this->handleMsg(); _fromClient.reset(); } @@ -145,47 +134,35 @@ void Client::handleMsg() { _pingTimeout = QDateTime::currentMSecsSinceEpoch() + PING_TIMEOUT_MS; const QString &id = _fromClient.getFieldString(_ID); - if (id.isEmpty()) - { + if (id.isEmpty()) { qDebug("Received message with empty ID field. ignored."); return; } - if (_authed == 2) - { + if (_authed == 2) { // Following messages are only valid of the client is already authenticated - if (id == _THUMB) - { + if (id == _THUMB) { QPixmap pixmap; const QByteArray& rawImage = _fromClient.getFieldBytes("IMG"); /* size 0 means the client is in exam-mode and therefore doesn't send any thumbnail */ if (rawImage.size() > 0) { - if (!pixmap.loadFromData(rawImage)) - { + if (!pixmap.loadFromData(rawImage)) { qDebug("Could not decode thumbnail image from client."); return; } _rawRemoteScreen = QByteArray(rawImage); emit thumbUpdated(this, pixmap, rawImage); } - } - else if (id == _VNCSERVER) - { + } else if (id == _VNCSERVER) { // Client tells about startup of vnc server const int port = _fromClient.getFieldString("PORT").toInt(); - if (port <= 0) - { - if (_vncPort <= 0) - { - qDebug() << "Starting VNC server on client" << _name << " (" << _socket->peerAddress().toString()+_vncPort << ") failed."; - } - else - { + if (port <= 0) { + if (_vncPort <= 0) { + qDebug() << "Starting VNC server on client" << _name << " (" << _socket->peerAddress().toString() + _vncPort << ") failed."; + } else { qDebug() << "Client " << _name << " stopped its VNC server"; } - } - else - { + } else { _vncRoPass = _fromClient.getFieldString("ROPASS"); _vncRwPass = _fromClient.getFieldString("RWPASS"); qDebug() << "Client " << _name << " started its VNC server"; @@ -193,20 +170,15 @@ void Client::handleMsg() _vncPort = port; emit vncServerStateChange(this); emit stateChanged(); - } - else if (id == _VNCCLIENT) - { + } else if (id == _VNCCLIENT) { // Client tells us that it started or stopped displaying a remote screen via VNC const int projectionSource = (int)_fromClient.getFieldString("CLIENTID").toInt(); - if (_fromClient.getFieldString("ENABLED").toInt() != 0) - { + if (_fromClient.getFieldString("ENABLED").toInt() != 0) { qDebug() << "Client " << _name << " started its VNC client (watching " << projectionSource << ")"; _projectionSource = projectionSource; _isActiveVncClient = true; emit vncClientStateChange(this); - } - else - { + } else { qDebug() << "Client " << _name << " stopped its VNC client (watched " << projectionSource << ")"; _isActiveVncClient = false; emit vncClientStateChange(this); @@ -217,10 +189,8 @@ void Client::handleMsg() } // Not authed yet, only care about login requests - if (_authed == 1) - { - if (id == _LOGIN) - { + if (_authed == 1) { + if (id == _LOGIN) { killTimer(_timerIdAuthTimeout); _timerIdAuthTimeout = 0; ClientLogin request; @@ -233,8 +203,7 @@ void Client::handleMsg() qDebug() << "Login request by " << request.name << (request.examMode ? "(in exam mode)" : ""); // emit event, see if request is accepted emit authenticating(this, &request); - if (!request.accept) - { + if (!request.accept) { qDebug("Request denied."); this->disconnect(); // Nope return; @@ -253,16 +222,14 @@ void Client::handleMsg() } // Did not pass challenge yet - if (_authed == 0) - { + if (_authed == 0) { // Waiting for challenge reply by client - if (id == _CHALLENGE) - { + if (id == _CHALLENGE) { QByteArray hash(_fromClient.getFieldBytes(_HASH)); QByteArray challenge(_fromClient.getFieldBytes(_CHALLENGE)); if (genSha1(&Global::sessionNameArray(), &_challenge) != hash - && !(Global::getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString()))) - { // Challenge reply is invalid, drop client + && !(Global::getCurrentRoom()->clientPositions.contains(_socket->peerAddress().toString()))) { + // Challenge reply is invalid, drop client NetworkMessage msgErr; msgErr.buildErrorMessage("Challenge reply invalid."); msgErr.writeMessage(_socket); @@ -310,8 +277,7 @@ void Client::startVncClient(const Client * const to) msg.setField("ROPASS", to->_vncRoPass); msg.setField("CLIENTID", QString::number(to->_id)); msg.setField("CAPTION", to->_name + " @ " + to->_host); - if (!to->_rawRemoteScreen.isEmpty()) - { + if (!to->_rawRemoteScreen.isEmpty()) { msg.setField(_THUMB, to->_rawRemoteScreen); } sendMessage(msg); @@ -333,18 +299,18 @@ void Client::stopVncClient() */ bool Client::isManagerMachine() { - foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) - if (address != QHostAddress(QHostAddress::LocalHost) - && this != NULL - && this->ip() == address.toString()) - return true; + foreach (const QHostAddress & address, QNetworkInterface::allAddresses()) + if (address != QHostAddress(QHostAddress::LocalHost) + && this != NULL + && this->ip() == address.toString()) + return true; return false; } /******************************************************************************/ void Client::lockScreen(bool lock) { - if (!_isTutor && _locked != lock && !isManagerMachine()){ + if (!_isTutor && _locked != lock && !isManagerMachine()) { _locked = lock; NetworkMessage msg; msg.setField(_ID, _LOCK); -- cgit v1.2.3-55-g7522