From 58646932664b6ab9014a410dc75dd443fb4f58b9 Mon Sep 17 00:00:00 2001 From: Manuel Schneider Date: Tue, 20 May 2014 14:47:42 +0200 Subject: Remove any knowledge of Networkmesage in Mainwindow --- src/server/mainwindow/mainwindow.cpp | 61 ++++++++-------------------- src/server/net/client.cpp | 25 +++++++++++- src/server/net/client.h | 79 ++++++++++++++++-------------------- 3 files changed, 74 insertions(+), 91 deletions(-) diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 83a424e..8ca00a0 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -28,7 +28,6 @@ #include "../net/listenserver.h" #include "../net/client.h" #include "../net/discoverylistener.h" -#include "../../shared/networkmessage.h" #include "../net/filedownloader.h" // Others #include "../../shared/settings.h" @@ -597,8 +596,8 @@ void MainWindow::onButtonStudentToTutorExclusive() /***************************************************************************//** * Handle Button StopProjection. - * Set ProjectionSource of each client to false and create a NetworkMessage to - * stop the active VNC Server and the active VNC Client(s). + * Set ProjectionSource of each client to false, stop the active VNC Server + * and the active VNC Client(s). */ void MainWindow::onButtonStopProjection() { @@ -610,47 +609,38 @@ void MainWindow::onButtonStopProjection() c->setDesiredProjectionSource(0); c->setProjectionSource(false); } - NetworkMessage stopVncClientmsg; - NetworkMessage stopVncServermsg; - stopVncClientmsg.setField(_ID, _VNCCLIENT); - stopVncServermsg.setField(_ID, _VNCSERVER); + for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { Client *c = (**it).client(); if (c == NULL) continue; - c->sendMessage(stopVncClientmsg); - c->sendMessage(stopVncServermsg); + c->stopVncClient(); + c->stopVncServer(); } } /***************************************************************************//** * Handle button to lock or unlock screens of client(s). - * If already locked, do nothing, else create a NetworkMessage to lock (checked) or - * unlock (!checked) the client(s), except the tutor. + * If already locked, do nothing, else lock or unlock the clients, except the + * tutor. * @param checked */ void MainWindow::onButtonLock(bool checked) { - NetworkMessage msg; - msg.setField(_ID, _LOCK); - if (checked) - msg.setField("ENABLE", QByteArray("1")); - else - msg.setField("ENABLE", QByteArray("0")); for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { - Client *c = (**it).client(); - // Check if client is Tutor or the manager is also running on this machine. bool isManagerMachine = false; foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) - if (address != QHostAddress(QHostAddress::LocalHost) && c != NULL && c->ip() == address.toString()) + if (address != QHostAddress(QHostAddress::LocalHost) + && (*it)->client() != NULL + && (*it)->client()->ip() == address.toString()) isManagerMachine = true; - if (c == NULL || (**it).isTutor() || isManagerMachine) + if ((*it)->client() == NULL || (*it)->isTutor() || isManagerMachine) continue; // Don't lock the tutor or the manager running machine. - c->sendMessage(msg); + (*it)->client()->lockScreen(checked); } } @@ -815,29 +805,17 @@ void MainWindow::onClientAuthenticated(Client* client) // Assign client instance cf->assignClient(client); // ################ - NetworkMessage msg; // If clients are currently locked, tell this new client if (ui->action_Lock->isChecked()) - { - msg.reset(); - msg.setField(_ID, _LOCK); - msg.setField("ENABLE", QByteArray("1")); - client->sendMessage(msg); - } + client->lockScreen(true); + // Same for VNC projections for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { Client *c = (**it).client(); if (c != NULL && c != client && c->isActiveVncServer() && c->isProjectionSource()) { - msg.reset(); - msg.setField(_ID, _VNCCLIENT); - msg.setField("HOST", c->ip()); - msg.setField("PORT", QString::number(c->vncPort())); - msg.setField("ROPASS", c->vncRoPass()); - msg.setField("CLIENTID", QString::number(c->id())); - msg.setField("CAPTION", c->name() + " @ " + c->host()); - client->sendMessage(msg); + c->startVncClient(c->ip(), c->vncPort(), c->vncRoPass(), c->id(), c->name() + " @ " + c->host()); client->setDesiredProjectionSource(c->id()); break; } @@ -857,13 +835,6 @@ void MainWindow::onVncServerStateChange(Client* client) if (client->vncPort() > 0) { // VNC Server started on some client - start projection on all clients interested in that client's screen - NetworkMessage msg; - msg.setField(_ID, _VNCCLIENT); - msg.setField("HOST", client->ip()); - msg.setField("PORT", QString::number(client->vncPort())); - msg.setField("ROPASS", client->vncRoPass()); - msg.setField("CLIENTID", QString::number(client->id())); - msg.setField("CAPTION", client->name() + " @ " + client->host()); for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { Client *c = (**it).client(); @@ -873,7 +844,7 @@ void MainWindow::onVncServerStateChange(Client* client) continue; // Already watching this client if (c->desiredProjectionSource() != client->id() && !client->isProjectionSource()) continue; // Not interested - c->sendMessage(msg); + c->startVncClient(client->ip(), client->vncPort(), client->vncRoPass(), client->id(), client->name() + " @ " + client->host()); } } else diff --git a/src/server/net/client.cpp b/src/server/net/client.cpp index 4bb19bf..6b3997c 100644 --- a/src/server/net/client.cpp +++ b/src/server/net/client.cpp @@ -187,7 +187,7 @@ void Client::handleMsg() { if (_vncPort <= 0) { - qDebug() << "Starting VNC server on client" << _name << " (" << _ip << ") failed."; + qDebug() << "Starting VNC server on client" << _name << " (" << _ip+_vncPort << ") failed."; // TODO: Show message on manager } else @@ -322,6 +322,29 @@ void Client::stopVncClient() sendMessage(_toClient); } +/******************************************************************************/ +void Client::startVncClient(QString host, int port, QString pass, int id, QString caption) +{ + _activeVncClient = false; + _toClient.reset(); + _toClient.setField(_ID, _VNCCLIENT); + _toClient.setField("HOST", host); + _toClient.setField("PORT", QString::number(port)); + _toClient.setField("ROPASS", pass); + _toClient.setField("CLIENTID", QString::number(id)); + _toClient.setField("CAPTION", caption); + sendMessage(_toClient); +} + +/******************************************************************************/ +void Client::lockScreen(bool lock) +{ + _toClient.reset(); + _toClient.setField(_ID, _LOCK); + _toClient.setField(_ENABLE, lock ? __TRUE : __FALSE); + sendMessage(_toClient); +} + /******************************************************************************/ void Client::setTutor(bool enable) { diff --git a/src/server/net/client.h b/src/server/net/client.h index a6d9001..e9bd46b 100644 --- a/src/server/net/client.h +++ b/src/server/net/client.h @@ -21,55 +21,10 @@ class Client : public QObject { Q_OBJECT -private: - static int _clientIdCounter; - - QSslSocket *_socket; - int _authed; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED - QString _name; - QString _host; - QString _ip; - QByteArray _challenge; - qint64 _pingTimeout; - NetworkMessage _toClient, _fromClient; - int _timerIdAuthTimeout, _timerDelete, _timerPingTimeout; - - // this client's unique id - int _id; - - // If this client should be projected to from another client, the other - // client's id is set here. 0 otherwise. This is not currently used and it is - // questionable if this makes sense, as it might just be confusing if several - // groups students watch different other students. Also, visualizing such a - // situation in the GUI in a meaningful way would be hard. - int _desiredProjectionSource; - - - bool _isProjectionSource; // Tells whether this client is currently the VNC broadcast source. - int _currentProjectionSource; - - QString _vncRwPass, _vncRoPass; - - // Indicates the state of the client. The clients acts as VNC server if this - // port is set. If this value is less than or equal to 0 ist is no server. - int _vncPort; - - // Flag indicating that the client is displaying a remote screen via VNC - bool _activeVncClient; - - // Flag indicating that the client has been set as a tutor - bool _isTutor; - - void handleMsg(); - -protected: - void timerEvent(QTimerEvent* event); - public: explicit Client(QSslSocket* socket); ~Client(); void requestThumb(const int width, const int height); - void sendMessage(NetworkMessage& message); //void acceptData(); const inline bool isAuthed() const { return _authed == 2; } const inline QString& name() const { return _name; } @@ -91,9 +46,43 @@ public: inline const int currentProjectionSource() const { return _currentProjectionSource; } void startVncServer(); void stopVncServer(); + void startVncClient(QString host, int port, QString pass, int id, QString caption); void stopVncClient(); + void lockScreen(bool); void setTutor(bool enable); +private: + static int _clientIdCounter; + + QSslSocket *_socket; + int _authed; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED + QString _name; + QString _host; + QString _ip; + QByteArray _challenge; + qint64 _pingTimeout; + NetworkMessage _toClient, _fromClient; + int _timerIdAuthTimeout, _timerDelete, _timerPingTimeout; + int _id; // this client's unique id + // If this client should be projected to from another client, the other + // client's id is set here. 0 otherwise. This is not currently used and it is + // questionable if this makes sense, as it might just be confusing if several + // groups students watch different other students. Also, visualizing such a + // situation in the GUI in a meaningful way would be hard. + int _desiredProjectionSource; + bool _isProjectionSource; // Tells whether this client is currently the VNC broadcast source. + int _currentProjectionSource; + QString _vncRwPass, _vncRoPass; + int _vncPort; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server. + bool _activeVncClient; // Flag indicating that the client is displaying a remote screen via VNC + bool _isTutor; // Flag indicating that the client has been set as a tutor + + void handleMsg(); + void sendMessage(NetworkMessage& message); + +protected: + void timerEvent(QTimerEvent* event); + signals: void authenticating(Client* client, ClientLogin* request); void authenticated(Client* client); -- cgit v1.2.3-55-g7522