Implemented the real server
This commit is contained in:
1 parent
931236bec0
commit
075750442f
22 files changed
+1130
-44
No files matched your search
@@ -86,5 +86,13 @@ int main()
|
||||
return fail("Battle Zone test bot animation metadata was not loaded");
|
||||
}
|
||||
|
||||
FRG::InternalGameServer networkServer;
|
||||
networkServer.startCampaign(battleZone, {}, true, false);
|
||||
const auto networkSnapshot = networkServer.snapshot();
|
||||
if (networkSnapshot->players.count("player") != 1)
|
||||
return fail("Network campaign shared player was not created");
|
||||
if (networkSnapshot->players.count("battle_zone_test_bot") != 0)
|
||||
return fail("Network campaign unexpectedly created the test bot");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "game_server/NetworkProtocol.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
void require(bool condition, const char* message)
|
||||
{
|
||||
if (condition) return;
|
||||
std::cerr << "NetworkProtocolTests: " << message << '\n';
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
{
|
||||
const nlohmann::json original{
|
||||
{"schemaVersion", 1},
|
||||
{"campaignId", "battle_zone"},
|
||||
{"players", {{"player", {{"hp", 200.0}}}}}
|
||||
};
|
||||
const std::string message = FRG::makeStateMessage(original);
|
||||
nlohmann::json parsed;
|
||||
std::string error;
|
||||
require(
|
||||
FRG::parseStateMessage(message, parsed, error),
|
||||
"valid state envelope was rejected");
|
||||
require(parsed == original, "state payload did not round trip");
|
||||
|
||||
require(
|
||||
!FRG::parseStateMessage(
|
||||
R"({"protocolVersion":2,"type":"state","payload":{}})",
|
||||
parsed, error),
|
||||
"unknown protocol version was accepted");
|
||||
require(
|
||||
!FRG::parseStateMessage(
|
||||
R"({"protocolVersion":1,"type":"command","payload":{}})",
|
||||
parsed, error),
|
||||
"unknown message type was accepted");
|
||||
require(
|
||||
!FRG::parseStateMessage("not json", parsed, error),
|
||||
"malformed JSON was accepted");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user