qmlfrontend/net_session.h
author Wuzzy <Wuzzy2@mail.ru>
Fri, 24 May 2019 22:26:47 +0200
changeset 15050 9f6e3be10e96
parent 15044 a4a058dcbbd6
child 15052 773beead236f
permissions -rw-r--r--
Use capgrpMessage2 for eidHomerun so it doesn't collide with death msgs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14920
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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     9
class NetSession : public QObject {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    10
  Q_OBJECT
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    11
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    12
  const int cMinServerVersion = 3;
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    13
  const int cProtocolVersion = 60;
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    14
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    15
  // clang-format off
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    16
  Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    17
  Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    18
  Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY nicknameChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    19
  Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    20
  Q_PROPERTY(SessionState sessionState READ sessionState NOTIFY sessionStateChanged)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    21
  // clang-format on
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    22
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    23
 public:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    24
  enum SessionState { NotConnected, Login, Lobby, Room, Game };
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    25
  Q_ENUMS(SessionState)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    26
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    27
  explicit NetSession(QObject *parent = nullptr);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    28
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    29
  QUrl url() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    30
  QAbstractSocket::SocketState state() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    31
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    32
  Q_INVOKABLE void open();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    33
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    34
  QString nickname() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    35
  QString password() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    36
  SessionState sessionState() const;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    37
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    38
 public slots:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    39
  void setUrl(const QUrl &url);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    40
  void setNickname(const QString &nickname);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    41
  void setPassword(const QString &password);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    42
  void close();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    43
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    44
 signals:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    45
  void urlChanged(const QUrl url);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    46
  void stateChanged(QAbstractSocket::SocketState state);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    47
  void nicknameChanged(const QString &nickname);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    48
  void passwordChanged(const QString &password);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    49
  void sessionStateChanged(SessionState sessionState);
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    50
  void warning(const QString &message);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    51
  void error(const QString &message);
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    52
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    53
 private slots:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    54
  void onReadyRead();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    55
  void parseNetMessage(const QStringList &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    56
  void handleConnected(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    57
  void handlePing(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    58
  void handleBye(const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    59
  void handleUnknownCommand(const QStringList &parameters);
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    60
  void handleAddTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    61
  void handleAskPassword(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    62
  void handleBanList(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    63
  void handleCfg(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    64
  void handleChat(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    65
  void handleClientFlags(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    66
  void handleEm(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    67
  void handleError(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    68
  void handleHhNum(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    69
  void handleInfo(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    70
  void handleJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    71
  void handleJoining(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    72
  void handleKicked(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    73
  void handleLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    74
  void handleLobbyJoined(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    75
  void handleLobbyLeft(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    76
  void handleNick(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    77
  void handleNotice(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    78
  void handlePong(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    79
  void handleProto(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    80
  void handleRedirect(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    81
  void handleRemoveTeam(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    82
  void handleReplayStart(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    83
  void handleRoomAbandoned(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    84
  void handleRoom(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    85
  void handleRooms(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    86
  void handleRoundFinished(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    87
  void handleRunGame(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    88
  void handleServerAuth(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    89
  void handleServerMessage(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    90
  void handleServerVars(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    91
  void handleTeamAccepted(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    92
  void handleTeamColor(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    93
  void handleWarning(const QStringList &parameters);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    94
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    95
  void send(const QString &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    96
  void send(const QString &message, const QString &param);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    97
  void send(const QString &message, const QStringList &parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    98
  void send(const QStringList &message);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    99
  void setSessionState(SessionState sessionState);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   100
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   101
 private:
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   102
  QUrl m_url;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   103
  QSharedPointer<QTcpSocket> m_socket;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   104
  QString m_nickname;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   105
  QString m_password;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   106
  QStringList m_buffer;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   107
  SessionState m_sessionState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   108
};
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   109
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   110
#endif  // NET_SESSION_H