1#ifndef BOMBERMAN_NET_CLIENTDIAGNOSTICS_H
2#define BOMBERMAN_NET_CLIENTDIAGNOSTICS_H
22#include <unordered_map>
24#include <nlohmann/json.hpp>
38 uint16_t protocolVersion = 0;
39 uint16_t clientTickRate = 0;
40 bool predictionEnabled =
false;
41 bool remoteSmoothingEnabled =
false;
43 std::optional<uint8_t> assignedPlayerId{};
44 std::optional<uint16_t> serverTickRate{};
50 uint64_t snapshotRecv = 0;
51 uint64_t correctionRecv = 0;
52 uint64_t inputSent = 0;
53 uint64_t gameplayEventRecv = 0;
62 uint64_t beginTimestampMs = 0;
63 uint64_t endTimestampMs = 0;
64 uint64_t durationMs = 0;
67 uint64_t connectedDurationMs = 0;
68 uint64_t handshakeDurationMs = 0;
70 uint32_t lastRttMs = 0;
71 uint32_t lastRttVarianceMs = 0;
72 uint32_t lastLossPermille = 0;
73 uint64_t transportSamples = 0;
74 uint64_t sampledRttMsTotal = 0;
75 uint64_t sampledRttVarianceMsTotal = 0;
76 uint64_t sampledLossPermilleTotal = 0;
79 bool predictionReachedActive =
false;
80 bool predictionEverRecovered =
false;
82 uint64_t packetsSent = 0;
83 uint64_t packetsRecv = 0;
84 uint64_t packetBytesSent = 0;
85 uint64_t packetBytesRecv = 0;
86 uint64_t packetsSentFailed = 0;
87 uint64_t packetsRecvFailed = 0;
88 uint64_t malformedPackets = 0;
89 uint64_t maxInputSendGapMs = 0;
91 uint64_t maxLobbySilenceMs = 0;
92 uint64_t maxGameplaySilenceMs = 0;
93 uint64_t staleSnapshotsIgnored = 0;
94 uint64_t staleCorrectionsIgnored = 0;
95 uint64_t brokenGameplayEventStreamIncidents = 0;
96 uint64_t maxPendingGameplayEventDepth = 0;
98 uint64_t recentEventsRecorded = 0;
99 uint64_t recentEventsEvicted = 0;
112 bool predictionEnabled,
113 bool remoteSmoothingEnabled);
119 uint16_t serverTickRate,
120 uint64_t handshakeDurationMs,
121 uint32_t transportPeerId);
136 std::optional<uint8_t> playerId,
137 uint32_t transportPeerId,
138 std::string_view note = {});
141 void sampleTransport(uint32_t rttMs, uint32_t rttVarianceMs, uint32_t lossPermille);
171 nlohmann::json
toJson()
const;
176 static uint64_t nowMs();
177 static uint64_t recentEventDedupeCooldownMs(
const NetEvent& event);
178 static std::string makeRecentEventSignature(
const NetEvent& event);
179 static bool isAlwaysEmitEvent(
const NetEvent& event);
183 void resetForNewSession(std::string_view ownerTag,
bool enabled);
184 void recordRecentEvent(NetEvent event);
185 void pushRecentEvent(NetEvent event);
187 bool enabled_ =
true;
188 bool sessionActive_ =
false;
190 std::string ownerTag_;
191 ClientSessionConfig config_{};
192 ClientSessionSummary summary_{};
193 ClientKeyMessageAggregates keyMessages_{};
195 std::array<NetEvent, kRecentEventCapacity> recentEvents_{};
196 std::size_t recentStart_ = 0;
197 std::size_t recentCount_ = 0;
198 std::unordered_map<std::string, RecentEventRepeatState> recentEventRepeatState_;
Client-side local prediction history, correction replay, and recovery state.
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.
Client-side multiplayer diagnostics recorder owned by NetClient.
Definition ClientDiagnostics.h:104
void recordStaleCorrectionIgnored(uint32_t serverTick, uint32_t lastProcessedInputSeq)
Records one stale correction rejected by the client.
Definition ClientDiagnostics.cpp:348
const ClientSessionSummary & summary() const
Returns the current aggregate session summary.
Definition ClientDiagnostics.h:164
void beginSession(std::string_view ownerTag, bool enabled, bool predictionEnabled, bool remoteSmoothingEnabled)
Starts a fresh diagnostics session and captures static client/session configuration.
Definition ClientDiagnostics.cpp:138
const ClientSessionConfig & config() const
Returns the static configuration captured for the current or last session.
Definition ClientDiagnostics.h:167
void recordPacketSent(EMsgType type, uint8_t channelId, std::size_t bytes, NetPacketResult result=NetPacketResult::Ok)
Records one outgoing packet attempt, including failures if the send was rejected.
Definition ClientDiagnostics.cpp:193
void feedPredictionStats(const PredictionStats &stats, bool reachedActive, bool everRecovered)
Merges the latest prediction helper stats into the session summary.
Definition ClientDiagnostics.cpp:391
void samplePendingGameplayEventDepth(std::size_t depth)
Tracks the deepest queued reliable gameplay-event backlog seen so far.
Definition ClientDiagnostics.cpp:382
void recordPacketRecv(EMsgType type, uint8_t channelId, std::size_t bytes, NetPacketResult result=NetPacketResult::Ok)
Records one incoming packet observation, including malformed or rejected packets.
Definition ClientDiagnostics.cpp:222
void sampleInputSendGap(uint32_t gapMs)
Tracks the longest gap between local input sends.
Definition ClientDiagnostics.cpp:308
void recordFinalState(EConnectState finalState, uint64_t connectedDurationMs)
Records the final connection state and how long the session stayed connected.
Definition ClientDiagnostics.cpp:187
void recordBrokenGameplayEventStream(uint32_t matchId)
Records a broken authoritative gameplay-event stream for the active match.
Definition ClientDiagnostics.cpp:366
void endSession()
Finalizes the active diagnostics session and stamps its end time.
Definition ClientDiagnostics.cpp:155
void sampleGameplaySilence(uint32_t gameplaySilenceMs)
Tracks gameplay-message silence while the client is in-match.
Definition ClientDiagnostics.cpp:324
void recordPeerLifecycle(NetPeerLifecycleType type, std::optional< uint8_t > playerId, uint32_t transportPeerId, std::string_view note={})
Records one peer/session lifecycle event such as connect, accept, reject, or disconnect.
Definition ClientDiagnostics.cpp:274
void recordMalformedPacket(uint8_t channelId, std::size_t bytes, std::string_view note={})
Records one malformed inbound packet incident.
Definition ClientDiagnostics.cpp:251
void recordStaleSnapshotIgnored(uint32_t serverTick)
Records one stale snapshot rejected by the client.
Definition ClientDiagnostics.cpp:332
void recordWelcome(uint8_t assignedPlayerId, uint16_t serverTickRate, uint64_t handshakeDurationMs, uint32_t transportPeerId)
Records handshake success details from the authoritative Welcome message.
Definition ClientDiagnostics.cpp:169
void sampleLobbySilence(uint32_t lobbySilenceMs)
Tracks lobby-message silence while the client is waiting in lobby flow.
Definition ClientDiagnostics.cpp:316
void sampleTransport(uint32_t rttMs, uint32_t rttVarianceMs, uint32_t lossPermille)
Samples live transport quality from ENet state.
Definition ClientDiagnostics.cpp:292
nlohmann::json toJson() const
Serializes the current diagnostics session to JSON.
Definition ClientDiagnostics.cpp:415
void recordEvent(const NetEvent &event)
Records one recent high-level diagnostics event in the bounded event buffer.
Definition ClientDiagnostics.cpp:403
bool writeJsonReport(std::string_view filePath) const
Writes the current diagnostics session as a JSON report file.
Definition ClientDiagnostics.cpp:534
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
EConnectState
Client connection lifecycle state.
Definition NetClient.h:25
Sparse per-message aggregates retained for client diagnostics and tuning.
Definition ClientDiagnostics.h:49
Client session metadata captured progressively as a multiplayer connection runs.
Definition ClientDiagnostics.h:37
Aggregate client-side diagnostics counters for one multiplayer session.
Definition ClientDiagnostics.h:58
Discrete diagnostics event stored in a recent-event ring buffer.
Definition NetDiagShared.h:66
Aggregate prediction stats for diagnostics.
Definition ClientPrediction.h:87