Working on the server
This commit is contained in:
1 parent
075750442f
commit
28c6e83eda
30 files changed
+646
-362
No files matched your search
@@ -16,10 +16,69 @@ int fail(const char* message)
|
||||
|
||||
int main()
|
||||
{
|
||||
FRG::ClientLocationState localState;
|
||||
auto camera = localState.getOrCreate("test_location");
|
||||
camera->cameraAzimuth = 0.75f;
|
||||
camera->cameraInclination = 1.25f;
|
||||
nlohmann::json localJson;
|
||||
localState.save(localJson);
|
||||
FRG::ClientLocationState restoredLocalState;
|
||||
restoredLocalState.load(localJson);
|
||||
const auto restoredCamera =
|
||||
restoredLocalState.getOrCreate("test_location");
|
||||
if (restoredCamera->cameraAzimuth != 0.75f ||
|
||||
restoredCamera->cameraInclination != 1.25f) {
|
||||
return fail("Local camera state did not round trip");
|
||||
}
|
||||
|
||||
FRG::LocationNetworkState networkLocationState;
|
||||
nlohmann::json networkLocationJson;
|
||||
networkLocationState.save(networkLocationJson);
|
||||
if (networkLocationJson.contains("cameraAzimuth") ||
|
||||
networkLocationJson.contains("cameraInclination")) {
|
||||
return fail("Network location state contains local camera fields");
|
||||
}
|
||||
|
||||
const nlohmann::json authoritativeJson{
|
||||
{"schemaVersion", FRG::GameState::kSchemaVersion},
|
||||
{"campaignId", "test"}
|
||||
};
|
||||
nlohmann::json persistenceJson;
|
||||
FRG::saveSinglePlayerPersistence(
|
||||
authoritativeJson, localState, persistenceJson);
|
||||
nlohmann::json restoredAuthoritativeJson;
|
||||
FRG::ClientLocationState restoredPersistenceLocalState;
|
||||
FRG::loadSinglePlayerPersistence(
|
||||
persistenceJson, restoredAuthoritativeJson,
|
||||
restoredPersistenceLocalState);
|
||||
if (restoredAuthoritativeJson != authoritativeJson ||
|
||||
restoredPersistenceLocalState.getOrCreate("test_location")
|
||||
->cameraAzimuth != 0.75f) {
|
||||
return fail("Composed single-player state did not round trip");
|
||||
}
|
||||
if (persistenceJson.at("networkState").contains("localState")) {
|
||||
return fail("Local state leaked into authoritative state");
|
||||
}
|
||||
|
||||
const std::filesystem::path repositoryRoot =
|
||||
std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
|
||||
std::filesystem::current_path(repositoryRoot);
|
||||
|
||||
FRG::CampaignRegistry::instance().loadFromJson(
|
||||
"resources/config/campaigns.json");
|
||||
const FRG::CampaignConfig* singlePlayerBattleZone =
|
||||
FRG::CampaignRegistry::instance().find("battle_zone");
|
||||
const FRG::CampaignConfig* multiplayerBattleZoneConfig =
|
||||
FRG::CampaignRegistry::instance().find("battle_zone_multiplayer");
|
||||
if (FRG::CampaignRegistry::instance().all().size() != 3 ||
|
||||
!singlePlayerBattleZone || !multiplayerBattleZoneConfig) {
|
||||
return fail("Expected three campaigns including both Battle Zone modes");
|
||||
}
|
||||
if (singlePlayerBattleZone->startStatePath !=
|
||||
multiplayerBattleZoneConfig->startStatePath) {
|
||||
return fail("Battle Zone modes do not share their initial state");
|
||||
}
|
||||
|
||||
FRG::LocationDefinition definition;
|
||||
definition.config.id = "test_location";
|
||||
|
||||
@@ -87,8 +146,12 @@ int main()
|
||||
}
|
||||
|
||||
FRG::InternalGameServer networkServer;
|
||||
networkServer.startCampaign(battleZone, {}, true, false);
|
||||
FRG::CampaignConfig multiplayerBattleZone = battleZone;
|
||||
multiplayerBattleZone.id = "battle_zone_multiplayer";
|
||||
networkServer.startCampaign(multiplayerBattleZone, {}, true, false);
|
||||
const auto networkSnapshot = networkServer.snapshot();
|
||||
if (networkSnapshot->campaignId != "battle_zone_multiplayer")
|
||||
return fail("Network campaign ID was not retained");
|
||||
if (networkSnapshot->players.count("player") != 1)
|
||||
return fail("Network campaign shared player was not created");
|
||||
if (networkSnapshot->players.count("battle_zone_test_bot") != 0)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "game_server/NetworkProtocol.h"
|
||||
#include "LocationState.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@@ -16,10 +17,14 @@ void require(bool condition, const char* message)
|
||||
|
||||
int main()
|
||||
{
|
||||
FRG::LocationNetworkState locationState;
|
||||
nlohmann::json savedLocationState;
|
||||
locationState.save(savedLocationState);
|
||||
const nlohmann::json original{
|
||||
{"schemaVersion", 1},
|
||||
{"campaignId", "battle_zone"},
|
||||
{"players", {{"player", {{"hp", 200.0}}}}}
|
||||
{"schemaVersion", 2},
|
||||
{"campaignId", "battle_zone_multiplayer"},
|
||||
{"players", {{"player", {{"hp", 200.0}}}}},
|
||||
{"locations", {{"uni_exterior", {{"state", savedLocationState}}}}}
|
||||
};
|
||||
const std::string message = FRG::makeStateMessage(original);
|
||||
nlohmann::json parsed;
|
||||
@@ -28,6 +33,10 @@ int main()
|
||||
FRG::parseStateMessage(message, parsed, error),
|
||||
"valid state envelope was rejected");
|
||||
require(parsed == original, "state payload did not round trip");
|
||||
require(
|
||||
!parsed["locations"]["uni_exterior"]["state"].contains("cameraAzimuth") &&
|
||||
!parsed["locations"]["uni_exterior"]["state"].contains("cameraInclination"),
|
||||
"local camera state leaked into the network payload");
|
||||
|
||||
require(
|
||||
!FRG::parseStateMessage(
|
||||
|
||||
Reference in new issue
Block a user