Working on the server

This commit is contained in:
Vladislav Khorev committed 2026-11-05 20:12:30 +06:00
1 parent 075750442f
commit 28c6e83eda
30 files changed
+646 -362

No files matched your search

+29 -1
View File
@@ -3,6 +3,8 @@
#include "game_server/WebsocketGameServer.h"
#endif
#include "Campaign.h"
#include "LocationState.h"
#include "utils/Utils.h"
#include <atomic>
#include <chrono>
#include <csignal>
@@ -88,7 +90,7 @@ int main(int argc, char** argv)
}
//Temporary override:
campaignId = "battle_zone";
campaignId = "battle_zone_multiplayer";
locationId = "uni_exterior";
std::signal(SIGINT, requestStop);
@@ -98,6 +100,7 @@ int main(int argc, char** argv)
if (!campaignId.empty()) {
try {
FRG::CampaignRegistry::instance().loadFromJson(campaignsPath);
std::cout << "[server] Loading...\n" << std::flush;
const FRG::CampaignConfig* campaign =
FRG::CampaignRegistry::instance().find(campaignId);
if (!campaign)
@@ -113,7 +116,32 @@ int main(int argc, char** argv)
"' has no location '" + selectedLocation + "'");
server.startCampaign(*campaign, std::string(), true, false);
server.prepareLocation(*location);
const std::string startState =
FRG::readTextFile(campaign->startStatePath);
if (!startState.empty()) {
try {
nlohmann::json persisted =
nlohmann::json::parse(startState);
nlohmann::json networkState;
FRG::ClientLocationState ignoredLocalState;
FRG::loadSinglePlayerPersistence(
persisted, networkState, ignoredLocalState);
networkState["campaignId"] = campaignId;
networkState["currentLocationId"] = selectedLocation;
server.load(networkState);
std::cout << "Loaded initial state '"
<< campaign->startStatePath << "'\n";
} catch (const std::exception& error) {
std::cerr << "Ignoring invalid initial state '"
<< campaign->startStatePath << "': "
<< error.what() << '\n';
}
}
server.activateLocation(selectedLocation);
if (!campaign->tutorial) {
server.submit(FRG::SetTutorialStepCommand{
FRG::TutorialStep::Completed});
}
std::cout << "Loaded campaign '" << campaignId
<< "', location '" << selectedLocation
<< "' with shared player '" << server.localPlayerId() << "'\n";