3 |
3 |
4 #include <QSharedPointer> |
4 #include <QSharedPointer> |
5 #include <QSslSocket> |
5 #include <QSslSocket> |
6 #include <QStringList> |
6 #include <QStringList> |
7 #include <QUrl> |
7 #include <QUrl> |
|
8 #include <QtQmlIntegration> |
8 |
9 |
9 class PlayersListModel; |
10 class PlayersListModel; |
10 class RoomsListModel; |
11 class RoomsListModel; |
11 class NetSession : public QObject { |
12 class NetSession : public QObject { |
12 Q_OBJECT |
13 Q_OBJECT |
|
14 |
|
15 QML_ELEMENT |
13 |
16 |
14 const int cMinServerVersion = 3; |
17 const int cMinServerVersion = 3; |
15 const int cProtocolVersion = 60; |
18 const int cProtocolVersion = 60; |
16 |
19 |
17 // clang-format off |
20 // clang-format off |
23 Q_PROPERTY(QString passwordHash READ passwordHash WRITE setPasswordHash NOTIFY passwordHashChanged) |
26 Q_PROPERTY(QString passwordHash READ passwordHash WRITE setPasswordHash NOTIFY passwordHashChanged) |
24 // clang-format on |
27 // clang-format on |
25 |
28 |
26 public: |
29 public: |
27 enum SessionState { NotConnected, Login, Authentication, Lobby, Room, Game }; |
30 enum SessionState { NotConnected, Login, Authentication, Lobby, Room, Game }; |
28 Q_ENUMS(SessionState) |
31 Q_ENUM(SessionState) |
29 |
32 |
30 explicit NetSession(QObject *parent = nullptr); |
33 explicit NetSession(QObject *parent = nullptr); |
31 ~NetSession() override; |
34 ~NetSession() override; |
32 |
35 |
33 QUrl url() const; |
36 QUrl url() const; |
36 QString nickname() const; |
39 QString nickname() const; |
37 SessionState sessionState() const; |
40 SessionState sessionState() const; |
38 QString room() const; |
41 QString room() const; |
39 QString passwordHash() const; |
42 QString passwordHash() const; |
40 |
43 |
41 public slots: |
44 public Q_SLOTS: |
42 void open(); |
45 void open(); |
43 void close(); |
46 void close(); |
44 |
47 |
45 void setUrl(const QUrl &url); |
48 void setUrl(const QUrl &url); |
46 void setNickname(const QString &nickname); |
49 void setNickname(const QString &nickname); |
47 void setPasswordHash(const QString &passwordHash); |
50 void setPasswordHash(const QString &passwordHash); |
48 |
51 |
49 signals: |
52 Q_SIGNALS: |
50 void urlChanged(const QUrl url); |
53 void urlChanged(const QUrl url); |
51 void stateChanged(QAbstractSocket::SocketState state); |
54 void stateChanged(QAbstractSocket::SocketState state); |
52 void nicknameChanged(const QString &nickname); |
55 void nicknameChanged(const QString &nickname); |
53 void sessionStateChanged(SessionState sessionState); |
56 void sessionStateChanged(SessionState sessionState); |
54 void warning(const QString &message); |
57 void warning(const QString &message); |
55 void error(const QString &message); |
58 void error(const QString &message); |
56 void roomChanged(const QString &room); |
59 void roomChanged(const QString &room); |
57 void passwordHashChanged(const QString &passwordHash); |
60 void passwordHashChanged(const QString &passwordHash); |
58 void passwordAsked(); |
61 void passwordAsked(); |
59 |
62 |
60 private slots: |
63 private Q_SLOTS: |
61 void onReadyRead(); |
64 void onReadyRead(); |
62 void parseNetMessage(const QStringList &message); |
65 void parseNetMessage(const QStringList &message); |
63 void handleConnected(const QStringList ¶meters); |
66 void handleConnected(const QStringList ¶meters); |
64 void handlePing(const QStringList ¶meters); |
67 void handlePing(const QStringList ¶meters); |
65 void handleBye(const QStringList ¶meters); |
68 void handleBye(const QStringList ¶meters); |