Skip to content

zuedev/rust-authoritative-netcode-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Authoritative Netcode Demo

Demonstrating core techniques for responsive, cheat-resistant multiplayer games in Rust.

A networked multiplayer demo built in Rust showcasing server-authoritative architecture with client-side prediction, server reconciliation, entity interpolation, and lag compensation. Built to demonstrate the core netcode techniques behind responsive, cheat-resistant multiplayer games.

✨ Features

  • Server Authority — The server is the single source of truth; clients cannot manipulate game state directly.
  • Client-Side Prediction — Inputs are applied locally and immediately for zero-latency-feeling movement.
  • Server Reconciliation — Clients replay unacknowledged inputs after receiving authoritative state, correcting drift smoothly.
  • Entity Interpolation — Remote players are rendered in the past and interpolated between snapshots for smooth motion.
  • Lag Compensation — Hit detection rewinds the world to the shooter's view at the time of fire.
  • Snapshot Compression & Delta Encoding — Only changed state is transmitted to minimize bandwidth.
  • Configurable Network Conditions — Built-in simulated latency, jitter, and packet loss for testing.

🏗️ Architecture

┌─────────────┐         UDP          ┌─────────────┐
│   Client A  │◄────────────────────►│             │
└─────────────┘    inputs / snapshots│             │
                                     │   Server    │
┌─────────────┐                      │ (authority) │
│   Client B  │◄────────────────────►│             │
└─────────────┘                      └─────────────┘
  • Client sends timestamped input commands and predicts the result locally.
  • Server processes inputs at a fixed tick rate, simulates the authoritative world, and broadcasts snapshots.
  • Reconciliation occurs when a client receives a snapshot: it discards acknowledged inputs and replays the rest.

Tick Rates

Component Rate
Server simulation 60 Hz
Snapshot send 20 Hz
Client render Uncapped

🛠️ Tech Stack

🚀 Getting Started

Prerequisites

Build

git clone https://github.com/zuedev/rust-authoritative-netcode-demo.git
cd rust-authoritative-netcode-demo
cargo build --release

Run the Server

cargo run --release --bin server -- --port 7777 --tick-rate 60

Run a Client

cargo run --release --bin client -- --connect 127.0.0.1:7777

Launch multiple clients to see prediction and interpolation in action.

🎮 Controls

Key Action
WASD Move
Mouse Aim
Click Fire
F3 Toggle netgraph
Esc Quit

🔬 Debugging & Visualization

Press F3 in the client to display the netgraph overlay, which shows:

  • Round-trip time (RTT) and jitter
  • Prediction error / reconciliation corrections
  • Interpolation buffer state
  • Packet loss percentage

Simulating Bad Network Conditions

cargo run --release --bin client -- --connect 127.0.0.1:7777 --sim-latency 100 --sim-jitter 20 --sim-loss 0.05

🧪 Testing

Run the full unit-test suite — covering the wire protocol and delta encoding, the deterministic simulation, server input handling and lag compensation, and client prediction / reconciliation / interpolation:

cargo test --workspace

For an end-to-end check without opening a window, run the headless smoke test in a second terminal while the server is running. It connects, drives a player, and asserts that the authoritative server moves it and emits delta snapshots:

# terminal 1
cargo run --bin server

# terminal 2
cargo run -p client --example headless_smoke

📊 Benchmarks

The performance-critical paths — the deterministic simulation step, hitscan ray casts, and delta snapshot encoding / decoding — are benchmarked with criterion:

cargo bench -p shared

📁 Project Structure

.
├── crates/
│   ├── shared/      # Types, protocol, deterministic simulation (unit tests + benches)
│   ├── server/      # Authoritative server binary (unit tests)
│   └── client/      # Predicting client binary (unit tests + headless example)
└── Cargo.toml       # Workspace manifest

📚 References

This project draws on well-known netcode resources:

About

Demonstrating core techniques for responsive, cheat-resistant multiplayer games in Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages