qmlfrontend/net_session.h
author Wuzzy <Wuzzy2@mail.ru>
Sun, 21 Jul 2019 11:22:06 +0200
changeset 15278 752b44ffa707
parent 15099 fb7a9b0119d3
permissions -rw-r--r--
Pagetraining: Move style sheet to CSS files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     1
#ifndef NET_SESSION_H
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     2
#define NET_SESSION_H
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     3
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     4
#include <QSharedPointer>
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     5
#include <QSslSocket>
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     6
#include <QStringList>
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     7
#include <QUrl>
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    11
class NetSession : public QObject {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    12
  Q_OBJECT
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    13
15060
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    14
  const int cMinServerVersion = 3;
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    15
  const int cProtocolVersion = 60;
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    16
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    17
  // clang-format off
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    18
  Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    19
  Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    20
  Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY nicknameChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    21
  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
    22
  Q_PROPERTY(QString room READ room NOTIFY roomChanged)
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    23
  Q_PROPERTY(QString passwordHash READ passwordHash WRITE setPasswordHash NOTIFY passwordHashChanged)
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    24
  // clang-format on
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    25
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    26
 public:
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    27
  enum SessionState { NotConnected, Login, Authentication, Lobby, Room, Game };
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    28
  Q_ENUMS(SessionState)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    29
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    32
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    33
  QUrl url() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    34
  QAbstractSocket::SocketState state() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    35
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    36
  QString nickname() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    37
  SessionState sessionState() const;
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
    38
  QString room() const;
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    39
  QString passwordHash() const;
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    40
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    45
  void setUrl(const QUrl &url);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    46
  void setNickname(const QString &nickname);
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    47
  void setPasswordHash(const QString &passwordHash);
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    48
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    49
 signals:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    50
  void urlChanged(const QUrl url);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    51
  void stateChanged(QAbstractSocket::SocketState state);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    52
  void nicknameChanged(const QString &nickname);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    53
  void sessionStateChanged(SessionState sessionState);
15060
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    54
  void warning(const QString &message);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    55
  void error(const QString &message);
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
    56
  void roomChanged(const QString &room);
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    57
  void passwordHashChanged(const QString &passwordHash);
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
    58
  void passwordAsked();
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    59
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    60
 private slots:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    61
  void onReadyRead();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    62
  void parseNetMessage(const QStringList &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    63
  void handleConnected(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    64
  void handlePing(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    65
  void handleBye(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    66
  void handleUnknownCommand(const QStringList &parameters);
15060
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    67
  void handleAddTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    68
  void handleAskPassword(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    69
  void handleBanList(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    70
  void handleCfg(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    71
  void handleChat(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    72
  void handleClientFlags(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    73
  void handleEm(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    74
  void handleError(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    75
  void handleHhNum(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    76
  void handleInfo(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    77
  void handleJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    78
  void handleJoining(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    79
  void handleKicked(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    80
  void handleLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    81
  void handleLobbyJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    82
  void handleLobbyLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    83
  void handleNick(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    84
  void handleNotice(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    85
  void handlePong(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    86
  void handleProto(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    87
  void handleRedirect(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    88
  void handleRemoveTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    89
  void handleReplayStart(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    90
  void handleRoomAbandoned(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    91
  void handleRoom(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    92
  void handleRooms(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    93
  void handleRoundFinished(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    94
  void handleRunGame(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    95
  void handleServerAuth(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    96
  void handleServerMessage(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    97
  void handleServerVars(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    98
  void handleTeamAccepted(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    99
  void handleTeamColor(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
   100
  void handleWarning(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
   101
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   102
  void send(const QString &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   103
  void send(const QString &message, const QString &param);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   104
  void send(const QString &message, const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   105
  void send(const QStringList &message);
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   106
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   107
  void sendPassword();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   108
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   109
  void setSessionState(SessionState sessionState);
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   110
  void setRoom(const QString &room);
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   111
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   112
 private:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   113
  QUrl m_url;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   114
  QSharedPointer<QTcpSocket> m_socket;
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   115
  QSharedPointer<PlayersListModel> m_playersModel;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   116
  QSharedPointer<RoomsListModel> m_roomsModel;
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   117
  QString m_nickname;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   118
  QStringList m_buffer;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   119
  SessionState m_sessionState;
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   120
  QString m_serverAuthHash;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   121
  QString m_room;
15099
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   122
  QString m_serverSalt;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   123
  QString m_serverHash;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   124
  QString m_clientSalt;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15068
diff changeset
   125
  QString m_passwordHash;
15068
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   126
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15060
diff changeset
   127
  Q_DISABLE_COPY(NetSession)
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   128
};
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   129
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   130
#endif  // NET_SESSION_H