forked from dparker2/StudyGroup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
71 lines (64 loc) · 2.71 KB
/
server.h
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
#ifndef SERVER_H
#define SERVER_H
#include <QObject>
#include <QtNetwork>
#include <QTimer>
#include <QDateTime>
class server : public QObject
{
Q_OBJECT
public:
const static char timestamp_utc = 2;
const static char timestamp_local = 1;
explicit server(QObject *parent = nullptr);
void connect_server();
void setTimestamps(char arg);
// Account Functions
bool login(QString& username, QString& password, QString& email);
bool create_account(QString& username, QString& password, QString& email);
bool recover_user(QString& email, QString& user);
bool recover_pass(QString& username, QString& email, QString& pass);
bool logout();
// Group Functions
bool create_group(QString& group_name, QString& group_id);
bool join_group(QString& group_id);
bool leave_group(QString& group_id);
signals:
void disconnected();
void connected();
// Group Signals
void new_chat(QString,QString,QString);
void users_changed();
void user_joined(QString);
void user_left(QString);
// Whiteboard
void whiteboard_draw_line(const QPoint&, const QPoint&, const QColor&, const int&);
void get_whiteboard(QString);
void update_whiteboard(QByteArray*);
// Flashcard
void new_flashcard(const int id, const QString&, const bool front);
public slots:
// Socket helper functions
void reconnect_socket(QAbstractSocket::SocketState);
void read_socket_send_signal();
// Group Slots
void send_chat(QString& groupID, QString& message);
// Whiteboard Slots
void send_whiteboard_line(const QString& groupID, const QPoint& point1, const QPoint& point2, const QColor& pen_color, const int& pen_size);
void send_whiteboard(QString& ip, QByteArray* whiteboard);
void save_whiteboard(QString& group_id, QByteArray* whiteboard);
void error(QAbstractSocket::SocketError);
void send_card(QString&, QString&, int&, int&);
private:
QTcpSocket* my_socket;
bool reconnecting;
QDateTime timestamps;
QString username;
bool success_flag; // ***Always set this to 0 before checking, ONLY to be set to 1 by the read_socket_send_signal() function.
bool fail_flag; // ***Always set this to 0 before checking, ONLY to be set to 1 by the read_socket_send_signal() function.
QString success_message; // ***Always set this to nullptr before checking, ONLY to be set by the read_socket_send_signal() function.
QByteArray format_socket_request(const QString& request_code, QString request_arg);
QByteArray format_socket_request(const QString &request_code, const QByteArray& request_arg);
bool read_socket_helper(QString& out_message);
};
#endif // SERVER_H