Jazz2::Multiplayer::NetworkManager class

Manages game-specific network connections.

Extends NetworkManagerBase with the game session layer: holds the ServerConfiguration, owns the per-peer PeerDescriptor map (including retained descriptors for reconnecting players), drives LAN ServerDiscovery, and overrides the connect/disconnect hooks to enforce server policy.

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 GameModeToString(MpGameMode mode) -> StringView
Converts MpGameMode to the string representation.
static auto StringToGameMode(StringView value) -> MpGameMode
Converts the non-localized string representation back to MpGameMode.
static auto UuidToString(StaticArrayView<Uuid::Size, Uuid::Type> uuid) -> String
Converts UUID to the string representation.

Constructors, destructors, conversion operators

NetworkManager()
Creates a new instance.
~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.
auto CreateLocalServer(INetworkHandler* handler, ServerConfiguration&& serverConfig) -> bool
Creates a socket-less local server for local splitscreen multiplayer.
void Dispose() override
Disposes all active connections.
auto GetServerConfiguration() const -> ServerConfiguration&
Returns server configuration.
auto GetPeerCount() -> std::uint32_t
Returns connected peer count.
auto GetPeers() -> LockedPtr<const HashMap<Peer, std::shared_ptr<PeerDescriptor>>, Spinlock>
Returns all connected peers.
auto GetPeerDescriptor(LocalPeerT) -> std::shared_ptr<PeerDescriptor>
Returns session peer descriptor for the local peer.
auto GetPeerDescriptor(LocalPeerT, std::int32_t index) -> std::shared_ptr<PeerDescriptor>
Returns the session peer descriptor for the local splitscreen player at the given index.
auto AddLocalPlayer(std::int32_t index) -> std::shared_ptr<PeerDescriptor>
Registers (or returns the existing) descriptor for a local splitscreen player.
auto GetPeerDescriptor(const Peer& peer) -> std::shared_ptr<PeerDescriptor>
Returns session peer descriptor for the specified connected remote peer.
auto ReclaimDisconnectedPeer(StaticArrayView<Uuid::Size, Uuid::Type> uuid) -> std::shared_ptr<PeerDescriptor>
Tries to reclaim a recently disconnected peer's descriptor by unique player ID.
void ClearDisconnectedPeerStates()
Clears the restorable state of all retained disconnected peers (e.g., when a new round starts).
auto HasInboundConnections() const -> bool
Returns true if there are any inbound connections.
void RefreshServerConfiguration()
Reloads server configuration from the source file.
void SetStatusProvider(std::weak_ptr<IServerStatusProvider> statusProvider)
Sets status provider.

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.

bool Jazz2::Multiplayer::NetworkManager::CreateLocalServer(INetworkHandler* handler, ServerConfiguration&& serverConfig)

Creates a socket-less local server for local splitscreen multiplayer.

Behaves like a server (authoritative game state, NetworkState::Local) but binds no socket and accepts no remote connections. Local players are registered with AddLocalPlayer().

std::shared_ptr<PeerDescriptor> Jazz2::Multiplayer::NetworkManager::GetPeerDescriptor(LocalPeerT, std::int32_t index)

Returns the session peer descriptor for the local splitscreen player at the given index.

Index zero is the default local peer (same as GetPeerDescriptor(LocalPeerT)). Returns nullptr if no such local player has been registered with AddLocalPlayer().

std::shared_ptr<PeerDescriptor> Jazz2::Multiplayer::NetworkManager::AddLocalPlayer(std::int32_t index)

Registers (or returns the existing) descriptor for a local splitscreen player.

The descriptor is inserted into the peer map under a synthetic local key (see Peer::Local) so the shared game-mode logic iterates it like any other player, while its PeerDescriptor::RemotePeer stays empty so it is treated as a local player. Index zero maps to the default local peer.

std::shared_ptr<PeerDescriptor> Jazz2::Multiplayer::NetworkManager::ReclaimDisconnectedPeer(StaticArrayView<Uuid::Size, Uuid::Type> uuid)

Tries to reclaim a recently disconnected peer's descriptor by unique player ID.

Lets a reconnecting player resume. Returns the retained descriptor (with its restorable state), or nullptr if there is none within the reconnect window.