Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
bomberman::net Namespace Reference

Shared multiplayer protocol types and transport-facing wire helpers. More...

Classes

class  ClientDiagnostics
 Client-side multiplayer diagnostics recorder owned by NetClient. More...
 
struct  ClientKeyMessageAggregates
 Sparse per-message aggregates retained for client diagnostics and tuning. More...
 
class  ClientPrediction
 Client-side local input prediction and reconciliation. More...
 
struct  ClientSessionConfig
 Client session metadata captured progressively as a multiplayer connection runs. More...
 
struct  ClientSessionSummary
 Aggregate client-side diagnostics counters for one multiplayer session. More...
 
struct  CorrectionReplayResult
 Summary of one correction/replay attempt. More...
 
struct  LocalPlayerState
 Local state currently presented for the owning player. More...
 
struct  MsgBombPlaced
 Reliable discrete bomb-placement event sent by the server. More...
 
struct  MsgCell
 Compact tile cell payload reused by reliable gameplay events. More...
 
struct  MsgCorrection
 Owner-only correction payload sent by the server. More...
 
struct  MsgExplosionResolved
 Reliable authoritative explosion-resolution event sent by the server. More...
 
struct  MsgHello
 Hello payload sent by client during handshake. More...
 
struct  MsgInput
 Batched input payload sent by client each simulation tick. More...
 
struct  MsgLevelInfo
 Round-start payload sent reliably by the server when a match begins. More...
 
struct  MsgLobbyReady
 Client-authored desired ready state for its currently accepted lobby seat. More...
 
struct  MsgLobbyState
 Passive lobby seat snapshot sent reliably by the server. More...
 
struct  MsgMatchCancelled
 Explicit pre-start cancel edge sent when the current round start is aborted back to lobby. More...
 
struct  MsgMatchLoaded
 Client acknowledgement that the gameplay scene for one round start is loaded. More...
 
struct  MsgMatchResult
 Reliable end-of-match result edge sent before the automatic return to lobby. More...
 
struct  MsgMatchStart
 Explicit reliable start edge sent once all current match participants have loaded. More...
 
struct  MsgReject
 Reject payload sent by server in response to Hello on failure. More...
 
struct  MsgSnapshot
 Snapshot payload broadcast by the server to all clients. More...
 
struct  MsgWelcome
 Welcome payload sent by server in response to Hello. More...
 
class  NetClient
 ENet client connection and protocol endpoint. More...
 
class  NetDiagnostics
 Session-local recorder for recent multiplayer diagnostics and aggregate counters. More...
 
struct  NetEvent
 Discrete diagnostics event stored in a recent-event ring buffer. More...
 
struct  NetPeerContinuitySummary
 Aggregate input-continuity facts for one authoritative gameplay player id. More...
 
struct  NetPeerTransportSample
 Latest sampled transport health values for a single gameplay player id. More...
 
struct  NetSessionSummary
 Aggregate counters and timing collected across one diagnostics session. More...
 
struct  PacketDispatcher
 Fixed-size message type to handler lookup table. More...
 
struct  PacketHeader
 Packet metadata prefix present on every wire message. More...
 
struct  PredictionStats
 Aggregate prediction stats for diagnostics. More...
 
struct  RecentEventRepeatState
 Recent-event dedupe state keyed by semantic event signature. More...
 
struct  ServerKeyMessageAggregates
 Sparse per-message aggregates retained for server tuning. More...
 
struct  ServerSessionConfig
 Static server-side session configuration captured into diagnostics output. More...
 

Typedefs

template<typename TContext >
using PacketHandlerFn = void(*)(TContext &context, const PacketHeader &header, const uint8_t *payload, std::size_t payloadSize)
 Function signature for a typed message handler.
 

Enumerations

enum class  EConnectState : uint8_t {
  Disconnected , Connecting , Handshaking , Connected ,
  Disconnecting , FailedResolve , FailedConnect , FailedHandshake ,
  FailedProtocol , FailedInit
}
 Client connection lifecycle state. More...
 
enum class  EChannel : uint8_t {
  ControlReliable = 0 , GameplayReliable = 1 , InputUnreliable = 2 , SnapshotUnreliable = 3 ,
  CorrectionUnreliable = 4
}
 ENet channel identifiers used by the current protocol. More...
 
enum class  EMsgType : uint8_t {
  Invalid = 0x00 , Hello = 0x01 , Welcome = 0x02 , Reject = 0x03 ,
  LevelInfo = 0x04 , LobbyState = 0x05 , LobbyReady = 0x06 , MatchLoaded = 0x07 ,
  MatchStart = 0x08 , MatchCancelled = 0x09 , MatchResult = 0x0A , Input = 0x10 ,
  Snapshot = 0x11 , Correction = 0x12 , BombPlaced = 0x13 , ExplosionResolved = 0x14
}
 Message type identifiers used in packet headers. More...
 
enum class  NetEventType : uint8_t {
  Unknown , SessionBegin , SessionEnd , PeerLifecycle ,
  PacketSent , PacketRecv , Simulation , Flow
}
 High-level kinds of recent events captured during a diagnostics session.
 
enum class  NetPeerLifecycleType : uint8_t {
  TransportConnected , PlayerAccepted , PeerRejected , PeerDisconnected ,
  TransportDisconnectedBeforeHandshake
}
 Peer lifecycle milestones emitted by multiplayer networking flows.
 
enum class  NetPacketDirection : uint8_t { Outgoing , Incoming }
 Packet travel direction recorded in a recent packet event.
 
enum class  NetPacketResult : uint8_t { Ok , Dropped , Rejected , Malformed }
 Diagnostics classification for one packet attempt or receive path outcome.
 
enum class  NetSimulationEventType : uint8_t { Gap , BufferedDeadlineRecovery , RoundEnded }
 Simulation/input-timeline events worth retaining in recent-event history.
 

Functions

constexpr bool isFailedState (EConnectState state)
 Returns true if the state represents a terminal failure.
 
constexpr std::string_view connectStateName (EConnectState state)
 Returns a human-readable label for a connection state.
 
constexpr int8_t buttonsToMoveX (uint8_t buttons)
 Derives horizontal movement {-1, 0, 1} from a button bitmask.
 
constexpr int8_t buttonsToMoveY (uint8_t buttons)
 Derives vertical movement {-1, 0, 1} from a button bitmask.
 
constexpr std::string_view channelName (uint8_t id)
 Returns a human-readable name for a channel ID.
 
bool isValidMsgType (uint8_t raw)
 Checks whether a raw byte value corresponds to a valid EMsgType.
 
constexpr std::string_view msgTypeName (EMsgType type)
 Returns a human-readable name for a protocol message type.
 
constexpr EChannel expectedChannelFor (EMsgType type)
 Returns the required ENet channel for a protocol message type.
 
constexpr bool isValidPlayerMask (const uint32_t mask)
 Returns true when the given player-id bitmask uses only valid player bits.
 
constexpr std::size_t explosionBlastCellOffset (std::size_t index)
 Returns the payload offset of the explosion blast-cell entry at index.
 
constexpr std::size_t explosionDestroyedBrickOffset (std::size_t index)
 Returns the payload offset of the explosion destroyed-brick entry at index.
 
constexpr bool isValidTileCell (const uint8_t col, const uint8_t row)
 Returns true when the given cell lies within the current tile-map bounds.
 
constexpr uint16_t tileCellKey (const uint8_t col, const uint8_t row)
 Packs one tile cell into a monotonic key for ordering and deduplication.
 
constexpr bool isExpectedChannelFor (EMsgType type, uint8_t channelId)
 Returns true when a message was received on its expected ENet channel.
 
constexpr std::size_t expectedPayloadSize (EMsgType type)
 Returns the exact expected payload size for a message type.
 
constexpr void writeU16LE (uint8_t *out, uint16_t value)
 Writes a 16-bit value using little-endian encoding.
 
constexpr void writeU32LE (uint8_t *out, uint32_t value)
 Writes a 32-bit value using little-endian encoding.
 
constexpr uint16_t readU16LE (const uint8_t *in)
 Reads a 16-bit value encoded as little-endian.
 
constexpr uint32_t readU32LE (const uint8_t *in)
 Reads a 32-bit value encoded as little-endian.
 
constexpr std::size_t boundedStrLen (const char *s, const std::size_t maxBytes)
 Returns string length capped to maxBytes for bounded C strings.
 
constexpr std::size_t snapshotPlayerOffset (std::size_t index)
 Returns the payload offset of the snapshot player entry at index.
 
constexpr std::size_t snapshotBombOffset (std::size_t index)
 Returns the payload offset of the snapshot bomb entry at index.
 
constexpr std::size_t snapshotPowerupOffset (std::size_t index)
 Returns the payload offset of the snapshot powerup entry at index.
 
void setHelloName (MsgHello &hello, std::string_view name)
 Sets MsgHello::name from string_view with truncation and zero padding.
 
void setHelloName (MsgHello &hello, const char *name)
 C-string overload of setHelloName.
 
constexpr bool isValidLobbySeatFlags (const uint8_t flags)
 Returns true when one lobby-seat flag field contains only known bits.
 
constexpr bool isValidLobbyPhase (const uint8_t rawPhase)
 Returns true when one lobby-state phase field contains a known encoding.
 
void setLobbySeatName (MsgLobbyState::SeatEntry &seat, std::string_view name)
 Sets one lobby-seat display name with truncation and zero padding.
 
void setMatchResultWinnerName (MsgMatchResult &matchResult, std::string_view name)
 Sets one match-result winner display name with truncation and zero padding.
 
std::string_view lobbySeatName (const MsgLobbyState::SeatEntry &seat)
 Returns the visible lobby-seat display name.
 
std::string_view matchResultWinnerName (const MsgMatchResult &matchResult)
 Returns the visible winner display name carried by one match-result payload.
 
constexpr bool lobbySeatIsOccupied (const MsgLobbyState::SeatEntry &seat)
 Returns true when one lobby seat is currently occupied.
 
constexpr bool lobbySeatIsReady (const MsgLobbyState::SeatEntry &seat)
 Returns true when one occupied lobby seat is marked ready.
 
constexpr bool lobbyCountdownActive (const MsgLobbyState &lobbyState)
 Returns true when the authoritative lobby is in the visible pre-match countdown phase.
 
void serializeHeader (const PacketHeader &header, uint8_t *out) noexcept
 Serializes PacketHeader into kPacketHeaderSize bytes.
 
bool deserializeHeader (const uint8_t *in, std::size_t inSize, PacketHeader &outHeader)
 Deserializes and validates PacketHeader.
 
void serializeMsgHello (const MsgHello &hello, uint8_t *out) noexcept
 Serializes MsgHello to fixed-size wire payload.
 
bool deserializeMsgHello (const uint8_t *in, std::size_t inSize, MsgHello &outHello)
 Deserializes MsgHello from fixed-size wire payload.
 
void serializeMsgWelcome (const MsgWelcome &welcome, uint8_t *out) noexcept
 Serializes MsgWelcome to fixed-size wire payload.
 
bool deserializeMsgWelcome (const uint8_t *in, std::size_t inSize, MsgWelcome &outWelcome)
 Deserializes MsgWelcome from fixed-size wire payload.
 
void serializeMsgReject (const MsgReject &reject, uint8_t *out) noexcept
 Serializes MsgReject to fixed-size wire payload.
 
bool deserializeMsgReject (const uint8_t *in, std::size_t inSize, MsgReject &outReject)
 Deserializes MsgReject from fixed-size wire payload.
 
void serializeMsgLevelInfo (const MsgLevelInfo &info, uint8_t *out) noexcept
 Serializes MsgLevelInfo to fixed-size wire payload.
 
bool deserializeMsgLevelInfo (const uint8_t *in, std::size_t inSize, MsgLevelInfo &outInfo)
 Deserializes MsgLevelInfo from fixed-size wire payload.
 
constexpr bool isValidLobbyReadyValue (const uint8_t ready)
 Returns true when one lobby-ready value uses a known wire encoding.
 
void serializeMsgLobbyReady (const MsgLobbyReady &ready, uint8_t *out) noexcept
 Serializes MsgLobbyReady to a fixed-size wire payload.
 
bool deserializeMsgLobbyReady (const uint8_t *in, std::size_t inSize, MsgLobbyReady &outReady)
 Deserializes MsgLobbyReady from a fixed-size wire payload.
 
void serializeMsgMatchLoaded (const MsgMatchLoaded &loaded, uint8_t *out) noexcept
 Serializes MsgMatchLoaded to fixed-size wire payload.
 
bool deserializeMsgMatchLoaded (const uint8_t *in, std::size_t inSize, MsgMatchLoaded &outLoaded)
 Deserializes MsgMatchLoaded from fixed-size wire payload.
 
void serializeMsgMatchStart (const MsgMatchStart &matchStart, uint8_t *out) noexcept
 Serializes MsgMatchStart to fixed-size wire payload.
 
bool deserializeMsgMatchStart (const uint8_t *in, std::size_t inSize, MsgMatchStart &outMatchStart)
 Deserializes MsgMatchStart from fixed-size wire payload.
 
void serializeMsgMatchCancelled (const MsgMatchCancelled &cancelled, uint8_t *out) noexcept
 Serializes MsgMatchCancelled to fixed-size wire payload.
 
bool deserializeMsgMatchCancelled (const uint8_t *in, std::size_t inSize, MsgMatchCancelled &outCancelled)
 Deserializes MsgMatchCancelled from fixed-size wire payload.
 
void serializeMsgMatchResult (const MsgMatchResult &matchResult, uint8_t *out) noexcept
 Serializes MsgMatchResult to fixed-size wire payload.
 
bool deserializeMsgMatchResult (const uint8_t *in, std::size_t inSize, MsgMatchResult &outMatchResult)
 Deserializes MsgMatchResult from fixed-size wire payload.
 
void serializeMsgLobbyState (const MsgLobbyState &lobbyState, uint8_t *out) noexcept
 Serializes MsgLobbyState to fixed-size wire payload.
 
bool deserializeMsgLobbyState (const uint8_t *in, std::size_t inSize, MsgLobbyState &outLobbyState)
 Deserializes MsgLobbyState from fixed-size wire payload.
 
void serializeMsgInput (const MsgInput &input, uint8_t *out) noexcept
 Serializes MsgInput to its fixed-size wire payload.
 
bool deserializeMsgInput (const uint8_t *in, std::size_t inSize, MsgInput &outInput)
 Deserializes MsgInput from fixed-size wire payload.
 
void serializeMsgSnapshot (const MsgSnapshot &snap, uint8_t *out) noexcept
 Serializes MsgSnapshot to its fixed-size wire payload.
 
bool deserializeMsgSnapshot (const uint8_t *in, std::size_t inSize, MsgSnapshot &outSnap)
 Deserializes MsgSnapshot from fixed-size wire payload.
 
void serializeMsgCorrection (const MsgCorrection &corr, uint8_t *out) noexcept
 Serializes MsgCorrection to fixed-size wire payload.
 
bool deserializeMsgCorrection (const uint8_t *in, std::size_t inSize, MsgCorrection &outCorr)
 Deserializes MsgCorrection from fixed-size wire payload.
 
void serializeMsgBombPlaced (const MsgBombPlaced &bombPlaced, uint8_t *out) noexcept
 Serializes MsgBombPlaced to fixed-size wire payload.
 
bool deserializeMsgBombPlaced (const uint8_t *in, std::size_t inSize, MsgBombPlaced &outBombPlaced)
 Deserializes MsgBombPlaced from fixed-size wire payload.
 
void serializeMsgExplosionResolved (const MsgExplosionResolved &explosion, uint8_t *out) noexcept
 Serializes MsgExplosionResolved to fixed-size wire payload.
 
bool deserializeMsgExplosionResolved (const uint8_t *in, std::size_t inSize, MsgExplosionResolved &outExplosion)
 Deserializes MsgExplosionResolved from fixed-size wire payload.
 
std::array< uint8_t, kPacketHeaderSize+kMsgHelloSize > makeHelloPacket (const MsgHello &hello)
 Builds a full Hello packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgHelloSize > makeHelloPacket (std::string_view name, uint16_t protocolVersion)
 Convenience overload building Hello from name and version.
 
std::array< uint8_t, kPacketHeaderSize+kMsgWelcomeSize > makeWelcomePacket (const MsgWelcome &welcome)
 Builds a full Welcome packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgRejectSize > makeRejectPacket (const MsgReject &reject)
 Builds a full Reject packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgLevelInfoSize > makeLevelInfoPacket (const MsgLevelInfo &info)
 Builds a full LevelInfo packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgLobbyReadySize > makeLobbyReadyPacket (const MsgLobbyReady &ready)
 Builds a full LobbyReady packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgLobbyReadySize > makeLobbyReadyPacket (const bool ready)
 Convenience overload building LobbyReady directly from the desired ready state.
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchLoadedSize > makeMatchLoadedPacket (const MsgMatchLoaded &loaded)
 Builds a full MatchLoaded packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchLoadedSize > makeMatchLoadedPacket (const uint32_t matchId)
 Convenience overload building MatchLoaded directly from a match identifier.
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchStartSize > makeMatchStartPacket (const MsgMatchStart &matchStart)
 Builds a full MatchStart packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchStartSize > makeMatchStartPacket (const uint32_t matchId, const uint32_t goShowServerTick, const uint32_t unlockServerTick)
 Convenience overload building MatchStart directly from match timing values.
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchCancelledSize > makeMatchCancelledPacket (const MsgMatchCancelled &cancelled)
 Builds a full MatchCancelled packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchCancelledSize > makeMatchCancelledPacket (const uint32_t matchId)
 Convenience overload building MatchCancelled directly from a match identifier.
 
std::array< uint8_t, kPacketHeaderSize+kMsgMatchResultSize > makeMatchResultPacket (const MsgMatchResult &matchResult)
 Builds a full MatchResult packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgLobbyStateSize > makeLobbyStatePacket (const MsgLobbyState &lobbyState)
 Builds a full LobbyState packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgInputSize > makeInputPacket (const MsgInput &input)
 Builds a full Input packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgSnapshotSize > makeSnapshotPacket (const MsgSnapshot &snap)
 Builds a full Snapshot packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgCorrectionSize > makeCorrectionPacket (const MsgCorrection &corr)
 Builds a full Correction packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgBombPlacedSize > makeBombPlacedPacket (const MsgBombPlaced &bombPlaced)
 Builds a full BombPlaced packet (header + payload).
 
std::array< uint8_t, kPacketHeaderSize+kMsgExplosionResolvedSize > makeExplosionResolvedPacket (const MsgExplosionResolved &explosion)
 Builds a full ExplosionResolved packet (header + payload).
 
template<std::size_t N>
bool queueOnChannel (ENetPeer *peer, EChannel channel, uint32_t flags, const std::array< uint8_t, N > &bytes)
 Queues a pre-serialized byte buffer on an explicit channel.
 
void flush (ENetHost *host)
 Flushes all currently queued packets for this host.
 
template<std::size_t N>
bool queueReliableControl (ENetPeer *peer, const std::array< uint8_t, N > &bytes)
 Queues a reliable control packet.
 
template<std::size_t N>
bool queueReliableGame (ENetPeer *peer, const std::array< uint8_t, N > &bytes)
 Queues a reliable gameplay packet.
 
template<std::size_t N>
bool queueUnreliableInput (ENetPeer *peer, const std::array< uint8_t, N > &bytes)
 Queues an unreliable input packet.
 
template<std::size_t N>
bool queueUnreliableSnapshot (ENetPeer *peer, const std::array< uint8_t, N > &bytes)
 Queues an unreliable snapshot packet.
 
template<std::size_t N>
bool queueUnreliableCorrection (ENetPeer *peer, const std::array< uint8_t, N > &bytes)
 Queues an unreliable owner-correction packet.
 
void applyDefaultPeerTransportConfig (ENetPeer *peer)
 Applies the project's default transport-level liveness policy to one ENet peer.
 
bool tryParsePacket (const uint8_t *data, std::size_t dataLength, PacketHeader &outHeader, const uint8_t *&outPayload, std::size_t &outPayloadSize)
 Validates and parses a raw packet into header and payload view.
 

Variables

constexpr std::size_t kClientPredictionHistorySize = 128
 Power-of-two ring size used for local prediction history and bitmask slot indexing.
 
constexpr uint16_t kProtocolVersion = 9
 
constexpr uint16_t kDefaultServerPort = 12345
 Default server port used by both client and server.
 
constexpr std::size_t kMaxPacketSize = 1400
 Upper packet size bound (below typical 1500-byte MTU).
 
constexpr uint32_t kInputLogEveryN = 30
 Input log sampling interval on client and server.
 
constexpr uint32_t kSnapshotLogEveryN = 30
 Snapshot log sampling interval on client and server.
 
constexpr uint32_t kPeerPingIntervalMs = 500
 Transport heartbeat interval for connected peers.
 
constexpr uint32_t kPeerTimeoutLimit = 8
 Consecutive timeout limit before ENet drops a peer.
 
constexpr uint32_t kPeerTimeoutMinimumMs = 5000
 Lower bound for ENet peer timeout detection.
 
constexpr uint32_t kPeerTimeoutMaximumMs = 10000
 Upper bound for ENet peer timeout detection.
 
constexpr std::size_t kPlayerNameMax = 16
 
constexpr uint8_t kMaxPlayers = 4
 Maximum supported player count in a game instance.
 
constexpr uint8_t kMaxSnapshotBombs = kMaxPlayers * 4
 Maximum bombs carried by one snapshot payload.
 
constexpr uint8_t kMaxSnapshotPowerups = sim::kPowerupsPerRound
 Maximum revealed powerups carried by one snapshot payload.
 
constexpr std::size_t kMaxExplosionBlastCells
 Maximum cells a cross-shaped blast can touch.
 
constexpr std::size_t kMaxExplosionDestroyedBricks = kMaxExplosionBlastCells - 1u
 Upper bound for bricks one blast can destroy.
 
constexpr uint32_t kFirstInputSeq = 1
 First valid input sequence number. Seq 0 means "no input received yet".
 
constexpr uint8_t kMaxInputBatchSize = 16
 Maximum number of inputs in a single batched MsgInput packet.
 
constexpr uint8_t kInputUp = 0x01
 
constexpr uint8_t kInputDown = 0x02
 
constexpr uint8_t kInputLeft = 0x04
 
constexpr uint8_t kInputRight = 0x08
 
constexpr uint8_t kInputBomb = 0x10
 
constexpr uint8_t kInputKnownBits = kInputUp | kInputDown | kInputLeft | kInputRight | kInputBomb
 Union of all defined input bits. Used for unknown-bit rejection.
 
constexpr std::size_t kChannelCount = 5
 Number of ENet channels provisioned by client and server.
 
constexpr std::size_t kPacketHeaderSize
 
constexpr std::size_t kMsgHelloSize
 
constexpr std::size_t kMsgWelcomeSize
 
constexpr std::size_t kMsgRejectSize
 
constexpr std::size_t kMsgLevelInfoSize
 
constexpr std::size_t kMsgLobbyReadySize
 
constexpr std::size_t kMsgMatchLoadedSize
 
constexpr std::size_t kMsgMatchStartSize
 
constexpr std::size_t kMsgMatchCancelledSize
 
constexpr std::size_t kMsgMatchResultSize
 
constexpr std::size_t kMsgLobbyStateSeatSize
 
constexpr std::size_t kMsgLobbyStateSize
 
constexpr std::size_t kMsgInputSize
 
constexpr std::size_t kMsgSnapshotSize
 
constexpr std::size_t kMsgCorrectionSize
 
constexpr std::size_t kMsgBombPlacedSize
 
constexpr std::size_t kMsgExplosionResolvedSize
 
constexpr std::size_t kSnapshotPlayersOffset
 Compile-time checks for expected wire sizes.
 
constexpr std::size_t kSnapshotPlayerEntrySize
 
constexpr std::size_t kSnapshotBombsOffset
 
constexpr std::size_t kSnapshotBombEntrySize
 
constexpr std::size_t kSnapshotPowerupsOffset
 
constexpr std::size_t kSnapshotPowerupEntrySize
 
constexpr std::size_t kExplosionBlastCellsOffset
 
constexpr std::size_t kExplosionCellEntrySize
 
constexpr std::size_t kExplosionDestroyedBricksOffset
 
constexpr std::size_t kRecentEventCapacity = 256
 Maximum number of recent events retained in the NetDiagnostics ring buffer.
 
constexpr uint64_t kRecentEventDedupeCooldownMs = 1000
 Minimum time between repeated recent events with the same semantic signature.
 
constexpr uint32_t kServerInputBatchLogIntervalTicks = static_cast<uint32_t>(sim::kTickRate) * 2u
 Accepted-input debug log cadence in authoritative server ticks.
 
constexpr uint32_t kServerSnapshotLogIntervalTicks = static_cast<uint32_t>(sim::kTickRate) * 2u
 Snapshot summary debug log cadence in authoritative server ticks.
 
constexpr uint32_t kPeerTransportSampleTicks = static_cast<uint32_t>(sim::kTickRate)
 ENet transport-health sampling cadence in authoritative server ticks.
 
constexpr uint16_t kRepeatedInputWarnThreshold = 6
 Consecutive anomaly streak that triggers a WARN log for repeated ahead drops or input gaps.
 
constexpr uint32_t kRepeatedInputWarnCooldownTicks = static_cast<uint32_t>(sim::kTickRate) * 2u
 Minimum authoritative tick spacing between repeated anomaly WARN lines for the same peer.
 
constexpr uint32_t kDiagnosticsReportVersion = 1
 Shared JSON report schema version for diagnostics outputs.
 

Detailed Description

Shared multiplayer protocol types and transport-facing wire helpers.

Typedef Documentation

◆ PacketHandlerFn

template<typename TContext >
using bomberman::net::PacketHandlerFn = typedef void(*)(TContext& context, const PacketHeader& header, const uint8_t* payload, std::size_t payloadSize)

Function signature for a typed message handler.

Template Parameters
TContextContext type forwarded to handlers.
Note
Handlers can assume header and payload length were validated by tryParsePacket. They must still validate typed payload contents.

Enumeration Type Documentation

◆ EChannel

enum class bomberman::net::EChannel : uint8_t
strong

ENet channel identifiers used by the current protocol.

Note
ENet preserves packet order only within a single channel. The protocol assigns each message type to exactly one expected channel and rejects packets received on the wrong one.

◆ EConnectState

enum class bomberman::net::EConnectState : uint8_t
strong

Client connection lifecycle state.

Enumerator
Disconnected 

Not connected and holding no transport resources.

Connecting 

ENet connect in progress, waiting for a CONNECT event.

Handshaking 

Transport connected and Hello sent, awaiting Welcome or Reject.

Connected 

Session accepted and ready for lobby flow or the next round-start message.

Disconnecting 

Graceful disconnect requested, awaiting ENet completion.

FailedResolve 

Host address could not be resolved.

FailedConnect 

Connect attempt timed out or transport failed before handshake.

FailedHandshake 

Handshake timed out or was rejected for a non-protocol reason.

FailedProtocol 

Protocol version mismatch during handshake.

FailedInit 

ENet initialization or host creation failed.

◆ EMsgType

enum class bomberman::net::EMsgType : uint8_t
strong

Message type identifiers used in packet headers.

Enumerator
Invalid 

Invalid or uninitialized message type.

Hello 

Client-initiated handshake message.

Welcome 

Server handshake acceptance message.

Reject 

Server handshake rejection message.

LevelInfo 

Server message containing map seed and match id for an upcoming round.

LobbyState 

Server message containing current lobby state.

LobbyReady 

Client message indicating the local player's ready status for the next round.

MatchLoaded 

Server message indicating that all players have loaded the level and the match is ready to start.

MatchStart 

Server message indicating the authoritative server tick for round start and the unlock tick for early inputs.

MatchCancelled 

Server message indicating that the current match has been cancelled due to a player disconnect.

MatchResult 

Server message containing the result of a completed match.

Input 

Client message containing a batch of input bitmasks and their base sequence number.

Snapshot 

Server message containing the authoritative game state for a single tick.

Correction 

Server message containing an authoritative correction to the local player's state.

BombPlaced 

Server message indicating that a bomb has been placed by a player.

ExplosionResolved 

Server message containing the authoritative result of a bomb explosion.

Function Documentation

◆ applyDefaultPeerTransportConfig()

void bomberman::net::applyDefaultPeerTransportConfig ( ENetPeer *  peer)
inline

Applies the project's default transport-level liveness policy to one ENet peer.

This is transport liveness only. It does not replace higher-level gameplay/input idle policy.

◆ deserializeHeader()

bool bomberman::net::deserializeHeader ( const uint8_t *  in,
std::size_t  inSize,
PacketHeader outHeader 
)
inline

Deserializes and validates PacketHeader.

Validates type, payload bounds, and expected payload size for known message types.

◆ expectedChannelFor()

constexpr EChannel bomberman::net::expectedChannelFor ( EMsgType  type)
constexpr

Returns the required ENet channel for a protocol message type.

Note
Handshake, lobby, and match-flow control messages all use reliable control delivery owned by higher-level session and match flow.

◆ expectedPayloadSize()

constexpr std::size_t bomberman::net::expectedPayloadSize ( EMsgType  type)
constexpr

Returns the exact expected payload size for a message type.

All current messages use fixed-size payloads. This is part of the first validation pass performed before payload deserialization. Returns 0 for unknown types.

◆ queueOnChannel()

template<std::size_t N>
bool bomberman::net::queueOnChannel ( ENetPeer *  peer,
EChannel  channel,
uint32_t  flags,
const std::array< uint8_t, N > &  bytes 
)

Queues a pre-serialized byte buffer on an explicit channel.

Warning
peer must be a valid ENet peer owned by the active host. This helper does not validate protocol/message pairing.
Returns
true if the packet was queued successfully.

◆ serializeMsgInput()

void bomberman::net::serializeMsgInput ( const MsgInput input,
uint8_t *  out 
)
inlinenoexcept

Serializes MsgInput to its fixed-size wire payload.

Note
Callers are expected to keep entries beyond count zero-padded.

◆ serializeMsgSnapshot()

void bomberman::net::serializeMsgSnapshot ( const MsgSnapshot snap,
uint8_t *  out 
)
inlinenoexcept

Serializes MsgSnapshot to its fixed-size wire payload.

Note
Callers are expected to keep entries beyond the active counts zero-initialized because the current wire format always writes every fixed-size snapshot slot.

◆ tryParsePacket()

bool bomberman::net::tryParsePacket ( const uint8_t *  data,
std::size_t  dataLength,
PacketHeader outHeader,
const uint8_t *&  outPayload,
std::size_t &  outPayloadSize 
)
inline

Validates and parses a raw packet into header and payload view.

Wraps deserializeHeader() and computes the payload pointer.

Note
This validates only the packet header and payload-length contract. Channel checks and typed payload deserialization stay with the caller.
Parameters
dataRaw packet bytes (header + payload).
dataLengthTotal packet size in bytes.
outHeaderParsed and validated packet header.
outPayloadPointer to payload start on success.
outPayloadSizePayload size on success.
Returns
true if packet is valid and ready for dispatch.

Variable Documentation

◆ kExplosionBlastCellsOffset

constexpr std::size_t bomberman::net::kExplosionBlastCellsOffset
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)

◆ kExplosionCellEntrySize

constexpr std::size_t bomberman::net::kExplosionCellEntrySize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint8_t)

◆ kExplosionDestroyedBricksOffset

constexpr std::size_t bomberman::net::kExplosionDestroyedBricksOffset
constexpr
Initial value:
=
kExplosionBlastCellsOffset + kMaxExplosionBlastCells * kExplosionCellEntrySize
constexpr std::size_t kMaxExplosionBlastCells
Maximum cells a cross-shaped blast can touch.
Definition NetCommon.h:57

◆ kMaxExplosionBlastCells

constexpr std::size_t bomberman::net::kMaxExplosionBlastCells
constexpr
Initial value:
=
1u + 4u * (static_cast<std::size_t>((tileArrayWidth > tileArrayHeight) ?
tileArrayWidth :
constexpr unsigned int tileArrayWidth
Tile map width in tiles.
Definition Const.h:43
constexpr unsigned int tileArrayHeight
Tile map height in tiles.
Definition Const.h:44

Maximum cells a cross-shaped blast can touch.

◆ kMsgBombPlacedSize

constexpr std::size_t bomberman::net::kMsgBombPlacedSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)

◆ kMsgCorrectionSize

constexpr std::size_t bomberman::net::kMsgCorrectionSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(int16_t) +
sizeof(int16_t) +
sizeof(uint8_t) +
3u

◆ kMsgExplosionResolvedSize

constexpr std::size_t bomberman::net::kMsgExplosionResolvedSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
kMaxExplosionBlastCells *
(sizeof(uint8_t) +
sizeof(uint8_t)) +
(sizeof(uint8_t) +
sizeof(uint8_t))
constexpr std::size_t kMaxExplosionDestroyedBricks
Upper bound for bricks one blast can destroy.
Definition NetCommon.h:61

◆ kMsgHelloSize

constexpr std::size_t bomberman::net::kMsgHelloSize
constexpr
Initial value:
=
sizeof(uint16_t) +
kPlayerNameMax

◆ kMsgInputSize

constexpr std::size_t bomberman::net::kMsgInputSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint8_t) +
constexpr uint8_t kMaxInputBatchSize
Maximum number of inputs in a single batched MsgInput packet.
Definition NetCommon.h:67

◆ kMsgLevelInfoSize

constexpr std::size_t bomberman::net::kMsgLevelInfoSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t)

◆ kMsgLobbyReadySize

constexpr std::size_t bomberman::net::kMsgLobbyReadySize
constexpr
Initial value:
=
sizeof(uint8_t)

◆ kMsgLobbyStateSeatSize

constexpr std::size_t bomberman::net::kMsgLobbyStateSeatSize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint8_t) +
constexpr std::size_t kPlayerNameMax
Definition NetCommon.h:53

◆ kMsgLobbyStateSize

constexpr std::size_t bomberman::net::kMsgLobbyStateSize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint16_t) +
kMaxPlayers * kMsgLobbyStateSeatSize

◆ kMsgMatchCancelledSize

constexpr std::size_t bomberman::net::kMsgMatchCancelledSize
constexpr
Initial value:
=
sizeof(uint32_t)

◆ kMsgMatchLoadedSize

constexpr std::size_t bomberman::net::kMsgMatchLoadedSize
constexpr
Initial value:
=
sizeof(uint32_t)

◆ kMsgMatchResultSize

constexpr std::size_t bomberman::net::kMsgMatchResultSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
kPlayerNameMax

◆ kMsgMatchStartSize

constexpr std::size_t bomberman::net::kMsgMatchStartSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint32_t)

◆ kMsgRejectSize

constexpr std::size_t bomberman::net::kMsgRejectSize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint16_t)

◆ kMsgSnapshotSize

constexpr std::size_t bomberman::net::kMsgSnapshotSize
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
kMaxPlayers *
(sizeof(uint8_t) +
sizeof(int16_t) +
sizeof(int16_t) +
sizeof(uint8_t)) +
(sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)) +
kMaxSnapshotPowerups *
(sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t))
constexpr uint8_t kMaxSnapshotBombs
Maximum bombs carried by one snapshot payload.
Definition NetCommon.h:55

◆ kMsgWelcomeSize

constexpr std::size_t bomberman::net::kMsgWelcomeSize
constexpr
Initial value:
=
sizeof(uint16_t) +
sizeof(uint8_t) +
sizeof(uint16_t)

◆ kPacketHeaderSize

constexpr std::size_t bomberman::net::kPacketHeaderSize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint16_t)

◆ kPlayerNameMax

constexpr std::size_t bomberman::net::kPlayerNameMax = 16
constexpr
Note
Changing these values will affect wire layout and require protocol version bump.

◆ kSnapshotBombEntrySize

constexpr std::size_t bomberman::net::kSnapshotBombEntrySize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)

◆ kSnapshotBombsOffset

constexpr std::size_t bomberman::net::kSnapshotBombsOffset
constexpr
Initial value:
=
kSnapshotPlayersOffset + kMaxPlayers * kSnapshotPlayerEntrySize
constexpr std::size_t kSnapshotPlayersOffset
Compile-time checks for expected wire sizes.
Definition NetCommon.h:271
constexpr uint8_t kMaxPlayers
Maximum supported player count in a game instance.
Definition NetCommon.h:54

◆ kSnapshotPlayerEntrySize

constexpr std::size_t bomberman::net::kSnapshotPlayerEntrySize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(int16_t) +
sizeof(int16_t) +
sizeof(uint8_t)

◆ kSnapshotPlayersOffset

constexpr std::size_t bomberman::net::kSnapshotPlayersOffset
constexpr
Initial value:
=
sizeof(uint32_t) +
sizeof(uint32_t) +
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)

Compile-time checks for expected wire sizes.

◆ kSnapshotPowerupEntrySize

constexpr std::size_t bomberman::net::kSnapshotPowerupEntrySize
constexpr
Initial value:
=
sizeof(uint8_t) +
sizeof(uint8_t) +
sizeof(uint8_t)

◆ kSnapshotPowerupsOffset

constexpr std::size_t bomberman::net::kSnapshotPowerupsOffset
constexpr
Initial value:
=
kSnapshotBombsOffset + kMaxSnapshotBombs * kSnapshotBombEntrySize