-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.h
75 lines (62 loc) · 2.12 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
72
73
74
75
#pragma once
#include <QTcpServer>
#include <QTcpSocket>
#include <QVector>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonParseError>
#include <QFile>
#include <QTime>
#include <QUuid>
#include <QTimer>
#include <plog/Log.h>
#include "Entities/entities.h"
#include "Entities/Enums/Enums.h"
#include "Entities/SrvModels/Message.h"
#include "Controllers/RoomController/RoomController.h"
const QString CONFIG_FILE_PATH = "./config.json";
class Server : public QTcpServer
{
Q_OBJECT
Q_DISABLE_COPY(Server)
public:
explicit Server(QObject* parent = nullptr);
~Server();
signals:
void logMessage(enum Severity log_lvl, const QString& msg);
public slots:
void startServer();
void stopServer();
void incomingConnection(qintptr socketDescriptor) override;
private slots:
void broadcastSend(const QJsonObject& message, UserConnection* exclude);
void jsonReceived(UserConnection* sender, const QJsonObject& doc);
void userDisconnected(UserConnection* sender);
void userError(UserConnection* sender);
private:
void disableUsers();
void loadConfig(QString _path);
void openConnection();
void loadRooms();
//void SendToClient(const User_Message& msg, QTcpSocket* socket);
//void SendToClient(const QVector<User_Message>& msgs, QTcpSocket* socket);
////void SendToAllClients(const QString &str);
//void SendToAllClients(const User_Message&msg);
void jsonFromLoggedOut(UserConnection* sender, const QJsonObject& doc);
void jsonFromLoggedIn(UserConnection* sender, const QJsonObject& doc);
void sendJson(UserConnection* destination, const QJsonObject& message);
User_Message createMessage(QString nickame, QString text);
private:
QString server_address;
quint16 server_port;
quint16 flood_limit;
QString black_list_path;
//QTcpSocket* socket;
//QVector <QTcpSocket*> sockets;
QVector<UserConnection*> connected_users;
QVector<RoomController*> rooms;
//переделать в QVector <User_Message*> messages и перенести в Room
QVector <User_Message> messages;
QByteArray Data;
};