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

+39 -23
View File
@@ -552,7 +552,7 @@ namespace FRG
CampaignRegistry::instance().find(campaignId);
if (!campaign) return;
#if defined(NETWORK)
remoteCampaignActive = campaignId == "battle_zone";
remoteCampaignActive = campaignId == "battle_zone_multiplayer";
if (remoteCampaignActive) {
websocketGameClient = std::make_unique<WebsocketGameClient>();
remoteGameServerHost =
@@ -644,12 +644,7 @@ namespace FRG
});
loc->stopCharacter(*loc->player);
}
auto locationState = loc->stateSnapshot();
const float inclination = locationState
? locationState->cameraInclination
: 1.1036f;
server().submit(SetLocationCameraCommand{
destName, destRotY, inclination});
loc->localState().cameraAzimuth = destRotY;
loc->scriptEngine.callLocationEnterCallback();
//Reset taxi
@@ -1163,6 +1158,17 @@ namespace FRG
// The authoritative implementation advances simulation; a future
// network client can use the same call to poll/apply server updates.
gameServerHost.update(delta);
#if defined(NETWORK)
if (remoteCampaignActive && websocketGameClient &&
websocketGameClient->connectionFailed()) {
logger() << "[network] Connection failed; returning to campaign selection"
<< std::endl;
unloadCampaign();
menuManager.showMainMenu();
menuManager.showCampaignScreen();
return;
}
#endif
processServerEvents();
}
@@ -1524,11 +1530,9 @@ namespace FRG
currentLocation()->lastMouseY = eventY;
// Snapshot current angles so we can measure how far the user rotates.
auto state = currentLocation()->stateSnapshot();
if (state) {
dragStartAzimuth = state->cameraAzimuth;
dragStartInclination = state->cameraInclination;
}
const LocationLocalState& state = currentLocation()->localState();
dragStartAzimuth = state.cameraAzimuth;
dragStartInclination = state.cameraInclination;
}
}
@@ -1736,10 +1740,9 @@ namespace FRG
if (cameraDragging
&& game
&& game->tutorialStep == TutorialStep::RotateCamera) {
auto state = currentLocation()->stateSnapshot();
if (!state) return;
float deltaAz = std::abs(state->cameraAzimuth - dragStartAzimuth);
float deltaInc = std::abs(state->cameraInclination - dragStartInclination);
const LocationLocalState& state = currentLocation()->localState();
float deltaAz = std::abs(state.cameraAzimuth - dragStartAzimuth);
float deltaInc = std::abs(state.cameraInclination - dragStartInclination);
if (deltaAz >= TUTORIAL_ROTATION_THRESHOLD && deltaInc >= TUTORIAL_ROTATION_THRESHOLD) {
server().submit(
CompleteTutorialStepCommand{TutorialStep::RotateCamera});
@@ -1894,12 +1897,18 @@ namespace FRG
if (content.empty()) return {};
try {
nlohmann::json root = nlohmann::json::parse(content);
if (root.value("schemaVersion", -1) != GameState::kSchemaVersion) return {};
if (root.value("persistenceVersion", -1) !=
kSinglePlayerPersistenceVersion) return {};
const auto& networkState = root.at("networkState");
if (networkState.value("schemaVersion", -1) !=
GameState::kSchemaVersion) return {};
SaveSlotInfo info;
info.empty = false;
info.campaignId = root.at("campaignId").get<std::string>();
info.locationName = root.at("currentLocationId").get<std::string>();
info.savedAt = root.value("savedAt", "");
info.campaignId =
networkState.at("campaignId").get<std::string>();
info.locationName =
networkState.at("currentLocationId").get<std::string>();
info.savedAt = networkState.value("savedAt", "");
return info;
} catch (...) {
return {};
@@ -1937,12 +1946,19 @@ namespace FRG
return;
}
if (root.value("schemaVersion", -1) != GameState::kSchemaVersion) {
if (root.value("persistenceVersion", -1) !=
kSinglePlayerPersistenceVersion ||
!root.contains("networkState") ||
root["networkState"].value("schemaVersion", -1) !=
GameState::kSchemaVersion) {
std::cerr << "[save] Unsupported save schema in " << path << std::endl;
return;
}
const std::string campaignId = root.value("campaignId", std::string());
const std::string locationId = root.value("currentLocationId", std::string());
const auto& networkState = root["networkState"];
const std::string campaignId =
networkState.value("campaignId", std::string());
const std::string locationId =
networkState.value("currentLocationId", std::string());
const CampaignConfig* campaign = CampaignRegistry::instance().find(campaignId);
if (!campaign || !campaign->findLocation(locationId)) {
std::cerr << "[save] Unknown campaign/location in " << path << std::endl;