qmlfrontend/net_session.cpp
author alfadur <mail@none>
Sat, 11 Jan 2020 01:06:41 +0300
changeset 15541 d122b65bdf6f
parent 15078 fb7a9b0119d3
child 15891 d52f5d8e75e6
permissions -rw-r--r--
reapply some simplifications
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14915
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
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
     3
#include <QUuid>
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
     4
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
     5
#include "players_model.h"
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
     6
#include "rooms_model.h"
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
     7
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
     8
NetSession::NetSession(QObject *parent)
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
     9
    : QObject(parent),
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    10
      m_playersModel(new PlayersListModel()),
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    11
      m_roomsModel(new RoomsListModel()),
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    12
      m_sessionState(NotConnected) {}
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    13
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    14
NetSession::~NetSession() { close(); }
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    15
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    16
QUrl NetSession::url() const { return m_url; }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    17
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    18
QAbstractSocket::SocketState NetSession::state() const {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    19
  if (m_socket)
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    20
    return m_socket->state();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    21
  else
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    22
    return QAbstractSocket::UnconnectedState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    23
}
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
void NetSession::open() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    26
  m_socket.reset(new QTcpSocket());
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
  connect(m_socket.data(), &QAbstractSocket::stateChanged, this,
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    29
          &NetSession::stateChanged);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    30
  connect(m_socket.data(), &QTcpSocket::readyRead, this,
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    31
          &NetSession::onReadyRead);
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
  m_socket->connectToHost(m_url.host(),
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    34
                          static_cast<quint16>(m_url.port(46631)));
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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    37
QString NetSession::nickname() const { return m_nickname; }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    38
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    39
NetSession::SessionState NetSession::sessionState() const {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    40
  return m_sessionState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    41
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    42
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    43
QString NetSession::room() const { return m_room; }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    44
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    45
QString NetSession::passwordHash() const { return m_passwordHash; }
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    46
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    47
void NetSession::setUrl(const QUrl &url) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    48
  if (m_url == url) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    49
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    50
  m_url = url;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    51
  emit urlChanged(m_url);
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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    54
void NetSession::setNickname(const QString &nickname) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    55
  if (m_nickname == nickname) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    56
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    57
  m_nickname = nickname;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    58
  emit nicknameChanged(m_nickname);
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
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    61
void NetSession::setPasswordHash(const QString &passwordHash) {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    62
  if (m_passwordHash == passwordHash) return;
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    63
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    64
  m_passwordHash = passwordHash;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    65
  emit passwordHashChanged(m_passwordHash);
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    66
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
    67
  if (m_sessionState == Authentication) sendPassword();
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    68
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    69
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    70
void NetSession::setRoom(const QString &room) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    71
  if (m_room == room) return;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    72
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    73
  m_room = room;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    74
  emit roomChanged(m_room);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    75
}
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    76
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    77
void NetSession::close() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    78
  if (!m_socket.isNull()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    79
    m_socket->disconnectFromHost();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    80
    m_socket.clear();
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
    setSessionState(NotConnected);
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
    83
    setRoom({});
14915
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
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    86
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    87
void NetSession::onReadyRead() {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    88
  while (m_socket->canReadLine()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    89
    auto line = QString::fromUtf8(m_socket->readLine().simplified());
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    90
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    91
    if (line.isEmpty()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    92
      parseNetMessage(m_buffer);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    93
      m_buffer.clear();
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    94
    } else {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    95
      m_buffer.append(line);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    96
    }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    97
  }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    98
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
    99
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   100
void NetSession::parseNetMessage(const QStringList &message) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   101
  if (message.isEmpty()) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   102
    qWarning() << "Empty net message received";
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   103
    return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   104
  }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   105
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   106
  qDebug() << "[SERVER]" << message;
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
  using Handler = std::function<void(NetSession *, const QStringList &)>;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   109
  static QMap<QString, Handler> commandsMap{
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   110
      {"ADD_TEAM", &NetSession::handleAddTeam},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   111
      {"ASKPASSWORD", &NetSession::handleAskPassword},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   112
      {"BANLIST", &NetSession::handleBanList},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   113
      {"BYE", &NetSession::handleBye},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   114
      {"CFG", &NetSession::handleCfg},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   115
      {"CHAT", &NetSession::handleChat},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   116
      {"CLIENT_FLAGS", &NetSession::handleClientFlags},
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   117
      {"CONNECTED", &NetSession::handleConnected},
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   118
      {"EM", &NetSession::handleEm},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   119
      {"ERROR", &NetSession::handleError},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   120
      {"HH_NUM", &NetSession::handleHhNum},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   121
      {"INFO", &NetSession::handleInfo},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   122
      {"JOINED", &NetSession::handleJoined},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   123
      {"JOINING", &NetSession::handleJoining},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   124
      {"KICKED", &NetSession::handleKicked},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   125
      {"LEFT", &NetSession::handleLeft},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   126
      {"LOBBY:JOINED", &NetSession::handleLobbyJoined},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   127
      {"LOBBY:LEFT", &NetSession::handleLobbyLeft},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   128
      {"NICK", &NetSession::handleNick},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   129
      {"NOTICE", &NetSession::handleNotice},
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   130
      {"PING", &NetSession::handlePing},
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   131
      {"PONG", &NetSession::handlePong},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   132
      {"PROTO", &NetSession::handleProto},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   133
      {"REDIRECT", &NetSession::handleRedirect},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   134
      {"REMOVE_TEAM", &NetSession::handleRemoveTeam},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   135
      {"REPLAY_START", &NetSession::handleReplayStart},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   136
      {"ROOMABANDONED", &NetSession::handleRoomAbandoned},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   137
      {"ROOM", &NetSession::handleRoom},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   138
      {"ROOMS", &NetSession::handleRooms},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   139
      {"ROUND_FINISHED", &NetSession::handleRoundFinished},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   140
      {"RUN_GAME", &NetSession::handleRunGame},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   141
      {"SERVER_AUTH", &NetSession::handleServerAuth},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   142
      {"SERVER_MESSAGE", &NetSession::handleServerMessage},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   143
      {"SERVER_VARS", &NetSession::handleServerVars},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   144
      {"TEAM_ACCEPTED", &NetSession::handleTeamAccepted},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   145
      {"TEAM_COLOR", &NetSession::handleTeamColor},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   146
      {"WARNING", &NetSession::handleWarning},
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   147
  };
14915
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
  auto handler =
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   150
      commandsMap.value(message[0], &NetSession::handleUnknownCommand);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   151
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   152
  handler(this, message.mid(1));
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
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   155
void NetSession::handleConnected(const QStringList &parameters) {
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   156
  if (parameters.length() < 2 || parameters[1].toInt() < cMinServerVersion) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   157
    send("QUIT", "Server too old");
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   158
    emit error(tr("Server too old"));
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   159
    close();
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   160
  } else {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   161
    setSessionState(Login);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   162
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   163
    send("NICK", m_nickname);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   164
    send("PROTO", QString::number(cProtocolVersion));
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   165
  }
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   166
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   167
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   168
void NetSession::handlePing(const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   169
  send("PONG", parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   170
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   171
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   172
void NetSession::handleBye(const QStringList &parameters) { close(); }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   173
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   174
void NetSession::handleUnknownCommand(const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   175
  Q_UNUSED(parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   176
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   177
  qWarning() << "Command is not recognized";
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   178
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   179
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   180
void NetSession::handleAddTeam(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   181
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   182
void NetSession::handleAskPassword(const QStringList &parameters) {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   183
  if (parameters.length() != 1 || parameters[0].length() < 16) {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   184
    qWarning("Bad ASKPASSWORD message");
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   185
    return;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   186
  }
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   187
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   188
  setSessionState(Authentication);
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   189
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   190
  m_serverSalt = parameters[0];
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   191
  m_clientSalt = QUuid::createUuid().toString();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   192
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   193
  if (m_passwordHash.isEmpty()) {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   194
    emit passwordAsked();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   195
  } else {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   196
    sendPassword();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   197
  }
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   198
}
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   199
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   200
void NetSession::handleBanList(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   201
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   202
void NetSession::handleCfg(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   203
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   204
void NetSession::handleChat(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   205
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   206
void NetSession::handleClientFlags(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   207
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   208
void NetSession::handleEm(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   209
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   210
void NetSession::handleError(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   211
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   212
void NetSession::handleHhNum(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   213
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   214
void NetSession::handleInfo(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   215
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   216
void NetSession::handleJoined(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   217
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   218
void NetSession::handleJoining(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   219
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   220
void NetSession::handleKicked(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   221
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   222
void NetSession::handleLeft(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   223
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   224
void NetSession::handleLobbyJoined(const QStringList &parameters) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   225
  for (auto player : parameters) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   226
    if (player == m_nickname) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   227
      // check if server is authenticated or no authentication was performed at
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   228
      // all
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   229
      if (!m_serverAuthHash.isEmpty()) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   230
        emit error(tr("Server authentication error"));
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   231
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   232
        close();
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   233
      }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   234
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   235
      setSessionState(Lobby);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   236
    }
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   237
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   238
    m_playersModel->addPlayer(player, false);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   239
  }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   240
}
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   241
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   242
void NetSession::handleLobbyLeft(const QStringList &parameters) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   243
  if (parameters.length() == 1) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   244
    m_playersModel->removePlayer(parameters[0]);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   245
  } else if (parameters.length() == 2) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   246
    m_playersModel->removePlayer(parameters[0], parameters[1]);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   247
  } else {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   248
    qWarning("Malformed LOBBY:LEFT message");
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   249
  }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   250
}
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   251
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   252
void NetSession::handleNick(const QStringList &parameters) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   253
  if (parameters.length()) setNickname(parameters[0]);
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   254
}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   255
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   256
void NetSession::handleNotice(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   257
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   258
void NetSession::handlePong(const QStringList &parameters) {
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   259
  Q_UNUSED(parameters)
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   260
}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   261
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   262
void NetSession::handleProto(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   263
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   264
void NetSession::handleRedirect(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   265
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   266
void NetSession::handleRemoveTeam(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   267
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   268
void NetSession::handleReplayStart(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   269
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   270
void NetSession::handleRoomAbandoned(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   271
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   272
void NetSession::handleRoom(const QStringList &parameters) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   273
  if (parameters.size() == 10 && parameters[0] == "ADD") {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   274
    m_roomsModel->addRoom(parameters.mid(1));
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   275
  } else if (parameters.length() == 11 && parameters[0] == "UPD") {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   276
    m_roomsModel->updateRoom(parameters[1], parameters.mid(2));
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   277
15047
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   278
    // keep track of room name so correct name is displayed
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   279
    if (m_room == parameters[1]) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   280
      setRoom(parameters[2]);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   281
    }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   282
  } else if (parameters.size() == 2 && parameters[0] == "DEL") {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   283
    m_roomsModel->removeRoom(parameters[1]);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   284
  }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   285
}
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   286
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   287
void NetSession::handleRooms(const QStringList &parameters) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   288
  if (parameters.size() % 9) {
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   289
    qWarning("Net: Malformed ROOMS message");
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   290
    return;
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   291
  }
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   292
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   293
  m_roomsModel->setRoomsList(parameters);
773beead236f Add handling of some messages, reuse models from the old frontend
unc0rr
parents: 15039
diff changeset
   294
}
15039
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   295
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   296
void NetSession::handleRoundFinished(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   297
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   298
void NetSession::handleRunGame(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   299
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   300
void NetSession::handleServerAuth(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   301
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   302
void NetSession::handleServerMessage(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   303
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   304
void NetSession::handleServerVars(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   305
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   306
void NetSession::handleTeamAccepted(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   307
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   308
void NetSession::handleTeamColor(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   309
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   310
void NetSession::handleWarning(const QStringList &parameters) {}
a4a058dcbbd6 Add slots for all protocol messages
unC0Rr
parents: 14915
diff changeset
   311
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   312
void NetSession::send(const QString &message) { send(QStringList(message)); }
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   313
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   314
void NetSession::send(const QString &message, const QString &param) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   315
  send(QStringList{message, param});
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   316
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   317
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   318
void NetSession::send(const QString &message, const QStringList &parameters) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   319
  send(QStringList(message) + parameters);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   320
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   321
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   322
void NetSession::send(const QStringList &message) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   323
  Q_ASSERT(!m_socket.isNull());
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   324
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   325
  qDebug() << "[CLIENT]" << message;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   326
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   327
  m_socket->write(message.join('\n').toUtf8() + "\n\n");
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   328
}
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   329
15078
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   330
void NetSession::sendPassword() {
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   331
  /* When we got password hash, and server asked us for a password, perform
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   332
   * mutual authentication: at this point we have salt chosen by server. Client
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   333
   * sends client salt and hash of secret (password hash) salted with client
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   334
   * salt, server salt, and static salt (predefined string + protocol number).
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   335
   * Server should respond with hash of the same set in different order.
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   336
   */
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   337
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   338
  if (m_passwordHash.isEmpty() || m_serverSalt.isEmpty()) return;
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   339
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   340
  QString hash =
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   341
      QCryptographicHash::hash(m_clientSalt.toLatin1()
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   342
                                   .append(m_serverSalt.toLatin1())
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   343
                                   .append(m_passwordHash)
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   344
                                   .append(QByteArray::number(cProtocolVersion))
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   345
                                   .append("!hedgewars"),
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   346
                               QCryptographicHash::Sha1)
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   347
          .toHex();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   348
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   349
  m_serverHash =
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   350
      QCryptographicHash::hash(m_serverSalt.toLatin1()
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   351
                                   .append(m_clientSalt.toLatin1())
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   352
                                   .append(m_passwordHash)
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   353
                                   .append(QByteArray::number(cProtocolVersion))
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   354
                                   .append("!hedgewars"),
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   355
                               QCryptographicHash::Sha1)
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   356
          .toHex();
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   357
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   358
  send("PASSWORD", QStringList{hash, m_clientSalt});
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   359
}
fb7a9b0119d3 Copy authentication from the old frontend
unC0Rr
parents: 15047
diff changeset
   360
14915
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   361
void NetSession::setSessionState(NetSession::SessionState sessionState) {
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   362
  if (m_sessionState == sessionState) return;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   363
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   364
  m_sessionState = sessionState;
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   365
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   366
  emit sessionStateChanged(sessionState);
a3ad06ac390e Proof of concept for new net game client
unc0rr
parents:
diff changeset
   367
}