浏览代码

Added debug validation of lobby protocol on every send/receive

Ivan Savenko 1 年之前
父节点
当前提交
456dfd9e3d
共有 3 个文件被更改,包括 12 次插入0 次删除
  1. 3 0
      client/globalLobby/GlobalLobbyClient.cpp
  2. 2 0
      lobby/LobbyServer.cpp
  3. 7 0
      server/GlobalLobbyProcessor.cpp

+ 3 - 0
client/globalLobby/GlobalLobbyClient.cpp

@@ -22,6 +22,7 @@
 
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/MetaString.h"
+#include "../../lib/json/JsonUtils.h"
 #include "../../lib/TextOperations.h"
 
 GlobalLobbyClient::GlobalLobbyClient() = default;
@@ -273,6 +274,7 @@ void GlobalLobbyClient::onDisconnected(const std::shared_ptr<INetworkConnection>
 
 void GlobalLobbyClient::sendMessage(const JsonNode & data)
 {
+	assert(JsonUtils::validate(data, "vcmi:lobbyProtocol/" + data["type"].String(), "network"));
 	networkConnection->sendPacket(data.toBytes());
 }
 
@@ -362,5 +364,6 @@ void GlobalLobbyClient::sendProxyConnectionLogin(const NetworkConnectionPtr & ne
 	toSend["accountCookie"] = settings["lobby"]["accountCookie"];
 	toSend["gameRoomID"] = settings["lobby"]["roomID"];
 
+	assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
 	netConnection->sendPacket(toSend.toBytes());
 }

+ 2 - 0
lobby/LobbyServer.cpp

@@ -60,6 +60,7 @@ NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) c
 
 void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json)
 {
+	assert(JsonUtils::validate(json, "vcmi:lobbyProtocol/" + json["type"].String(), "network"));
 	target->sendPacket(json.toBytes());
 }
 
@@ -264,6 +265,7 @@ JsonNode LobbyServer::parseAndValidateMessage(const std::vector<std::byte> & mes
 	if (!JsonUtils::validate(json, schemaName, "network"))
 	{
 		logGlobal->info("Json validation error encountered!");
+		assert(0);
 		return JsonNode();
 	}
 

+ 7 - 0
server/GlobalLobbyProcessor.cpp

@@ -12,6 +12,7 @@
 
 #include "CVCMIServer.h"
 #include "../lib/CConfigHandler.h"
+#include "../lib/json/JsonUtils.h"
 
 GlobalLobbyProcessor::GlobalLobbyProcessor(CVCMIServer & owner)
 	: owner(owner)
@@ -45,6 +46,8 @@ void GlobalLobbyProcessor::onDisconnected(const std::shared_ptr<INetworkConnecti
 					JsonNode message;
 					message["type"].String() = "leaveGameRoom";
 					message["accountID"].String() = proxy.first;
+
+					assert(JsonUtils::validate(message, "vcmi:lobbyProtocol/" + message["type"].String(), "network"));
 					controlConnection->sendPacket(message.toBytes());
 					break;
 				}
@@ -122,6 +125,8 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
 		toSend["gameRoomID"].String() = owner.uuid;
 		toSend["accountID"] = settings["lobby"]["accountID"];
 		toSend["accountCookie"] = settings["lobby"]["accountCookie"];
+
+		assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
 		connection->sendPacket(toSend.toBytes());
 	}
 	else
@@ -137,6 +142,8 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
 		toSend["gameRoomID"].String() = owner.uuid;
 		toSend["guestAccountID"].String() = guestAccountID;
 		toSend["accountCookie"] = settings["lobby"]["accountCookie"];
+
+		assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
 		connection->sendPacket(toSend.toBytes());
 
 		proxyConnections[guestAccountID] = connection;