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