Jazz2::Multiplayer::NetworkManager class

Manages game-specific network connections.

Base classes

class NetworkManagerBase
Allows to create generic network clients and servers.

Public static functions

static auto CreateDefaultServerConfiguration() -> ServerConfiguration
Creates a default server configuration from the default template file.
static auto LoadServerConfigurationFromFile(StringView path) -> ServerConfiguration
Loads a server configuration from the specified file.
static auto GameModeToLocalizedString(MpGameMode mode) -> StringView
Converts MpGameMode to the localized string representation.
static auto StringToGameMode(StringView value) -> MpGameMode
Converts the non-localized string representation back to MpGameMode.

Constructors, destructors, conversion operators

NetworkManager()
~NetworkManager()
NetworkManager(const NetworkManager&) deleted

Public functions

auto operator=(const NetworkManager&) -> NetworkManager& deleted
void CreateClient(INetworkHandler* handler, StringView endpoints, std::uint16_t defaultPort, std::uint32_t clientData) override
Creates a client connection to a remote server.
auto CreateServer(INetworkHandler* handler, ServerConfiguration&& serverConfig) -> bool virtual
Creates a server that accepts incoming connections.
void Dispose() override
Disposes all active connections.
auto GetServerConfiguration() const -> ServerConfiguration&
Returns server configuration.
auto GetPeerCount() const -> std::uint32_t
Returns connected peer count.
auto GetPeers() const -> const HashMap<Peer, std::shared_ptr<PeerDescriptor>>&
Returns all connected peers.
auto GetPeerDescriptor(const Peer& peer) -> std::shared_ptr<PeerDescriptor>
Returns session peer descriptor for the specified connected peer.
auto HasInboundConnections() const -> bool
Returns true if there are any inbound connections.

Protected functions

auto OnPeerConnected(const Peer& peer, std::uint32_t clientData) -> ConnectionResult override
Called when a peer connects to the local server or the local client connects to a server.
void OnPeerDisconnected(const Peer& peer, Reason reason) override
Called when a peer disconnects from the local server or the local client disconnects from a server.

Function documentation

static ServerConfiguration Jazz2::Multiplayer::NetworkManager::CreateDefaultServerConfiguration()

Creates a default server configuration from the default template file.

This method reads a JSON configuration file described in ServerConfiguration. If the JSON contains a "$include" directive, it recursively loads the referenced files.

static ServerConfiguration Jazz2::Multiplayer::NetworkManager::LoadServerConfigurationFromFile(StringView path)

Loads a server configuration from the specified file.

This method reads a JSON configuration file described in ServerConfiguration. If the JSON contains a "$include" directive, it recursively loads the referenced files.