qmlfrontend/net_session.cpp
author unC0Rr
Fri, 24 May 2019 16:01:30 +0200
changeset 15044 a4a058dcbbd6
parent 14920 a3ad06ac390e
child 15052 773beead236f
permissions -rw-r--r--
Add slots for all protocol messages
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
#include "net_session.h"
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     2
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     3
NetSession::NetSession(QObject *parent) : QObject(parent) {}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     4
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     5
QUrl NetSession::url() const { return m_url; }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     6
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     7
QAbstractSocket::SocketState NetSession::state() const {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     8
  if (m_socket)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
     9
    return m_socket->state();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    10
  else
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    11
    return QAbstractSocket::UnconnectedState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    12
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    13
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    14
void NetSession::open() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    15
  m_socket.reset(new QTcpSocket());
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    16
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    17
  connect(m_socket.data(), &QAbstractSocket::stateChanged, this,
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    18
          &NetSession::stateChanged);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    19
  connect(m_socket.data(), &QTcpSocket::readyRead, this,
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    20
          &NetSession::onReadyRead);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    21
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    22
  m_socket->connectToHost(m_url.host(),
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    23
                          static_cast<quint16>(m_url.port(46631)));
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    24
}
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
QString NetSession::nickname() const { return m_nickname; }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    27
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    28
QString NetSession::password() const { return m_password; }
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
NetSession::SessionState NetSession::sessionState() const {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    31
  return m_sessionState;
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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    34
void NetSession::setUrl(const QUrl &url) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    35
  if (m_url == url) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    36
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    37
  m_url = url;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    38
  emit urlChanged(m_url);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    39
}
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
void NetSession::setNickname(const QString &nickname) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    42
  if (m_nickname == nickname) return;
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
  m_nickname = nickname;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    45
  emit nicknameChanged(m_nickname);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    46
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    47
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    48
void NetSession::setPassword(const QString &password) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    49
  if (m_password == password) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    50
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    51
  m_password = password;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    52
  emit passwordChanged(m_password);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    53
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    54
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    55
void NetSession::close() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    56
  if (!m_socket.isNull()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    57
    m_socket->disconnectFromHost();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    58
    m_socket.clear();
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
    setSessionState(NotConnected);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    61
  }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    62
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    63
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    64
void NetSession::onReadyRead() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    65
  while (m_socket->canReadLine()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    66
    auto line = QString::fromUtf8(m_socket->readLine().simplified());
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    67
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    68
    if (line.isEmpty()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    69
      parseNetMessage(m_buffer);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    70
      m_buffer.clear();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    71
    } else {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    72
      m_buffer.append(line);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    73
    }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    74
  }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    75
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    76
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    77
void NetSession::parseNetMessage(const QStringList &message) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    78
  if (message.isEmpty()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    79
    qWarning() << "Empty net message received";
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    80
    return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    81
  }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    82
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    83
  qDebug() << "[SERVER]" << message;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    84
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    85
  using Handler = std::function<void(NetSession *, const QStringList &)>;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    86
  static QMap<QString, Handler> commandsMap{
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    87
      {"ADD_TEAM", &NetSession::handleAddTeam},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    88
      {"ASKPASSWORD", &NetSession::handleAskPassword},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    89
      {"BANLIST", &NetSession::handleBanList},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    90
      {"BYE", &NetSession::handleBye},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    91
      {"CFG", &NetSession::handleCfg},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    92
      {"CHAT", &NetSession::handleChat},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    93
      {"CLIENT_FLAGS", &NetSession::handleClientFlags},
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    94
      {"CONNECTED", &NetSession::handleConnected},
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    95
      {"EM", &NetSession::handleEm},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    96
      {"ERROR", &NetSession::handleError},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    97
      {"HH_NUM", &NetSession::handleHhNum},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    98
      {"INFO", &NetSession::handleInfo},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
    99
      {"JOINED", &NetSession::handleJoined},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   100
      {"JOINING", &NetSession::handleJoining},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   101
      {"KICKED", &NetSession::handleKicked},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   102
      {"LEFT", &NetSession::handleLeft},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   103
      {"LOBBY:JOINED", &NetSession::handleLobbyJoined},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   104
      {"LOBBY:LEFT", &NetSession::handleLobbyLeft},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   105
      {"NICK", &NetSession::handleNick},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   106
      {"NOTICE", &NetSession::handleNotice},
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   107
      {"PING", &NetSession::handlePing},
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   108
      {"PONG", &NetSession::handlePong},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   109
      {"PROTO", &NetSession::handleProto},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   110
      {"REDIRECT", &NetSession::handleRedirect},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   111
      {"REMOVE_TEAM", &NetSession::handleRemoveTeam},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   112
      {"REPLAY_START", &NetSession::handleReplayStart},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   113
      {"ROOMABANDONED", &NetSession::handleRoomAbandoned},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   114
      {"ROOM", &NetSession::handleRoom},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   115
      {"ROOMS", &NetSession::handleRooms},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   116
      {"ROUND_FINISHED", &NetSession::handleRoundFinished},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   117
      {"RUN_GAME", &NetSession::handleRunGame},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   118
      {"SERVER_AUTH", &NetSession::handleServerAuth},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   119
      {"SERVER_MESSAGE", &NetSession::handleServerMessage},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   120
      {"SERVER_VARS", &NetSession::handleServerVars},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   121
      {"TEAM_ACCEPTED", &NetSession::handleTeamAccepted},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   122
      {"TEAM_COLOR", &NetSession::handleTeamColor},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   123
      {"WARNING", &NetSession::handleWarning},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   124
  };
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   125
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   126
  auto handler =
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   127
      commandsMap.value(message[0], &NetSession::handleUnknownCommand);
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
  handler(this, message.mid(1));
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   130
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   131
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   132
void NetSession::handleConnected(const QStringList &parameters) {
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   133
  if (parameters.length() < 2 || parameters[1].toInt() < cMinServerVersion) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   134
    send("QUIT", "Server too old");
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   135
    emit error(tr("Server too old"));
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   136
    close();
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   137
  } else {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   138
    setSessionState(Login);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   139
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   140
    send("NICK", m_nickname);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   141
    send("PROTO", QString::number(cProtocolVersion));
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   142
  }
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   143
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   144
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   145
void NetSession::handlePing(const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   146
  send("PONG", parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   147
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   148
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   149
void NetSession::handleBye(const QStringList &parameters) { close(); }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   150
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   151
void NetSession::handleUnknownCommand(const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   152
  Q_UNUSED(parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   153
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   154
  qWarning() << "Command is not recognized";
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   155
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   156
15044
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   157
void NetSession::handleAddTeam(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   158
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   159
void NetSession::handleAskPassword(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   160
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   161
void NetSession::handleBanList(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   162
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   163
void NetSession::handleCfg(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   164
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   165
void NetSession::handleChat(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   166
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   167
void NetSession::handleClientFlags(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   168
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   169
void NetSession::handleEm(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   170
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   171
void NetSession::handleError(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   172
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   173
void NetSession::handleHhNum(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   174
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   175
void NetSession::handleInfo(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   176
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   177
void NetSession::handleJoined(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   178
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   179
void NetSession::handleJoining(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   180
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   181
void NetSession::handleKicked(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   182
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   183
void NetSession::handleLeft(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   184
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   185
void NetSession::handleLobbyJoined(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   186
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   187
void NetSession::handleLobbyLeft(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   188
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   189
void NetSession::handleNick(const QStringList &parameters) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   190
  if (parameters.length()) setNickname(parameters[0]);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   191
}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   192
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   193
void NetSession::handleNotice(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   194
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   195
void NetSession::handlePong(const QStringList &parameters) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   196
  Q_UNUSED(parameters)
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   197
}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   198
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   199
void NetSession::handleProto(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   200
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   201
void NetSession::handleRedirect(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   202
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   203
void NetSession::handleRemoveTeam(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   204
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   205
void NetSession::handleReplayStart(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   206
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   207
void NetSession::handleRoomAbandoned(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   208
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   209
void NetSession::handleRoom(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   210
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   211
void NetSession::handleRooms(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   212
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   213
void NetSession::handleRoundFinished(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   214
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   215
void NetSession::handleRunGame(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   216
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   217
void NetSession::handleServerAuth(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   218
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   219
void NetSession::handleServerMessage(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   220
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   221
void NetSession::handleServerVars(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   222
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   223
void NetSession::handleTeamAccepted(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   224
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   225
void NetSession::handleTeamColor(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   226
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   227
void NetSession::handleWarning(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14920
diff changeset
   228
14920
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   229
void NetSession::send(const QString &message) { send(QStringList(message)); }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   230
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   231
void NetSession::send(const QString &message, const QString &param) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   232
  send(QStringList{message, param});
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   233
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   234
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   235
void NetSession::send(const QString &message, const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   236
  send(QStringList(message) + parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   237
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   238
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   239
void NetSession::send(const QStringList &message) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   240
  Q_ASSERT(!m_socket.isNull());
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   241
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   242
  qDebug() << "[CLIENT]" << message;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   243
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   244
  m_socket->write(message.join('\n').toUtf8() + "\n\n");
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   245
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   246
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   247
void NetSession::setSessionState(NetSession::SessionState sessionState) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   248
  if (m_sessionState == sessionState) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   249
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   250
  m_sessionState = sessionState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   251
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   252
  emit sessionStateChanged(sessionState);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   253
}