1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Added debug validation of lobby protocol on every send/receive

This commit is contained in:
Ivan Savenko 2024-03-04 22:13:06 +02:00
parent c9604f3dc1
commit 456dfd9e3d
3 changed files with 12 additions and 0 deletions

View File

@ -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());
}

View File

@ -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();
}

View File

@ -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;