1#ifndef BOMBERMAN_NET_NETDIAGNOSTICS_H
2#define BOMBERMAN_NET_NETDIAGNOSTICS_H
10#include <unordered_map>
12#include <nlohmann/json.hpp>
34 uint16_t protocolVersion = 0;
35 uint16_t tickRate = 0;
36 uint32_t inputLeadTicks = 0;
37 uint32_t snapshotIntervalTicks = 0;
38 uint32_t brickSpawnRandomize = 0;
39 uint32_t powerupsPerRound = 0;
40 uint8_t maxPlayers = 0;
41 bool powersEnabled =
true;
47 uint64_t snapshotSent = 0;
48 uint64_t correctionSent = 0;
49 uint64_t inputRecv = 0;
50 uint64_t gameplayEventSent = 0;
61 uint64_t beginTimestampMs = 0;
62 uint64_t endTimestampMs = 0;
63 uint64_t durationMs = 0;
65 uint64_t tickCount = 0;
67 uint64_t recentEventsRecorded = 0;
68 uint64_t recentEventsEvicted = 0;
70 uint64_t packetsSent = 0;
71 uint64_t packetsRecv = 0;
72 uint64_t packetBytesSent = 0;
73 uint64_t packetBytesRecv = 0;
74 uint64_t packetsSentFailed = 0;
75 uint64_t packetsRecvFailed = 0;
76 uint64_t malformedPacketsRecv = 0;
78 uint64_t inputPacketsReceived = 0;
79 uint64_t inputPacketsFullyStale = 0;
80 uint64_t inputEntriesTooLate = 0;
83 uint64_t inputEntriesTooFarAhead = 0;
88 uint64_t bombsPlaced = 0;
89 uint64_t bricksDestroyed = 0;
90 uint64_t roundsEnded = 0;
91 uint64_t roundsDrawn = 0;
115 void beginSession(std::string_view ownerTag,
bool enabled =
true);
166 void recordSimulationGap(uint8_t peerId, uint32_t inputSeq, uint8_t heldButtons, uint32_t serverTick);
179 void recordRoundEnded(std::optional<uint8_t> winnerPlayerId,
bool endedInDraw, uint32_t serverTick);
184 void samplePeerTransport(uint8_t peerId, uint32_t rttMs, uint32_t rttVarianceMs, uint32_t packetLossPermille, uint32_t queuedReliable, uint32_t queuedUnreliable);
190 void recordServerFlowState(std::string_view stateName,
bool idle, uint32_t serverTick, uint32_t matchId = 0);
202 nlohmann::json
toJson()
const;
210 static uint64_t nowMs();
211 static uint64_t recentEventDedupeCooldownMs(
const NetEvent& event);
212 static std::string makeRecentEventSignature(
const NetEvent& event);
213 static bool isAlwaysEmitEvent(
const NetEvent& event);
222 void resetForNewSession(std::string_view ownerTag,
bool enabled);
225 void recordRecentEvent(
NetEvent event);
227 void pushRecentEvent(
NetEvent event);
231 bool enabled_ =
true;
232 bool sessionActive_ =
false;
234 std::string ownerTag_;
238 std::string serverFlowState_;
239 bool serverIdle_ =
false;
241 std::array<NetEvent, kRecentEventCapacity> recentEvents_{};
242 std::size_t recentStart_ = 0;
243 std::size_t recentCount_ = 0;
245 std::unordered_map<uint8_t, NetPeerTransportSample> latestPeerSamples_;
246 std::unordered_map<uint8_t, NetPeerContinuitySummary> peerContinuitySummaries_;
247 std::unordered_map<std::string, RecentEventRepeatState> recentEventRepeatState_;
Shared client/server wire contract for the multiplayer protocol.
Shared policy constants for lightweight multiplayer diagnostics.
Shared diagnostics event/sample types used by both server and client recorders.
Session-local recorder for recent multiplayer diagnostics and aggregate counters.
Definition NetDiagnostics.h:103
nlohmann::json toJson() const
Serializes the current diagnostics state as JSON.
Definition NetDiagnostics.cpp:546
void recordBufferedDeadlineRecovery(uint8_t peerId, uint32_t inputSeq, uint32_t serverTick)
Records a buffered deadline recovery where redundant history supplied the exact seq before consume ti...
Definition NetDiagnostics.cpp:389
void recordInputEntriesTooLate(uint32_t count)
Records input entries that arrived after their sequence had already been processed.
Definition NetDiagnostics.cpp:314
void recordMalformedPacketRecv(uint8_t peerId, uint8_t channelId, std::size_t bytes, std::string_view note={})
Records an incoming packet that failed before typed dispatch, such as a malformed header.
Definition NetDiagnostics.cpp:255
void samplePeerInputContinuity(uint8_t peerId, uint32_t lastReceivedInputSeq, uint32_t lastProcessedInputSeq)
Stores the latest input progression cursors for a peer.
Definition NetDiagnostics.cpp:478
void recordInputEntriesTooLateBuffered(uint32_t count)
Records late entries that arrived only as redundant buffered history.
Definition NetDiagnostics.cpp:330
void endSession()
Ends the current diagnostics session and finalizes duration fields.
Definition NetDiagnostics.cpp:145
void recordInputPacketReceived()
Records one input packet that was received and parsed successfully.
Definition NetDiagnostics.cpp:298
void recordSessionConfig(ServerSessionConfig config)
Captures static server session config for later reporting output.
Definition NetDiagnostics.cpp:529
void recordDirectDeadlineConsume(uint8_t peerId, uint32_t inputSeq)
Records a direct consume where the exact seq was present by deadline with a direct/newest batch entry...
Definition NetDiagnostics.cpp:376
void recordPeerLifecycle(NetPeerLifecycleType type, uint8_t peerId, uint32_t transportPeerId, std::string_view note={})
Records a structured peer lifecycle event.
Definition NetDiagnostics.cpp:280
void recordPacketRecv(EMsgType type, uint8_t peerId, uint8_t channelId, std::size_t bytes, NetPacketResult result=NetPacketResult::Ok)
Records one incoming packet attempt and updates packet summary totals.
Definition NetDiagnostics.cpp:219
void recordBricksDestroyed(uint32_t count)
Records bricks destroyed by one authoritative explosion resolution.
Definition NetDiagnostics.cpp:421
void recordServerFlowState(std::string_view stateName, bool idle, uint32_t serverTick, uint32_t matchId=0)
Records the current coarse server flow state and derived idle flag.
Definition NetDiagnostics.cpp:492
void beginSession(std::string_view ownerTag, bool enabled=true)
Starts a new diagnostics session and clears previous session state.
Definition NetDiagnostics.cpp:135
void recordRoundEnded(std::optional< uint8_t > winnerPlayerId, bool endedInDraw, uint32_t serverTick)
Records one authoritative round-end outcome.
Definition NetDiagnostics.cpp:429
void recordInputEntriesTooLateDirect(uint32_t count)
Records late entries that were the newest/direct command of their received batch.
Definition NetDiagnostics.cpp:322
void recordPacketSent(EMsgType type, uint8_t peerId, uint8_t channelId, std::size_t bytes, NetPacketResult result=NetPacketResult::Ok)
Records one outgoing packet attempt and updates packet summary totals.
Definition NetDiagnostics.cpp:183
bool writeJsonReport(std::string_view filePath) const
Writes a machine-readable JSON session report to disk.
Definition NetDiagnostics.cpp:680
void advanceTick()
Advances per-session tick bookkeeping.
Definition NetDiagnostics.cpp:538
void recordInputPacketFullyStale(uint32_t count=1)
Records a fully stale input packet whose newest sequence was already consumed.
Definition NetDiagnostics.cpp:306
void recordEvent(const NetEvent &event)
Records a fully populated recent event.
Definition NetDiagnostics.cpp:171
void recordInputEntriesTooFarAhead(uint32_t count)
Records input entries rejected for being too far ahead of the accepted receive window.
Definition NetDiagnostics.cpp:338
void recordBombPlaced()
Records one authoritative bomb placement accepted by the server simulation.
Definition NetDiagnostics.cpp:413
void recordSimulationGap(uint8_t peerId, uint32_t inputSeq, uint8_t heldButtons, uint32_t serverTick)
Records a consume deadline miss that required reusing the previous buttons for a gameplay peer.
Definition NetDiagnostics.cpp:346
void samplePeerTransport(uint8_t peerId, uint32_t rttMs, uint32_t rttVarianceMs, uint32_t packetLossPermille, uint32_t queuedReliable, uint32_t queuedUnreliable)
Stores the latest sampled transport health values for a peer.
Definition NetDiagnostics.cpp:456
Shared multiplayer protocol types and transport-facing wire helpers.
Definition ClientPrediction.cpp:13
NetEventType
High-level kinds of recent events captured during a diagnostics session.
Definition NetDiagShared.h:19
NetPacketResult
Diagnostics classification for one packet attempt or receive path outcome.
Definition NetDiagShared.h:49
EMsgType
Message type identifiers used in packet headers.
Definition NetCommon.h:316
NetPeerLifecycleType
Peer lifecycle milestones emitted by multiplayer networking flows.
Definition NetDiagShared.h:32
Discrete diagnostics event stored in a recent-event ring buffer.
Definition NetDiagShared.h:66
Aggregate counters and timing collected across one diagnostics session.
Definition NetDiagnostics.h:57
uint64_t simulationGaps
Consume deadlines that reused previous buttons because the exact input was missing.
Definition NetDiagnostics.h:86
uint64_t inputEntriesTooLateDirect
Already-processed entries that were also the newest/direct command in their batch.
Definition NetDiagnostics.h:81
uint64_t directDeadlineConsumes
Exact-next input sequence present by deadline with a direct/newest batch entry.
Definition NetDiagnostics.h:85
uint64_t bufferedDeadlineRecoveries
Redundant history supplied the exact sequence by deadline without the direct/newest entry.
Definition NetDiagnostics.h:87
uint64_t inputEntriesTooLateBuffered
Already-processed entries received only through buffered redundant history.
Definition NetDiagnostics.h:82
std::array< uint64_t, kMaxPlayers > roundWinsByPlayerId
Round wins keyed by authoritative player id.
Definition NetDiagnostics.h:92
Sparse per-message aggregates retained for server tuning.
Definition NetDiagnostics.h:46
Static server-side session configuration captured into diagnostics output.
Definition NetDiagnostics.h:33