|
|
Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
|
ENet client connection and protocol endpoint. More...
#include <NetClient.h>
Classes | |
| struct | ClientLiveStats |
| Live multiplayer/network HUD state updated during gameplay. More... | |
| struct | GameplayEvent |
| One reliable gameplay event dequeued in original receive order. More... | |
| struct | Impl |
Public Member Functions | |
| NetClient () | |
| Constructs an idle client with no active transport. | |
| ~NetClient () noexcept | |
| Disconnects locally if needed and releases ENet resources. | |
| NetClient (const NetClient &)=delete | |
| Non-copyable. | |
| NetClient & | operator= (const NetClient &)=delete |
| NetClient (NetClient &&)=delete | |
| Non-movable. | |
| NetClient & | operator= (NetClient &&)=delete |
| void | beginConnect (const std::string &host, uint16_t port, std::string_view playerName) |
| Starts a non-blocking connect attempt. | |
| bool | disconnectBlocking () |
| Attempts a blocking graceful disconnect, then releases local transport resources. | |
| void | disconnectAsync () |
| Starts a non-blocking graceful disconnect for an active session. | |
| void | cancelConnect () |
| Cancels an in-progress connect or handshake attempt. | |
| void | pumpNetwork (uint16_t timeoutMs=0) |
| Pumps ENet events for this client host. | |
| std::optional< uint32_t > | sendInput (uint8_t buttons) |
| Records a button bitmask and queues a batched input packet. | |
| bool | sendLobbyReady (bool ready) |
| Sends an authoritative lobby ready-state request for the local accepted seat. | |
| bool | sendMatchLoaded (uint32_t matchId) |
Acknowledges that the gameplay scene for matchId has been constructed locally. | |
| void | flushOutgoing () const |
| Flushes any queued outgoing ENet packets immediately. | |
| bool | isConnected () const |
| Returns true when an active session is connected. | |
| EConnectState | connectState () const |
| Returns the current connection state. | |
| const std::optional< MsgReject::EReason > & | lastRejectReason () const |
| Returns the last explicit server reject reason, if any. | |
| void | setDiagnosticsConfig (bool enabled, bool predictionEnabled, bool remoteSmoothingEnabled) |
| Configures client diagnostics behavior for future connect sessions. | |
| ClientDiagnostics & | clientDiagnostics () |
| Returns the client diagnostics recorder. | |
| const ClientDiagnostics & | clientDiagnostics () const |
| Returns the client diagnostics recorder. | |
| void | updateLiveTransportStats (uint32_t rttMs, uint32_t rttVarianceMs, uint32_t lossPermille, uint32_t lastSnapshotTick, uint32_t lastCorrectionTick, uint32_t snapshotAgeMs, uint32_t gameplaySilenceMs) |
| Updates the live transport portion of the multiplayer HUD state. | |
| void | updateLivePredictionStats (bool predictionActive, bool recoveryActive, uint32_t correctionCount, uint32_t mismatchCount, uint32_t lastCorrectionDeltaQ, uint32_t maxPendingInputDepth) |
| Updates the live prediction portion of the multiplayer HUD state. | |
| const ClientLiveStats & | liveStats () const |
| Returns the current live multiplayer HUD state. | |
| uint8_t | playerId () const |
| Returns the server-assigned player id, or NetClient::kInvalidPlayerId before connect. | |
| uint16_t | serverTickRate () const |
| Returns negotiated server tick rate. Valid only after a successful handshake. | |
| bool | tryGetLatestLobbyState (MsgLobbyState &out) const |
| Copies the newest cached lobby state for the current session. | |
| uint32_t | lobbySilenceMs () const |
| Returns milliseconds since the last authoritative lobby-state update. | |
| bool | consumePendingLevelInfo (MsgLevelInfo &out) |
Consumes the newest unhandled round-start LevelInfo for the current session. | |
| bool | tryGetLatestSnapshot (MsgSnapshot &out) const |
| Copies the newest cached snapshot for the current session. | |
| uint32_t | lastSnapshotTick () const |
| Returns the server tick of the newest cached snapshot, or 0 if none is cached. | |
| bool | tryGetLatestCorrection (MsgCorrection &out) const |
| Copies the newest cached owner correction for the current session. | |
| uint32_t | lastCorrectionTick () const |
| Returns the server tick of the newest cached correction, or 0 if none is cached. | |
| bool | tryDequeueGameplayEvent (GameplayEvent &out) |
| Pops the oldest pending reliable gameplay event for the current session. | |
| bool | hasBrokenGameplayEventStream () const |
| Returns true once the reliable gameplay-event stream can no longer be trusted. | |
| uint32_t | gameplaySilenceMs () const |
| Returns milliseconds since the last snapshot or correction. | |
| bool | tryGetLatestMatchStart (MsgMatchStart &out) const |
| Copies the newest cached match-start timing edge for the current session. | |
| bool | hasMatchStarted (uint32_t matchId) const |
Returns true after the server has explicitly started matchId for this session. | |
| bool | isMatchCancelled (uint32_t matchId) const |
Returns true after the server has explicitly cancelled matchId back to the lobby. | |
| bool | tryGetLatestMatchResult (MsgMatchResult &out) const |
| Copies the newest cached authoritative match result for the current session. | |
| bool | tryGetMapSeed (uint32_t &outSeed) const |
Returns the cached map seed from the current session's latest LevelInfo. | |
Static Public Attributes | |
| static constexpr uint8_t | kInvalidPlayerId = 0xFF |
| Sentinel value indicating no player id has been assigned yet. | |
ENet client connection and protocol endpoint.
Owns the client-side ENet host and peer lifecycle, drives the async connect and handshake flow, pumps incoming packets, caches the latest session data, and sends runtime input batches during gameplay.
A session is considered connected once Welcome has been received successfully.
| void bomberman::net::NetClient::beginConnect | ( | const std::string & | host, |
| uint16_t | port, | ||
| std::string_view | playerName | ||
| ) |
Starts a non-blocking connect attempt.
| host | Server hostname or IP address. |
| port | Server port. |
| playerName | Player name sent in the Hello payload. |
If transport setup succeeds, the client enters Connecting. Connected state means the server accepted the session and the client may enter lobby flow immediately.
| void bomberman::net::NetClient::cancelConnect | ( | ) |
Cancels an in-progress connect or handshake attempt.
Safe to call in any state. If the client is currently Connecting or Handshaking, transport resources are released and state returns to Disconnected. Otherwise, this is a no-op.
| bool bomberman::net::NetClient::consumePendingLevelInfo | ( | MsgLevelInfo & | out | ) |
Consumes the newest unhandled round-start LevelInfo for the current session.
Returns false until a newer LevelInfo arrives. Once returned successfully, the same cached message is not returned again until a later LevelInfo replaces it.
| void bomberman::net::NetClient::disconnectAsync | ( | ) |
Starts a non-blocking graceful disconnect for an active session.
If called during Connecting or Handshaking, the in-progress attempt is cancelled locally and state returns to Disconnected. Otherwise, connection state remains Disconnecting until NetClient::pumpNetwork observes completion or timeout.
| bool bomberman::net::NetClient::disconnectBlocking | ( | ) |
Attempts a blocking graceful disconnect, then releases local transport resources.
If called during Connecting or Handshaking, the in-progress attempt is cancelled locally and this returns false.
true if the remote disconnect handshake completed before local teardown. | uint32_t bomberman::net::NetClient::gameplaySilenceMs | ( | ) | const |
Returns milliseconds since the last snapshot or correction.
If gameplay traffic has not arrived yet for the current session, the timer runs from handshake completion instead.
| bool bomberman::net::NetClient::hasBrokenGameplayEventStream | ( | ) | const |
Returns true once the reliable gameplay-event stream can no longer be trusted.
The current client policy is fail-fast: if reliable gameplay events overflow locally, the active match should be abandoned instead of continuing with potentially divergent world state.
| uint32_t bomberman::net::NetClient::lobbySilenceMs | ( | ) | const |
Returns milliseconds since the last authoritative lobby-state update.
If no lobby-state update has arrived yet for the current session, the timer runs from handshake completion instead.
| void bomberman::net::NetClient::pumpNetwork | ( | uint16_t | timeoutMs = 0 | ) |
Pumps ENet events for this client host.
Evaluates connect and disconnect timeouts and dispatches any received protocol packets.
| timeoutMs | Maximum wait in milliseconds. Defaults to non-blocking. |
| std::optional< uint32_t > bomberman::net::NetClient::sendInput | ( | uint8_t | buttons | ) |
Records a button bitmask and queues a batched input packet.
| buttons | Button bitmask (kInput* flags). |
std::nullopt if the client is not currently connected. | bool bomberman::net::NetClient::sendLobbyReady | ( | bool | ready | ) |
Sends an authoritative lobby ready-state request for the local accepted seat.
The server remains the source of truth; successful sends are reflected back through later LobbyState updates.
true if the request was queued successfully. | bool bomberman::net::NetClient::sendMatchLoaded | ( | uint32_t | matchId | ) |
Acknowledges that the gameplay scene for matchId has been constructed locally.
This is a low-frequency reliable control message used only during the authoritative round-start handoff.
true if the request was queued successfully. | bool bomberman::net::NetClient::tryDequeueGameplayEvent | ( | GameplayEvent & | out | ) |
Pops the oldest pending reliable gameplay event for the current session.
Returns false when no pending event is queued or the reliable gameplay-event stream has been invalidated for the current match.
| bool bomberman::net::NetClient::tryGetLatestCorrection | ( | MsgCorrection & | out | ) | const |
Copies the newest cached owner correction for the current session.
Returns false if no valid correction has been received since the most recent successful connect.
| bool bomberman::net::NetClient::tryGetLatestLobbyState | ( | MsgLobbyState & | out | ) | const |
Copies the newest cached lobby state for the current session.
Returns false until at least one valid authoritative lobby-state message has been received for the current session.
| bool bomberman::net::NetClient::tryGetLatestSnapshot | ( | MsgSnapshot & | out | ) | const |
Copies the newest cached snapshot for the current session.
Returns false if no valid snapshot has been received since the most recent connect.
| bool bomberman::net::NetClient::tryGetMapSeed | ( | uint32_t & | outSeed | ) | const |
Returns the cached map seed from the current session's latest LevelInfo.
The cache is cleared on disconnect or reset. In lobby-only states no LevelInfo may have been received yet.