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