#pragma once #include "settlement/core/world.hpp" #include #include #include #include namespace settlement::viewer { enum class LanState { Offline, Hosting, HostConnected, Connecting, GuestConnected, GuestDisconnected }; inline constexpr std::uint16_t colony_lan_port = 41727; struct LanRejection { CommandStatus status; CommandKind kind; GridPosition cell; std::uint8_t value; GridPosition destination; }; class LanSession { public: LanSession(); ~LanSession(); LanSession(const LanSession&) = delete; LanSession& operator=(const LanSession&) = delete; void host(std::uint16_t port = colony_lan_port, bool loopback_only = false); void join(std::string address, std::string code, std::uint16_t port = colony_lan_port); void reconnect(); void leave() noexcept; [[nodiscard]] LanState state() const noexcept; [[nodiscard]] bool is_guest() const noexcept; [[nodiscard]] std::string join_code() const; [[nodiscard]] std::uint16_t port() const noexcept; [[nodiscard]] const std::string& detail() const noexcept; [[nodiscard]] bool submit(CommandKind kind, GridPosition cell, std::uint8_t value, GridPosition destination = {}, AgentId resident = 0); [[nodiscard]] std::optional take_rejection() noexcept; [[nodiscard]] std::unique_ptr poll(World& world); private: struct Impl; std::unique_ptr impl_; }; [[nodiscard]] std::string local_lan_addresses(); } // namespace settlement::viewer