42 const std::function<
void(
const Message&)>& handler);
102 void disconnect(std::function<
void()> on_disconnected =
nullptr);
120 std::unique_ptr<
Router> router_{
nullptr};
121 std::unique_ptr<Client> client_{
nullptr};
122 std::unique_ptr<Host> host_{
nullptr};
Definition iEngineService.h:4
High-level peer-to-peer networking service managing host/client mode, message routing,...
Definition multiplayer_service.h:25
void unregister_handler(MessageType type)
Removes a previously registered handler for a message type.
static constexpr int16_t default_max_clients
Definition multiplayer_service.h:28
void set_max_clients(int amount) noexcept
PeerType get_peer_type() const
Returns the current peer type (host, client, or none).
void register_handler(MessageType type, const std::function< void(const Message &)> &handler)
Registers a callback handler for a specific message type.
void disconnect(std::function< void()> on_disconnected=nullptr)
Disconnect the active host or client gracefully.
int get_client_amount() const noexcept
void set_connection_port(int port) noexcept
void poll()
Polls the network. Behavior depends on host/client mode.
void start_server()
Starts the host server. Only valid in host-mode.
std::string get_uuid() const
MultiplayerService()
Initializes ENet and prepares the internal Router.
void connect(const std::string &address)
Connect to a remote server. Only valid in client-mode.
static constexpr int16_t default_connection_port
Definition multiplayer_service.h:27
std::string get_host_ip() const
ConnectionState get_connection_state() const noexcept
Returns connection state of the current mode.
void set_client()
Switches the service into client-mode. Invalidates any host instance.
void send_to_peer_via_uuid(const std::string &uuid, const Message &message)
Sends a message to a specific connected client (host mode only).
void send(const Message &message)
Sends a message. Host broadcasts; client sends to server.
void set_host()
Switches the service into host-mode. Invalidates any client instance.
int get_connection_port() const noexcept
Routes incoming network messages to registered handlers.
Definition router.h:11
ConnectionState
Definition connection_state.h:4
PeerType
Definition multiplayer_service.h:14
Represents a complete network message including type and payload.
Definition network_message.h:105
Represents either a default or custom message identifier.
Definition network_message.h:40