// Copyright (c) 2026 Juhapekka Piiroinen // All Rights Reserved. // AmoosedWeb project: https://amoosed.com #pragma once #include "AmoosedWeb/Game.hpp" #include "AmoosedWeb/Reader.hpp" #include #include #include namespace amoosed { // An engine adapter owns one session per game instance. Refresh stages a new // verified index and catalogue, then swaps them together. A failed refresh // leaves the last verified in-memory snapshot available for offline play. // The member key is supplied per fetch and is never retained by this object. class GameSession { public: GameSession(std::string game_id, std::string game_version); bool refresh_hosted(HttpHost& http, CryptoHost& crypto, std::string& error, bool allow_rollback = false, MediaDecoder* media = nullptr, ReaderFailure* failure = nullptr); bool refresh_external(HttpHost& http, CryptoHost& crypto, std::string_view key_file, std::string& error, bool allow_rollback = false, MediaDecoder* media = nullptr, ReaderFailure* failure = nullptr); bool fetch_item(std::string_view item_id, const std::array* member_key, HttpHost& http, CryptoHost& crypto, OutputHost& output, DownloadResult& result, std::string& error, MediaDecoder* media = nullptr, ReaderFailure* failure = nullptr) const; bool ready() const { return ready_; } const GameCatalogue& catalogue() const { return catalogue_; } const std::string& index_digest() const { return index_digest_; } private: bool accept(IndexResult&& candidate, HttpHost& http, CryptoHost& crypto, std::string& error, bool allow_rollback, MediaDecoder* media, ReaderFailure* failure); std::string game_id_, game_version_, index_digest_; AppIndex index_; GameCatalogue catalogue_; bool ready_ = false; }; }