Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
ServerFlowInternal.h
Go to the documentation of this file.
1
7#ifndef BOMBERMAN_SERVER_SERVERFLOWINTERNAL_H
8#define BOMBERMAN_SERVER_SERVERFLOWINTERNAL_H
9
10#include <algorithm>
11#include <array>
12#include <cstddef>
13#include <cstdint>
14#include <string_view>
15
16#include "Net/NetSend.h"
17#include "ServerHandlers.h"
18#include "ServerState.h"
19#include "Sim/SimConfig.h"
20
21namespace bomberman::server::flow_internal
22{
23 static_assert(net::kMaxPlayers <= 32, "Current match-player mask assumes at most 32 player ids");
24
25 inline constexpr uint32_t kLobbyCountdownTicks = static_cast<uint32_t>(sim::kTickRate) * 3u;
26 inline constexpr uint32_t kMatchStartLoadTimeoutTicks = static_cast<uint32_t>(sim::kTickRate) * 5u;
27 inline constexpr uint32_t kMatchStartGoDelayTicks = static_cast<uint32_t>(sim::kTickRate);
28 inline constexpr uint32_t kMatchStartUnlockDelayTicks = kMatchStartGoDelayTicks;
29 inline constexpr uint32_t kEndOfMatchReturnTicks = static_cast<uint32_t>(sim::kTickRate) * 3u;
30
31 [[nodiscard]]
32 constexpr uint32_t playerMaskBit(const uint8_t playerId)
33 {
34 return 1u << playerId;
35 }
36
37 template<std::size_t N>
38 bool queueReliableControlToPlayer(ServerState& state,
39 const uint8_t playerId,
40 const net::EMsgType type,
41 const std::size_t payloadSize,
42 const std::array<uint8_t, N>& packet)
43 {
44 const auto* session = findPeerSessionByPlayerId(state, playerId);
45 const bool queued = session != nullptr &&
46 session->peer != nullptr &&
47 net::queueReliableControl(session->peer, packet);
48
49 state.diag.recordPacketSent(type,
50 playerId,
51 static_cast<uint8_t>(net::EChannel::ControlReliable),
52 net::kPacketHeaderSize + payloadSize,
53 queued ? net::NetPacketResult::Ok : net::NetPacketResult::Dropped);
54
55 return queued;
56 }
57
58 [[nodiscard]]
59 uint8_t computeCountdownSecondsRemaining(const ServerState& state);
60
61 [[nodiscard]]
62 constexpr std::string_view coarseServerFlowState(const ServerPhase phase)
63 {
64 switch (phase)
65 {
69 return "lobby";
71 return "in_match";
73 return "end_of_match";
74 }
75
76 return "lobby";
77 }
78
79 [[nodiscard]]
80 inline bool isServerIdleForDiagnostics(const ServerState& state)
81 {
82 if (coarseServerFlowState(state.phase) != "lobby")
83 return false;
84
85 return std::none_of(state.playerSlots.begin(),
86 state.playerSlots.end(),
87 [](const auto& slotEntry) { return slotEntry.has_value(); });
88 }
89
90 void cancelStartingMatch(ServerState& state, uint32_t notifyMask, std::string_view reason);
91} // namespace bomberman::server::flow_internal
92
93#endif // BOMBERMAN_SERVER_SERVERFLOWINTERNAL_H
Thin wrappers around ENet packet creation, queueing, and flushing.
Authoritative server receive-path entry point and shared handler declarations.
Authoritative server state model, lifecycle helpers, and fixed-tick simulation API.
Shared simulation tuning constants used by client and server gameplay code.
NetPacketResult
Diagnostics classification for one packet attempt or receive path outcome.
Definition NetDiagShared.h:49
bool queueReliableControl(ENetPeer *peer, const std::array< uint8_t, N > &bytes)
Queues a reliable control packet.
Definition NetSend.h:63
EMsgType
Message type identifiers used in packet headers.
Definition NetCommon.h:316
constexpr uint8_t kMaxPlayers
Maximum supported player count in a game instance.
Definition NetCommon.h:54
PeerSession * findPeerSessionByPlayerId(ServerState &state, const uint8_t playerId)
Returns the live peer session currently bound to playerId, if any.
Definition ServerSession.cpp:216
ServerPhase
High-level dedicated-server phase for the current lobby and match flow.
Definition ServerState.h:67
@ Lobby
Accepting players and waiting for match start.
@ StartingMatch
Transitioning accepted players from lobby into the next match.
@ LobbyCountdown
All required players are ready and the lobby countdown is running.
@ InMatch
Authoritative gameplay is active.
@ EndOfMatch
Match has finished and end-of-round presentation/results are active.
constexpr int16_t kTickRate
Simulation tick rate in Hz.
Definition SimConfig.h:14