blob: 5a4ac7906541ab8e7aaf93d5b4de32241e828cd8 (
plain) (
tree)
|
|
#ifndef CLIENT_H_
#define CLIENT_H_
#include "../../shared/networkmessage.h"
#include <QByteArray>
//class QSslSocket;
class QTcpSocket;
class Client;
#define NO_SOURCE 0
struct ClientLogin {
bool accept;
QString name;
QString host;
QString ip;
bool examMode;
};
class Client : public QObject
{
Q_OBJECT
public:
explicit Client(QTcpSocket* socket);
~Client() override;
// Getters
bool isAuthed() const { return _authed == 2; }
const QString& name() const { return _name; }
const QString& host() const { return _host; }
QString ip() const;
int id() const { return _id; }
bool isActiveVncClient() const { return _isActiveVncClient; }
bool isActiveVncServer() const { return _vncPort > 0; }
bool isLocked() const { return _locked; }
int desiredProjectionSource() const { return _desiredSource; }
int projectionSource() const { return _projectionSource; }
int isExamMode() const { return _isExamMode; }
bool wantsAttention() const { return _wantsAttention; }
void removeAttention() { if (!_wantsAttention) return; removeAttentionInternal(); }
// Setters
void setTutor(bool enable) { _isTutor = enable; }
void setDesiredProjectionSource(int id) { _desiredSource = id; }
void setExamMode(bool mode) { _isExamMode = mode; }
//Send message stuff
void startVncServer();
void stopVncServer();
void startVncClient(const Client * to);
void stopVncClient();
void lockScreen(bool);
void requestThumb(const QSize& size);
private:
QTcpSocket * const _socket;
bool _locked{};
int _authed{}; // 0 = challenge sent, awaiting reply 1 = challenge ok, client challenge replied, awaiting login, 2 = ESTABLISHED
QString _name;
QString _host;
QByteArray _challenge;
qint64 _pingTimeout;
NetworkMessage _fromClient;
int _timerIdAuthTimeout, _timerPingTimeout;
int _id; // this client's unique id
QString _vncRwPass, _vncRoPass;
int _vncPort{}; // VNCserver state. Greater 0 -> active on this port. Equals 0 -> no server.
int _desiredSource; // The source the client shall be connected to
int _projectionSource{}; // The source the client was or is connected to (depends on _isActiveVncClient)
bool _isActiveVncClient{}; // VNCclient state. indicating that the client is displaying a remote screen via VNC
bool _isTutor{}; // Flag indicating that the client has been set as a tutor
bool _isExamMode{};
bool _wantsAttention{}; // Flag telling whether the client activated the "i want attention" button
QByteArray _rawRemoteScreen;
static int _clientIdCounter;
bool isManagerMachine() const;
void handleMsg();
void sendMessage(NetworkMessage& message);
void removeAttentionInternal();
protected:
void timerEvent(QTimerEvent* event) override;
signals:
void authenticating(Client* client, ClientLogin* request);
void authenticated(Client* client);
void thumbUpdated(Client* client, const QImage& thumb);
void vncServerStateChange(Client* client);
void vncClientStateChange(Client* client);
void stateChanged();
void disconnected();
private slots:
void onDataArrival(); // triggered if data is available for reading
void disconnect(const char *errmsg);
};
#endif /* CLIENT_H_ */
|