#pragma once #include #include #include #include #include #include "Client.hh" #include "Server.hh" #include "ServerState.hh" struct GameServerSocket : ServerSocket { Version version; ServerBehavior behavior; }; class GameServer : public Server, public std::enable_shared_from_this { public: GameServer() = delete; GameServer(const GameServer&) = delete; GameServer(GameServer&&) = delete; explicit GameServer(std::shared_ptr state); virtual ~GameServer() = default; void listen( const std::string& name, const std::string& addr, uint16_t port, Version version, ServerBehavior initial_state); std::shared_ptr connect_channel(std::shared_ptr ch, uint16_t port, ServerBehavior initial_state); std::shared_ptr get_client() const; std::vector> get_clients_by_identifier(const std::string& ident) const; inline std::shared_ptr get_state() const { return this->state; } protected: std::shared_ptr state; asio::awaitable handle_client_command(std::shared_ptr c, std::unique_ptr msg); [[nodiscard]] virtual std::shared_ptr create_client( std::shared_ptr listen_sock, asio::ip::tcp::socket&& client_sock); virtual asio::awaitable handle_client(std::shared_ptr c); virtual asio::awaitable destroy_client(std::shared_ptr c); };