qmlfrontend/net_session.h
author unc0rr
Fri, 24 May 2019 23:39:51 +0200
changeset 15068 773beead236f
parent 15060 a4a058dcbbd6
child 15099 fb7a9b0119d3
permissions -rw-r--r--
Add handling of some messages, reuse models from the old frontend
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(QString password READ password WRITE setPassword NOTIFY passwordChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    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
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:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    27
  enum SessionState { NotConnected, Login, Lobby, Room, Game };
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
  QString password() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    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
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);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    47
  void setPassword(const QString &password);
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 passwordChanged(const QString &password);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    54
  void sessionStateChanged(SessionState sessionState);
15060
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    55
  void warning(const QString &message);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    58
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    59
 private slots:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    60
  void onReadyRead();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    61
  void parseNetMessage(const QStringList &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    62
  void handleConnected(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    63
  void handlePing(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    64
  void handleBye(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    65
  void handleUnknownCommand(const QStringList &parameters);
15060
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    66
  void handleAddTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    67
  void handleAskPassword(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    68
  void handleBanList(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    69
  void handleCfg(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    70
  void handleChat(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    71
  void handleClientFlags(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    72
  void handleEm(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    73
  void handleError(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    74
  void handleHhNum(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    75
  void handleInfo(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    76
  void handleJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    77
  void handleJoining(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    78
  void handleKicked(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    79
  void handleLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    80
  void handleLobbyJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    81
  void handleLobbyLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    82
  void handleNick(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    83
  void handleNotice(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    84
  void handlePong(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    85
  void handleProto(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    86
  void handleRedirect(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    87
  void handleRemoveTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    88
  void handleReplayStart(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    89
  void handleRoomAbandoned(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    90
  void handleRoom(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    91
  void handleRooms(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    92
  void handleRoundFinished(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    93
  void handleRunGame(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    94
  void handleServerAuth(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    95
  void handleServerMessage(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    96
  void handleServerVars(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    97
  void handleTeamAccepted(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    98
  void handleTeamColor(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
    99
  void handleWarning(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14936
diff changeset
   100
14936
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   101
  void send(const QString &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   102
  void send(const QString &message, const QString &param);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   103
  void send(const QString &message, const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   104
  void send(const QStringList &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   107
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   108
 private:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   109
  QUrl m_url;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   113
  QString m_nickname;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   114
  QString m_password;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   115
  QStringList m_buffer;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   121
};
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   122
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   123
#endif  // NET_SESSION_H