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:
parent
c9604f3dc1
commit
456dfd9e3d
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "../../lib/CConfigHandler.h"
|
#include "../../lib/CConfigHandler.h"
|
||||||
#include "../../lib/MetaString.h"
|
#include "../../lib/MetaString.h"
|
||||||
|
#include "../../lib/json/JsonUtils.h"
|
||||||
#include "../../lib/TextOperations.h"
|
#include "../../lib/TextOperations.h"
|
||||||
|
|
||||||
GlobalLobbyClient::GlobalLobbyClient() = default;
|
GlobalLobbyClient::GlobalLobbyClient() = default;
|
||||||
@ -273,6 +274,7 @@ void GlobalLobbyClient::onDisconnected(const std::shared_ptr<INetworkConnection>
|
|||||||
|
|
||||||
void GlobalLobbyClient::sendMessage(const JsonNode & data)
|
void GlobalLobbyClient::sendMessage(const JsonNode & data)
|
||||||
{
|
{
|
||||||
|
assert(JsonUtils::validate(data, "vcmi:lobbyProtocol/" + data["type"].String(), "network"));
|
||||||
networkConnection->sendPacket(data.toBytes());
|
networkConnection->sendPacket(data.toBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -362,5 +364,6 @@ void GlobalLobbyClient::sendProxyConnectionLogin(const NetworkConnectionPtr & ne
|
|||||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||||
toSend["gameRoomID"] = settings["lobby"]["roomID"];
|
toSend["gameRoomID"] = settings["lobby"]["roomID"];
|
||||||
|
|
||||||
|
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
|
||||||
netConnection->sendPacket(toSend.toBytes());
|
netConnection->sendPacket(toSend.toBytes());
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ NetworkConnectionPtr LobbyServer::findGameRoom(const std::string & gameRoomID) c
|
|||||||
|
|
||||||
void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json)
|
void LobbyServer::sendMessage(const NetworkConnectionPtr & target, const JsonNode & json)
|
||||||
{
|
{
|
||||||
|
assert(JsonUtils::validate(json, "vcmi:lobbyProtocol/" + json["type"].String(), "network"));
|
||||||
target->sendPacket(json.toBytes());
|
target->sendPacket(json.toBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,6 +265,7 @@ JsonNode LobbyServer::parseAndValidateMessage(const std::vector<std::byte> & mes
|
|||||||
if (!JsonUtils::validate(json, schemaName, "network"))
|
if (!JsonUtils::validate(json, schemaName, "network"))
|
||||||
{
|
{
|
||||||
logGlobal->info("Json validation error encountered!");
|
logGlobal->info("Json validation error encountered!");
|
||||||
|
assert(0);
|
||||||
return JsonNode();
|
return JsonNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "CVCMIServer.h"
|
#include "CVCMIServer.h"
|
||||||
#include "../lib/CConfigHandler.h"
|
#include "../lib/CConfigHandler.h"
|
||||||
|
#include "../lib/json/JsonUtils.h"
|
||||||
|
|
||||||
GlobalLobbyProcessor::GlobalLobbyProcessor(CVCMIServer & owner)
|
GlobalLobbyProcessor::GlobalLobbyProcessor(CVCMIServer & owner)
|
||||||
: owner(owner)
|
: owner(owner)
|
||||||
@ -45,6 +46,8 @@ void GlobalLobbyProcessor::onDisconnected(const std::shared_ptr<INetworkConnecti
|
|||||||
JsonNode message;
|
JsonNode message;
|
||||||
message["type"].String() = "leaveGameRoom";
|
message["type"].String() = "leaveGameRoom";
|
||||||
message["accountID"].String() = proxy.first;
|
message["accountID"].String() = proxy.first;
|
||||||
|
|
||||||
|
assert(JsonUtils::validate(message, "vcmi:lobbyProtocol/" + message["type"].String(), "network"));
|
||||||
controlConnection->sendPacket(message.toBytes());
|
controlConnection->sendPacket(message.toBytes());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -122,6 +125,8 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
|
|||||||
toSend["gameRoomID"].String() = owner.uuid;
|
toSend["gameRoomID"].String() = owner.uuid;
|
||||||
toSend["accountID"] = settings["lobby"]["accountID"];
|
toSend["accountID"] = settings["lobby"]["accountID"];
|
||||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||||
|
|
||||||
|
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
|
||||||
connection->sendPacket(toSend.toBytes());
|
connection->sendPacket(toSend.toBytes());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -137,6 +142,8 @@ void GlobalLobbyProcessor::onConnectionEstablished(const std::shared_ptr<INetwor
|
|||||||
toSend["gameRoomID"].String() = owner.uuid;
|
toSend["gameRoomID"].String() = owner.uuid;
|
||||||
toSend["guestAccountID"].String() = guestAccountID;
|
toSend["guestAccountID"].String() = guestAccountID;
|
||||||
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
toSend["accountCookie"] = settings["lobby"]["accountCookie"];
|
||||||
|
|
||||||
|
assert(JsonUtils::validate(toSend, "vcmi:lobbyProtocol/" + toSend["type"].String(), "network"));
|
||||||
connection->sendPacket(toSend.toBytes());
|
connection->sendPacket(toSend.toBytes());
|
||||||
|
|
||||||
proxyConnections[guestAccountID] = connection;
|
proxyConnections[guestAccountID] = connection;
|
||||||
|
Loading…
Reference in New Issue
Block a user