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 |
|
|
9 |
class NetSession : public QObject {
|
|
10 |
Q_OBJECT
|
|
11 |
|
15039
|
12 |
const int cMinServerVersion = 3;
|
|
13 |
const int cProtocolVersion = 60;
|
|
14 |
|
14915
|
15 |
// clang-format off
|
|
16 |
Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
|
|
17 |
Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged)
|
|
18 |
Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY nicknameChanged)
|
|
19 |
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
|
|
20 |
Q_PROPERTY(SessionState sessionState READ sessionState NOTIFY sessionStateChanged)
|
|
21 |
// clang-format on
|
|
22 |
|
|
23 |
public:
|
|
24 |
enum SessionState { NotConnected, Login, Lobby, Room, Game };
|
|
25 |
Q_ENUMS(SessionState)
|
|
26 |
|
|
27 |
explicit NetSession(QObject *parent = nullptr);
|
|
28 |
|
|
29 |
QUrl url() const;
|
|
30 |
QAbstractSocket::SocketState state() const;
|
|
31 |
|
|
32 |
Q_INVOKABLE void open();
|
|
33 |
|
|
34 |
QString nickname() const;
|
|
35 |
QString password() const;
|
|
36 |
SessionState sessionState() const;
|
|
37 |
|
|
38 |
public slots:
|
|
39 |
void setUrl(const QUrl &url);
|
|
40 |
void setNickname(const QString &nickname);
|
|
41 |
void setPassword(const QString &password);
|
|
42 |
void close();
|
|
43 |
|
|
44 |
signals:
|
|
45 |
void urlChanged(const QUrl url);
|
|
46 |
void stateChanged(QAbstractSocket::SocketState state);
|
|
47 |
void nicknameChanged(const QString &nickname);
|
|
48 |
void passwordChanged(const QString &password);
|
|
49 |
void sessionStateChanged(SessionState sessionState);
|
15039
|
50 |
void warning(const QString &message);
|
|
51 |
void error(const QString &message);
|
14915
|
52 |
|
|
53 |
private slots:
|
|
54 |
void onReadyRead();
|
|
55 |
void parseNetMessage(const QStringList &message);
|
|
56 |
void handleConnected(const QStringList ¶meters);
|
|
57 |
void handlePing(const QStringList ¶meters);
|
|
58 |
void handleBye(const QStringList ¶meters);
|
|
59 |
void handleUnknownCommand(const QStringList ¶meters);
|
15039
|
60 |
void handleAddTeam(const QStringList ¶meters);
|
|
61 |
void handleAskPassword(const QStringList ¶meters);
|
|
62 |
void handleBanList(const QStringList ¶meters);
|
|
63 |
void handleCfg(const QStringList ¶meters);
|
|
64 |
void handleChat(const QStringList ¶meters);
|
|
65 |
void handleClientFlags(const QStringList ¶meters);
|
|
66 |
void handleEm(const QStringList ¶meters);
|
|
67 |
void handleError(const QStringList ¶meters);
|
|
68 |
void handleHhNum(const QStringList ¶meters);
|
|
69 |
void handleInfo(const QStringList ¶meters);
|
|
70 |
void handleJoined(const QStringList ¶meters);
|
|
71 |
void handleJoining(const QStringList ¶meters);
|
|
72 |
void handleKicked(const QStringList ¶meters);
|
|
73 |
void handleLeft(const QStringList ¶meters);
|
|
74 |
void handleLobbyJoined(const QStringList ¶meters);
|
|
75 |
void handleLobbyLeft(const QStringList ¶meters);
|
|
76 |
void handleNick(const QStringList ¶meters);
|
|
77 |
void handleNotice(const QStringList ¶meters);
|
|
78 |
void handlePong(const QStringList ¶meters);
|
|
79 |
void handleProto(const QStringList ¶meters);
|
|
80 |
void handleRedirect(const QStringList ¶meters);
|
|
81 |
void handleRemoveTeam(const QStringList ¶meters);
|
|
82 |
void handleReplayStart(const QStringList ¶meters);
|
|
83 |
void handleRoomAbandoned(const QStringList ¶meters);
|
|
84 |
void handleRoom(const QStringList ¶meters);
|
|
85 |
void handleRooms(const QStringList ¶meters);
|
|
86 |
void handleRoundFinished(const QStringList ¶meters);
|
|
87 |
void handleRunGame(const QStringList ¶meters);
|
|
88 |
void handleServerAuth(const QStringList ¶meters);
|
|
89 |
void handleServerMessage(const QStringList ¶meters);
|
|
90 |
void handleServerVars(const QStringList ¶meters);
|
|
91 |
void handleTeamAccepted(const QStringList ¶meters);
|
|
92 |
void handleTeamColor(const QStringList ¶meters);
|
|
93 |
void handleWarning(const QStringList ¶meters);
|
|
94 |
|
14915
|
95 |
void send(const QString &message);
|
|
96 |
void send(const QString &message, const QString ¶m);
|
|
97 |
void send(const QString &message, const QStringList ¶meters);
|
|
98 |
void send(const QStringList &message);
|
|
99 |
void setSessionState(SessionState sessionState);
|
|
100 |
|
|
101 |
private:
|
|
102 |
QUrl m_url;
|
|
103 |
QSharedPointer<QTcpSocket> m_socket;
|
|
104 |
QString m_nickname;
|
|
105 |
QString m_password;
|
|
106 |
QStringList m_buffer;
|
|
107 |
SessionState m_sessionState;
|
|
108 |
};
|
|
109 |
|
|
110 |
#endif // NET_SESSION_H
|