group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Server::Connection Struct Reference

Per-client connection state. More...

Collaboration diagram for Server::Connection:
[legend]

Classes

struct  PendingReliableEvent
 Phase 3d-5: pending reliable events, each scheduled for remainingSends more cycles. More...

Public Attributes

MessageStream msgStream {}
 Framed message stream for this client.
ClientId clientId {}
 Unique identifier assigned on accept.
bool pendingInitialization = true
 True if waiting for Game to initialize player entity.
uint32_t lastAppliedInputTick = 0
 Highest InputSnapshot.tick this client has had applied to the simulation.
OutboundQueue outbound
 Per-client userspace outbound queue (Phase 3a).
std::uint64_t connectionId = 0
 Phase 3d: server-assigned UDP connection ID.
net::UdpEndpointAddr udpAddr
 Phase 3d: source address of the most-recent UDP packet from this client.
uint16_t udpSnapshotSequence = 0
 Phase 3d-4: per-client outgoing sequence for the Unreliable channel's snapshot stream.
uint16_t reliableNextSequence = 0
 Phase 3d-5: per-client outgoing sequence for the reliable event stream over UDP.
std::deque< PendingReliableEventreliableQueue
uint16_t lastReportedRttMs = 0
 Phase 6: client's most-recent self-reported smoothed RTT in milliseconds.
uint8_t lastReportedInterpDelaySnapshots = 0
 PR-12: client's most-recent self-reported render-delay in snapshots (i.e.
uint16_t lastReportedInterpDelayMs = 0
 PR-31: client's most-recent self-reported render delay in milliseconds, computed client-side as interpDelaySnapshots × EMA(observed snapshot-apply interval).
Uint64 chatWindowStartMs = 0
std::uint8_t chatMessagesInWindow = 0
Uint64 voiceWindowStartMs = 0
std::uint8_t voiceFramesInWindow = 0

Detailed Description

Per-client connection state.

PR-5b (server-perf): default-initialised for try_emplace in acceptClients. Pre-PR-5b the struct was copy-constructed from a designated-initialiser temporary, which would no longer compile once OutboundQueue grew an internal mutex.

Member Data Documentation

◆ chatMessagesInWindow

std::uint8_t Server::Connection::chatMessagesInWindow = 0

◆ chatWindowStartMs

Uint64 Server::Connection::chatWindowStartMs = 0

◆ clientId

ClientId Server::Connection::clientId {}

Unique identifier assigned on accept.

◆ connectionId

std::uint64_t Server::Connection::connectionId = 0

Phase 3d: server-assigned UDP connection ID.

Generated when the TCP connection is accepted and shipped to the client in the ASSIGN_CLIENT_ID packet. Clients stamp every outbound UDP datagram with this; the server demuxes incoming UDP via connIdToClient_ to find which TCP-established client the datagram is from. 0 = not yet assigned.

◆ lastAppliedInputTick

uint32_t Server::Connection::lastAppliedInputTick = 0

Highest InputSnapshot.tick this client has had applied to the simulation.

Used to dedup multi-input redundancy: each client sends the last N inputs every tick, so most arrivals are duplicates of already-applied data. We accept only inputs strictly newer than this value and update it as we process. Resets to 0 on reconnect because each Connection is constructed fresh.

◆ lastReportedInterpDelayMs

uint16_t Server::Connection::lastReportedInterpDelayMs = 0

PR-31: client's most-recent self-reported render delay in milliseconds, computed client-side as interpDelaySnapshots × EMA(observed snapshot-apply interval).

Unlike the snapshot count above — which the server multiplies by its own nominal cadence — this carries the client's measured render time, so it stays accurate when network jitter or the post-join warm-up window pushes the effective snapshot rate away from nominal.

updateLagCompTargets prefers this term whenever it is non-zero (server::lagcomp::computeRewindTicks), falling back to the snapshot-count path when it is 0 (interp disabled, or a client that predates this field). Stays at 0 until the first INPUT packet arrives.

◆ lastReportedInterpDelaySnapshots

uint8_t Server::Connection::lastReportedInterpDelaySnapshots = 0

PR-12: client's most-recent self-reported render-delay in snapshots (i.e.

their cl_interp value). The PR-11 renderer plays back at now − N × snapshotInterval for some client-chosen N (default 2). Lag comp must include this term in its rewind so the server hitbox state lines up with what the client SAW when they pulled the trigger — not merely with what the server held at INPUT-arrival time.

New rewind formula: targetServerTick = currentServerTick − clamp(rttHalfTicks + interpDelayTicks, 0, k_maxLagCompTicks)

where interpDelayTicks = N × (tickRateHz / snapshotRateHz). At default 32 Hz snapshots / 128 Hz physics, N=2 → 8 ticks (~62.5 ms). Clamped to InterpolationBuffer::k_capacity (8) on the wire, so the worst case is 8 snapshots × 4 ticks = 32 ticks (250 ms) of interp on top of RTT/2.

Stays at 0 until the first INPUT packet arrives. Source engine ships this value over the wire as well — see TF2 cl_interp / Quake cl_interp_ratio.

◆ lastReportedRttMs

uint16_t Server::Connection::lastReportedRttMs = 0

Phase 6: client's most-recent self-reported smoothed RTT in milliseconds.

Updated on every INPUT packet (the 2-byte rttMs prefix in the wire format). Read by the lag-compensation scheduler each server tick to size this client's hitscan rewind window — targetServerTick = currentServerTick - clamp(rttMs/2 → ticks, 0, k_maxLagCompTicks). Stays at 0 until the first INPUT packet arrives, which means brand-new connections start with no rewind (correct: their PING/PONG hasn't completed yet so any rewind would be guesswork).

◆ msgStream

MessageStream Server::Connection::msgStream {}

Framed message stream for this client.

◆ outbound

OutboundQueue Server::Connection::outbound

Per-client userspace outbound queue (Phase 3a).

All broadcast helpers push into this queue; the queue is then flushed once at end-of-tick via flushAllOutbound(). The replace-on-stale semantics mean a slow drainer only ever has one pending UPDATE_REGISTRY in flight (always the freshest), instead of accumulating dozens of obsolete snapshots in SDL3_net's internal pending_output_buffer.

◆ pendingInitialization

bool Server::Connection::pendingInitialization = true

True if waiting for Game to initialize player entity.

◆ reliableNextSequence

uint16_t Server::Connection::reliableNextSequence = 0

Phase 3d-5: per-client outgoing sequence for the reliable event stream over UDP.

Each pushed event gets next-sequence; client dedups against a sliding-window bitset of recently-seen sequences.

◆ reliableQueue

std::deque<PendingReliableEvent> Server::Connection::reliableQueue

◆ udpAddr

net::UdpEndpointAddr Server::Connection::udpAddr

Phase 3d: source address of the most-recent UDP packet from this client.

Filled in lazily on first UDP receive (the client's actual UDP source port isn't known until then — it's auto-assigned by their kernel). Server uses this to route UDP replies (PONG, future server→client UDP traffic).

◆ udpSnapshotSequence

uint16_t Server::Connection::udpSnapshotSequence = 0

Phase 3d-4: per-client outgoing sequence for the Unreliable channel's snapshot stream.

Increments on every snapshot the server sends to this client. Receiver uses it to drop stale fragments when a newer set arrives.

◆ voiceFramesInWindow

std::uint8_t Server::Connection::voiceFramesInWindow = 0

◆ voiceWindowStartMs

Uint64 Server::Connection::voiceWindowStartMs = 0

The documentation for this struct was generated from the following file: