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

Authoritative dedicated-server state, match flow, and fixed-tick simulation support. More...

Classes

struct  BombCell
 Tile-map cell coordinate used by bomb and powerup state. More...
 
struct  BombState
 Authoritative state for one active bomb in the current match. More...
 
struct  DisconnectedPlayerReclaim
 Bounded reconnect cache for one recently disconnected player seat. More...
 
struct  InputRingEntry
 One buffered authoritative input entry for a match player. More...
 
struct  MatchPlayerState
 Authoritative in-match state for one accepted player seat. More...
 
struct  PacketDispatchContext
 Per-dispatch context passed through the typed packet handlers. More...
 
struct  PeerSession
 Live transport/session state for one connected ENet peer. More...
 
struct  PlayerSlot
 Current-session metadata for one accepted player assignment. More...
 
struct  PowerupState
 Authoritative state for one round-scoped hidden or revealed powerup. More...
 
struct  ServerState
 Long-lived authoritative server state shared across receive and simulation paths. More...
 

Enumerations

enum class  ServerPhase : uint8_t {
  Lobby , LobbyCountdown , StartingMatch , InMatch ,
  EndOfMatch
}
 High-level dedicated-server phase for the current lobby and match flow. More...
 

Functions

void clearBombsAndReleaseOwnership (ServerState &state)
 Clears all active bombs and releases per-player active-bomb ownership counters.
 
void tryPlaceBomb (ServerState &state, MatchPlayerState &matchPlayer)
 Attempts to place one authoritative bomb for a match player on the current server tick.
 
void resolveExplodingBombs (ServerState &state)
 Resolves all bombs whose fuse expires on the current authoritative tick.
 
void onHello (PacketDispatchContext &ctx, const net::PacketHeader &header, const uint8_t *payload, std::size_t payloadSize)
 Handles one validated Hello packet.
 
void onLobbyReady (PacketDispatchContext &ctx, const net::PacketHeader &header, const uint8_t *payload, std::size_t payloadSize)
 Handles one lobby ready-toggle request from an accepted seat.
 
void onMatchLoaded (PacketDispatchContext &ctx, const net::PacketHeader &header, const uint8_t *payload, std::size_t payloadSize)
 Handles one match-loaded acknowledgement during StartingMatch.
 
void broadcastLobbyState (ServerState &state)
 Rebuilds and broadcasts the current lobby state.
 
bool serviceServerEvents (ServerState &state, uint32_t serviceTimeoutMs)
 Services pending ENet events for the dedicated server.
 
void refreshServerFlowDiagnostics (ServerState &state)
 Refreshes coarse server-flow diagnostics.
 
void advanceServerFlow (ServerState &state)
 Advances non-gameplay flow state.
 
void resetRoundRuntimeToLobby (ServerState &state)
 Resets round-scoped state and returns to the lobby.
 
void handleLobbyReadyStateChanged (ServerState &state)
 Reacts to one lobby ready-state change.
 
void handleAcceptedPlayerJoined (ServerState &state)
 Applies the lobby participant-change policy after one accepted player joins.
 
bool beginMatchBootstrap (ServerState &state)
 Starts match bootstrap from a validated lobby countdown commit.
 
void markPlayerLoadedForCurrentMatch (ServerState &state, uint8_t playerId)
 Records one match-loaded acknowledgement.
 
void handleAcceptedPlayerReleased (ServerState &state, uint8_t playerId)
 Updates flow state after one accepted player disconnects.
 
void beginEndOfMatch (ServerState &state, std::optional< uint8_t > winnerPlayerId, bool draw, uint8_t activePlayerCount, uint8_t alivePlayerCount)
 Commits end-of-match state for the current round.
 
std::optional< uint8_t > acceptedPlayerId (const ENetPeer *peer)
 Returns the accepted player id bound to a live peer, if any.
 
void handleReceiveEvent (const ENetEvent &event, ServerState &state)
 Parses, validates, and dispatches one received ENet packet.
 
void onInput (PacketDispatchContext &ctx, const net::PacketHeader &header, const uint8_t *payload, std::size_t payloadSize)
 Handles one validated gameplay input batch.
 
bool hasInvincibility (const MatchPlayerState &matchPlayer, uint32_t serverTick)
 Returns true if invincibility is active.
 
bool hasSpeedBoost (const MatchPlayerState &matchPlayer, uint32_t serverTick)
 Returns true if speed boost is active.
 
bool hasBombRangeBoost (const MatchPlayerState &matchPlayer, uint32_t serverTick)
 Returns true if bomb-range boost is active.
 
bool hasMaxBombsBoost (const MatchPlayerState &matchPlayer, uint32_t serverTick)
 Returns true if max-bombs boost is active.
 
void refreshMatchPlayerPowerupLoadout (const ServerState &state, MatchPlayerState &matchPlayer)
 Refreshes one match player's derived bomb loadout.
 
uint8_t buildReplicatedPlayerFlags (const MatchPlayerState &matchPlayer, uint32_t serverTick)
 Builds the replicated player-flag bitmask.
 
void clearRoundPowerups (ServerState &state)
 Clears all hidden and revealed round powerup state.
 
void placeRoundPowerups (ServerState &state)
 Deterministically seeds the current round's hidden powerups under random bricks.
 
void revealPowerupsUnderDestroyedBricks (ServerState &state, std::span< const BombCell > destroyedBricks)
 Reveals any hidden powerups whose brick cells were just destroyed.
 
void collectRevealedPowerups (ServerState &state)
 Removes any revealed powerups collected by active match players on the current tick.
 
void initServerState (ServerState &state, ENetHost *host, bool diagEnabled=false, bool overrideMapSeed=false, uint32_t mapSeed=0, uint32_t inputLeadTicks=sim::kDefaultServerInputLeadTicks, uint32_t snapshotIntervalTicks=sim::kDefaultServerSnapshotIntervalTicks, bool powersEnabled=true)
 Resets a ServerState for a new dedicated-server session.
 
void rollNextRoundMapSeed (ServerState &state)
 Chooses the seed for the next round map.
 
std::optional< uint8_t > acquirePlayerId (ServerState &state)
 Returns the lowest available playerId.
 
bool acquireSpecificPlayerId (ServerState &state, uint8_t playerId)
 Removes a specific playerId from the free pool if available.
 
void releasePlayerId (ServerState &state, uint8_t playerId)
 Returns a playerId to the free pool.
 
PeerSessionbindPeerSession (ServerState &state, ENetPeer &peer)
 Binds a connected ENet peer to stable live peer-session storage.
 
PeerSessiongetPeerSession (ENetPeer *peer)
 Returns the live peer session referenced by peer->data, if any.
 
const PeerSessiongetPeerSession (const ENetPeer *peer)
 
PeerSessionfindPeerSessionByPlayerId (ServerState &state, uint8_t playerId)
 Returns the live peer session currently bound to playerId, if any.
 
const PeerSessionfindPeerSessionByPlayerId (const ServerState &state, const uint8_t playerId)
 
void acceptPeerSession (ServerState &state, PeerSession &session, uint8_t playerId, std::string_view playerName, uint8_t carriedWins=0)
 Commits an accepted peer session into active player metadata.
 
std::optional< uint8_t > releasePeerSession (ServerState &state, ENetPeer &peer)
 Releases the live peer session bound to peer, if any.
 
void createMatchPlayerState (ServerState &state, uint8_t playerId)
 Creates active in-match state for one player seat.
 
void destroyMatchPlayerState (ServerState &state, uint8_t playerId)
 Destroys active in-match state for one player seat, if present.
 
void simulateServerTick (ServerState &state)
 Advances the authoritative server by one fixed simulation tick.
 
bool shouldBroadcastSnapshot (const ServerState &state)
 Returns true when the current tick should broadcast a snapshot.
 
net::MsgSnapshot buildSnapshot (const ServerState &state)
 Builds a MsgSnapshot from the current round state.
 

Variables

constexpr std::size_t kServerPeerSessionCapacity = net::kMaxPlayers + 4
 Maximum ENet peers the dedicated server provisions live peer-session storage for.
 
constexpr std::size_t kServerInputBufferSize = static_cast<std::size_t>(net::kMaxInputBatchSize) * 2u
 Input slots retained per active MatchPlayerState.
 
constexpr uint32_t kMaxBufferedInputLead = kServerInputBufferSize - 1
 Maximum distance ahead of lastProcessedInputSeq that a received input is allowed to be.
 
constexpr std::size_t kServerBombCapacity
 Maximum bombs the server stores for one match.
 
constexpr std::size_t kServerPowerupCapacity = sim::kPowerupsPerRound
 Maximum number of hidden/revealed round powerups the server tracks at once.
 

Detailed Description

Authoritative dedicated-server state, match flow, and fixed-tick simulation support.

Enumeration Type Documentation

◆ ServerPhase

enum class bomberman::server::ServerPhase : uint8_t
strong

High-level dedicated-server phase for the current lobby and match flow.

Enumerator
Lobby 

Accepting players and waiting for match start.

LobbyCountdown 

All required players are ready and the lobby countdown is running.

StartingMatch 

Transitioning accepted players from lobby into the next match.

InMatch 

Authoritative gameplay is active.

EndOfMatch 

Match has finished and end-of-round presentation/results are active.

Function Documentation

◆ acceptPeerSession()

void bomberman::server::acceptPeerSession ( ServerState state,
PeerSession session,
uint8_t  playerId,
std::string_view  playerName,
uint8_t  carriedWins = 0 
)

Commits an accepted peer session into active player metadata.

Creates the PlayerSlot and binds it to the provided PeerSession.

◆ releasePeerSession()

std::optional< uint8_t > bomberman::server::releasePeerSession ( ServerState state,
ENetPeer &  peer 
)

Releases the live peer session bound to peer, if any.

Disconnect ends the current assignment immediately. Later lobby admission may reclaim the same free seat by exact player name.

Variable Documentation

◆ kMaxBufferedInputLead

constexpr uint32_t bomberman::server::kMaxBufferedInputLead = kServerInputBufferSize - 1
constexpr

Maximum distance ahead of lastProcessedInputSeq that a received input is allowed to be.

Note
Input sequence arithmetic currently assumes a dedicated-server session will not approach uint32_t wraparound.
See also
kServerInputBufferSize

◆ kServerBombCapacity

constexpr std::size_t bomberman::server::kServerBombCapacity
constexpr
Initial value:
= static_cast<std::size_t>(tileArrayWidth) *
static_cast<std::size_t>(tileArrayHeight)
constexpr unsigned int tileArrayWidth
Tile map width in tiles.
Definition Const.h:43

Maximum bombs the server stores for one match.

◆ kServerPeerSessionCapacity

constexpr std::size_t bomberman::server::kServerPeerSessionCapacity = net::kMaxPlayers + 4
constexpr

Maximum ENet peers the dedicated server provisions live peer-session storage for.

Allow a few extra transport-level peers so overflow clients can reach Hello and receive an explicit ServerFull reject instead of timing out in ENet connect.