51 lines
1.5 KiB
C++
51 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "settlement/core/world.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
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;
|
|
};
|
|
|
|
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<LanRejection> take_rejection() noexcept;
|
|
[[nodiscard]] std::unique_ptr<World> poll(World& world);
|
|
|
|
private:
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
[[nodiscard]] std::string local_lan_addresses();
|
|
|
|
} // namespace settlement::viewer
|