#pragma once #include "IGameServer.h" #include "IGameServerLifecycle.h" namespace FRG { class LocalGameServerHost; class RemoteGameServerHost; struct LocationConfig; // In-process implementation used by single-player. GameState exists exactly // once, here; clients see immutable snapshots and mutate it with typed commands. class InternalGameServer final : public IGameServer, public IGameServerLifecycle { public: InternalGameServer(); std::shared_ptr snapshot() const override; const std::string& localPlayerId() const override { return localPlayerId_; } void submit(const GameCommand& command) override; std::vector drainEvents() override; void update(std::int64_t deltaMs) override; void save(nlohmann::json& out) const override; void load(const nlohmann::json& in) override; void setLocalPlayerId(std::string playerId) { localPlayerId_ = std::move(playerId); } void startCampaign( const CampaignConfig& campaign, const std::string& zipFile, bool createLocalPlayer, bool enableTestBot) override; bool prepareLocation(const LocationConfig& config) override; void activateLocation(const std::string& locationId) override; private: friend class LocalGameServerHost; friend class RemoteGameServerHost; friend class WebsocketGameClient; // Host-only lifecycle operations. They never expose authoritative state and // are intentionally absent from IGameServer. void initializeCampaign( const std::string& campaignId, const std::string& questsPath, const std::string& zipFile); void clearCampaign(); void resetCampaign(const std::string& questsPath, const std::string& zipFile); void publishMutation(); void ensureBattleZoneTestBot(); void updateBattleZoneTestBot(std::int64_t deltaMs); GameSnapshot buildSnapshot() const; GameState state_; std::string localPlayerId_ = "player1"; std::string resourceZipFile_; std::vector networkPlayerSlots_; std::int64_t battleZoneTestBotElapsedMs_ = 0; bool battleZoneTestBotEnabled_ = false; std::string pendingSimulationLocationId_; LocationSimulationEvents pendingSimulationEvents_; std::vector> pendingTriggerZoneUpdates_; std::uint64_t revision_ = 1; mutable std::uint64_t cachedRevision_ = 0; mutable std::shared_ptr cachedSnapshot_; std::vector pendingEvents_; }; } // namespace FRG