summaryrefslogtreecommitdiffstats
path: root/src/server/net/client.h
blob: 32237bffa526de94eadb3fe8903023f80237aa12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef CLIENT_H_
#define CLIENT_H_

#include <QtCore>
#include <QHostAddress>
#include <QAbstractSocket>
#include <QTcpSocket>
#include "../../shared/networkmessage.h"

//class QSslSocket;

#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();

	// Getters
	inline bool     isAuthed() { return _authed == 2; }
	inline const QString& name() const { return _name; }
	inline const QString& host() const { return _host; }
	inline const QString  ip() const { return _socket->peerAddress().toString(); }
	inline int      id() { return _id; }
	inline bool     isActiveVncClient() { return _isActiveVncClient; }
	inline bool     isActiveVncServer() { return _vncPort > 0; }
	inline bool     isLocked() { return _locked; }
	inline int      desiredProjectionSource() { return _desiredSource; }
	inline int      projectionSource() { return _projectionSource; }
	inline int      isExamMode() { return _isExamMode; }
	inline bool     wantsAttention() { return _wantsAttention; }
	inline void     removeAttention() { if (!_wantsAttention) return; removeAttentionInternal(); }

	// Setters
	inline void setTutor(bool enable) { _isTutor = enable; }
	inline void setDesiredProjectionSource(int id) {_desiredSource = id;}
	inline void setExamMode(bool mode) { _isExamMode = mode; }

	//Send message stuff
	void startVncServer();
	void stopVncServer();
	void startVncClient(Client const * const 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();

	void handleMsg();
	void sendMessage(NetworkMessage& message);
	void removeAttentionInternal();

protected:
	void timerEvent(QTimerEvent* event);

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();

};

#endif /* CLIENT_H_ */