Add slots for all protocol messages
authorunC0Rr
Fri, 24 May 2019 16:01:30 +0200
changeset 15039 a4a058dcbbd6
parent 15038 01bb1d7ca14f
child 15040 0dbd06bf90f4
Add slots for all protocol messages
qmlfrontend/net_session.cpp
qmlfrontend/net_session.h
--- a/qmlfrontend/net_session.cpp	Fri May 24 14:55:48 2019 +0200
+++ b/qmlfrontend/net_session.cpp	Fri May 24 16:01:30 2019 +0200
@@ -84,9 +84,44 @@
 
   using Handler = std::function<void(NetSession *, const QStringList &)>;
   static QMap<QString, Handler> commandsMap{
+      {"ADD_TEAM", &NetSession::handleAddTeam},
+      {"ASKPASSWORD", &NetSession::handleAskPassword},
+      {"BANLIST", &NetSession::handleBanList},
+      {"BYE", &NetSession::handleBye},
+      {"CFG", &NetSession::handleCfg},
+      {"CHAT", &NetSession::handleChat},
+      {"CLIENT_FLAGS", &NetSession::handleClientFlags},
       {"CONNECTED", &NetSession::handleConnected},
+      {"EM", &NetSession::handleEm},
+      {"ERROR", &NetSession::handleError},
+      {"HH_NUM", &NetSession::handleHhNum},
+      {"INFO", &NetSession::handleInfo},
+      {"JOINED", &NetSession::handleJoined},
+      {"JOINING", &NetSession::handleJoining},
+      {"KICKED", &NetSession::handleKicked},
+      {"LEFT", &NetSession::handleLeft},
+      {"LOBBY:JOINED", &NetSession::handleLobbyJoined},
+      {"LOBBY:LEFT", &NetSession::handleLobbyLeft},
+      {"NICK", &NetSession::handleNick},
+      {"NOTICE", &NetSession::handleNotice},
       {"PING", &NetSession::handlePing},
-      {"BYE", &NetSession::handleBye}};
+      {"PONG", &NetSession::handlePong},
+      {"PROTO", &NetSession::handleProto},
+      {"REDIRECT", &NetSession::handleRedirect},
+      {"REMOVE_TEAM", &NetSession::handleRemoveTeam},
+      {"REPLAY_START", &NetSession::handleReplayStart},
+      {"ROOMABANDONED", &NetSession::handleRoomAbandoned},
+      {"ROOM", &NetSession::handleRoom},
+      {"ROOMS", &NetSession::handleRooms},
+      {"ROUND_FINISHED", &NetSession::handleRoundFinished},
+      {"RUN_GAME", &NetSession::handleRunGame},
+      {"SERVER_AUTH", &NetSession::handleServerAuth},
+      {"SERVER_MESSAGE", &NetSession::handleServerMessage},
+      {"SERVER_VARS", &NetSession::handleServerVars},
+      {"TEAM_ACCEPTED", &NetSession::handleTeamAccepted},
+      {"TEAM_COLOR", &NetSession::handleTeamColor},
+      {"WARNING", &NetSession::handleWarning},
+  };
 
   auto handler =
       commandsMap.value(message[0], &NetSession::handleUnknownCommand);
@@ -95,7 +130,16 @@
 }
 
 void NetSession::handleConnected(const QStringList &parameters) {
-  setSessionState(Login);
+  if (parameters.length() < 2 || parameters[1].toInt() < cMinServerVersion) {
+    send("QUIT", "Server too old");
+    emit error(tr("Server too old"));
+    close();
+  } else {
+    setSessionState(Login);
+
+    send("NICK", m_nickname);
+    send("PROTO", QString::number(cProtocolVersion));
+  }
 }
 
 void NetSession::handlePing(const QStringList &parameters) {
@@ -110,6 +154,78 @@
   qWarning() << "Command is not recognized";
 }
 
+void NetSession::handleAddTeam(const QStringList &parameters) {}
+
+void NetSession::handleAskPassword(const QStringList &parameters) {}
+
+void NetSession::handleBanList(const QStringList &parameters) {}
+
+void NetSession::handleCfg(const QStringList &parameters) {}
+
+void NetSession::handleChat(const QStringList &parameters) {}
+
+void NetSession::handleClientFlags(const QStringList &parameters) {}
+
+void NetSession::handleEm(const QStringList &parameters) {}
+
+void NetSession::handleError(const QStringList &parameters) {}
+
+void NetSession::handleHhNum(const QStringList &parameters) {}
+
+void NetSession::handleInfo(const QStringList &parameters) {}
+
+void NetSession::handleJoined(const QStringList &parameters) {}
+
+void NetSession::handleJoining(const QStringList &parameters) {}
+
+void NetSession::handleKicked(const QStringList &parameters) {}
+
+void NetSession::handleLeft(const QStringList &parameters) {}
+
+void NetSession::handleLobbyJoined(const QStringList &parameters) {}
+
+void NetSession::handleLobbyLeft(const QStringList &parameters) {}
+
+void NetSession::handleNick(const QStringList &parameters) {
+  if (parameters.length()) setNickname(parameters[0]);
+}
+
+void NetSession::handleNotice(const QStringList &parameters) {}
+
+void NetSession::handlePong(const QStringList &parameters) {
+  Q_UNUSED(parameters)
+}
+
+void NetSession::handleProto(const QStringList &parameters) {}
+
+void NetSession::handleRedirect(const QStringList &parameters) {}
+
+void NetSession::handleRemoveTeam(const QStringList &parameters) {}
+
+void NetSession::handleReplayStart(const QStringList &parameters) {}
+
+void NetSession::handleRoomAbandoned(const QStringList &parameters) {}
+
+void NetSession::handleRoom(const QStringList &parameters) {}
+
+void NetSession::handleRooms(const QStringList &parameters) {}
+
+void NetSession::handleRoundFinished(const QStringList &parameters) {}
+
+void NetSession::handleRunGame(const QStringList &parameters) {}
+
+void NetSession::handleServerAuth(const QStringList &parameters) {}
+
+void NetSession::handleServerMessage(const QStringList &parameters) {}
+
+void NetSession::handleServerVars(const QStringList &parameters) {}
+
+void NetSession::handleTeamAccepted(const QStringList &parameters) {}
+
+void NetSession::handleTeamColor(const QStringList &parameters) {}
+
+void NetSession::handleWarning(const QStringList &parameters) {}
+
 void NetSession::send(const QString &message) { send(QStringList(message)); }
 
 void NetSession::send(const QString &message, const QString &param) {
--- a/qmlfrontend/net_session.h	Fri May 24 14:55:48 2019 +0200
+++ b/qmlfrontend/net_session.h	Fri May 24 16:01:30 2019 +0200
@@ -9,6 +9,9 @@
 class NetSession : public QObject {
   Q_OBJECT
 
+  const int cMinServerVersion = 3;
+  const int cProtocolVersion = 60;
+
   // clang-format off
   Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged)
   Q_PROPERTY(QAbstractSocket::SocketState state READ state NOTIFY stateChanged)
@@ -44,6 +47,8 @@
   void nicknameChanged(const QString &nickname);
   void passwordChanged(const QString &password);
   void sessionStateChanged(SessionState sessionState);
+  void warning(const QString &message);
+  void error(const QString &message);
 
  private slots:
   void onReadyRead();
@@ -52,6 +57,41 @@
   void handlePing(const QStringList &parameters);
   void handleBye(const QStringList &parameters);
   void handleUnknownCommand(const QStringList &parameters);
+  void handleAddTeam(const QStringList &parameters);
+  void handleAskPassword(const QStringList &parameters);
+  void handleBanList(const QStringList &parameters);
+  void handleCfg(const QStringList &parameters);
+  void handleChat(const QStringList &parameters);
+  void handleClientFlags(const QStringList &parameters);
+  void handleEm(const QStringList &parameters);
+  void handleError(const QStringList &parameters);
+  void handleHhNum(const QStringList &parameters);
+  void handleInfo(const QStringList &parameters);
+  void handleJoined(const QStringList &parameters);
+  void handleJoining(const QStringList &parameters);
+  void handleKicked(const QStringList &parameters);
+  void handleLeft(const QStringList &parameters);
+  void handleLobbyJoined(const QStringList &parameters);
+  void handleLobbyLeft(const QStringList &parameters);
+  void handleNick(const QStringList &parameters);
+  void handleNotice(const QStringList &parameters);
+  void handlePong(const QStringList &parameters);
+  void handleProto(const QStringList &parameters);
+  void handleRedirect(const QStringList &parameters);
+  void handleRemoveTeam(const QStringList &parameters);
+  void handleReplayStart(const QStringList &parameters);
+  void handleRoomAbandoned(const QStringList &parameters);
+  void handleRoom(const QStringList &parameters);
+  void handleRooms(const QStringList &parameters);
+  void handleRoundFinished(const QStringList &parameters);
+  void handleRunGame(const QStringList &parameters);
+  void handleServerAuth(const QStringList &parameters);
+  void handleServerMessage(const QStringList &parameters);
+  void handleServerVars(const QStringList &parameters);
+  void handleTeamAccepted(const QStringList &parameters);
+  void handleTeamColor(const QStringList &parameters);
+  void handleWarning(const QStringList &parameters);
+
   void send(const QString &message);
   void send(const QString &message, const QString &param);
   void send(const QString &message, const QStringList &parameters);