author | unC0Rr |
Tue, 04 Feb 2025 17:31:55 +0100 | |
branch | qmlrenderer |
changeset 16116 | 8da5a118120b |
parent 15099 | fb7a9b0119d3 |
permissions | -rw-r--r-- |
14936 | 1 |
#ifndef NET_SESSION_H |
2 |
#define NET_SESSION_H |
|
3 |
||
4 |
#include <QSharedPointer> |
|
5 |
#include <QSslSocket> |
|
6 |
#include <QStringList> |
|
7 |
#include <QUrl> |
|
16116 | 8 |
#include <QtQmlIntegration> |
14936 | 9 |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
10 |
class PlayersListModel; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
11 |
class RoomsListModel; |
14936 | 12 |
class NetSession : public QObject { |
13 |
Q_OBJECT |
|
14 |
||
16116 | 15 |
QML_ELEMENT |
16 |
||
15060 | 17 |
const int cMinServerVersion = 3; |
18 |
const int cProtocolVersion = 60; |
|
19 |
||
14936 | 20 |
// clang-format off |
21 |
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) |
|
22 |
Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged) |
|
23 |
Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY nicknameChanged) |
|
24 |
Q_PROPERTY(SessionState sessionState READ sessionState NOTIFY sessionStateChanged) |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
25 |
Q_PROPERTY(QString room READ room NOTIFY roomChanged) |
15099 | 26 |
Q_PROPERTY(QString passwordHash READ passwordHash WRITE setPasswordHash NOTIFY passwordHashChanged) |
14936 | 27 |
// clang-format on |
28 |
||
29 |
public: |
|
15099 | 30 |
enum SessionState { NotConnected, Login, Authentication, Lobby, Room, Game }; |
16116 | 31 |
Q_ENUM(SessionState) |
14936 | 32 |
|
33 |
explicit NetSession(QObject *parent = nullptr); |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
34 |
~NetSession() override; |
14936 | 35 |
|
36 |
QUrl url() const; |
|
37 |
QAbstractSocket::SocketState state() const; |
|
38 |
||
39 |
QString nickname() const; |
|
40 |
SessionState sessionState() const; |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
41 |
QString room() const; |
15099 | 42 |
QString passwordHash() const; |
14936 | 43 |
|
16116 | 44 |
public Q_SLOTS: |
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
45 |
void open(); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
46 |
void close(); |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
47 |
|
14936 | 48 |
void setUrl(const QUrl &url); |
49 |
void setNickname(const QString &nickname); |
|
15099 | 50 |
void setPasswordHash(const QString &passwordHash); |
14936 | 51 |
|
16116 | 52 |
Q_SIGNALS: |
14936 | 53 |
void urlChanged(const QUrl url); |
54 |
void stateChanged(QAbstractSocket::SocketState state); |
|
55 |
void nicknameChanged(const QString &nickname); |
|
56 |
void sessionStateChanged(SessionState sessionState); |
|
15060 | 57 |
void warning(const QString &message); |
58 |
void error(const QString &message); |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
59 |
void roomChanged(const QString &room); |
15099 | 60 |
void passwordHashChanged(const QString &passwordHash); |
61 |
void passwordAsked(); |
|
14936 | 62 |
|
16116 | 63 |
private Q_SLOTS: |
14936 | 64 |
void onReadyRead(); |
65 |
void parseNetMessage(const QStringList &message); |
|
66 |
void handleConnected(const QStringList ¶meters); |
|
67 |
void handlePing(const QStringList ¶meters); |
|
68 |
void handleBye(const QStringList ¶meters); |
|
69 |
void handleUnknownCommand(const QStringList ¶meters); |
|
15060 | 70 |
void handleAddTeam(const QStringList ¶meters); |
71 |
void handleAskPassword(const QStringList ¶meters); |
|
72 |
void handleBanList(const QStringList ¶meters); |
|
73 |
void handleCfg(const QStringList ¶meters); |
|
74 |
void handleChat(const QStringList ¶meters); |
|
75 |
void handleClientFlags(const QStringList ¶meters); |
|
76 |
void handleEm(const QStringList ¶meters); |
|
77 |
void handleError(const QStringList ¶meters); |
|
78 |
void handleHhNum(const QStringList ¶meters); |
|
79 |
void handleInfo(const QStringList ¶meters); |
|
80 |
void handleJoined(const QStringList ¶meters); |
|
81 |
void handleJoining(const QStringList ¶meters); |
|
82 |
void handleKicked(const QStringList ¶meters); |
|
83 |
void handleLeft(const QStringList ¶meters); |
|
84 |
void handleLobbyJoined(const QStringList ¶meters); |
|
85 |
void handleLobbyLeft(const QStringList ¶meters); |
|
86 |
void handleNick(const QStringList ¶meters); |
|
87 |
void handleNotice(const QStringList ¶meters); |
|
88 |
void handlePong(const QStringList ¶meters); |
|
89 |
void handleProto(const QStringList ¶meters); |
|
90 |
void handleRedirect(const QStringList ¶meters); |
|
91 |
void handleRemoveTeam(const QStringList ¶meters); |
|
92 |
void handleReplayStart(const QStringList ¶meters); |
|
93 |
void handleRoomAbandoned(const QStringList ¶meters); |
|
94 |
void handleRoom(const QStringList ¶meters); |
|
95 |
void handleRooms(const QStringList ¶meters); |
|
96 |
void handleRoundFinished(const QStringList ¶meters); |
|
97 |
void handleRunGame(const QStringList ¶meters); |
|
98 |
void handleServerAuth(const QStringList ¶meters); |
|
99 |
void handleServerMessage(const QStringList ¶meters); |
|
100 |
void handleServerVars(const QStringList ¶meters); |
|
101 |
void handleTeamAccepted(const QStringList ¶meters); |
|
102 |
void handleTeamColor(const QStringList ¶meters); |
|
103 |
void handleWarning(const QStringList ¶meters); |
|
104 |
||
14936 | 105 |
void send(const QString &message); |
106 |
void send(const QString &message, const QString ¶m); |
|
107 |
void send(const QString &message, const QStringList ¶meters); |
|
108 |
void send(const QStringList &message); |
|
15099 | 109 |
|
110 |
void sendPassword(); |
|
111 |
||
14936 | 112 |
void setSessionState(SessionState sessionState); |
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
113 |
void setRoom(const QString &room); |
14936 | 114 |
|
115 |
private: |
|
116 |
QUrl m_url; |
|
117 |
QSharedPointer<QTcpSocket> m_socket; |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
118 |
QSharedPointer<PlayersListModel> m_playersModel; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
119 |
QSharedPointer<RoomsListModel> m_roomsModel; |
14936 | 120 |
QString m_nickname; |
121 |
QStringList m_buffer; |
|
122 |
SessionState m_sessionState; |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
123 |
QString m_serverAuthHash; |
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
124 |
QString m_room; |
15099 | 125 |
QString m_serverSalt; |
126 |
QString m_serverHash; |
|
127 |
QString m_clientSalt; |
|
128 |
QString m_passwordHash; |
|
15068
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
129 |
|
773beead236f
Add handling of some messages, reuse models from the old frontend
unc0rr
parents:
15060
diff
changeset
|
130 |
Q_DISABLE_COPY(NetSession) |
14936 | 131 |
}; |
132 |
||
133 |
#endif // NET_SESSION_H |