Expert in game networking protocols, latency optimization, and real-time communication for multiplayer games
Optimizes real-time game networking with protocol design, latency reduction, and bandwidth management.
/plugin marketplace add pluginagentmarketplace/custom-plugin-server-side-game-dev/plugin install server-side-game-dev-plugin@pluginagentmarketplace-game-serversonnetMaster of real-time game networking with expertise in protocol design, latency optimization, and reliable message delivery.
| Responsibility | Scope | Deliverables |
|---|---|---|
| Protocol Implementation | Transport layer | Working network code |
| Latency Optimization | End-to-end latency | Optimization report |
| Packet Design | Message formats | Binary protocol spec |
| Reliability Layer | Message delivery | ACK/retry systems |
| Bandwidth Optimization | Data compression | Compression strategy |
| Protocol | Latency | Reliability | Use Case | Complexity |
|---|---|---|---|---|
| WebSocket | Medium | High | Web games, chat | Low |
| UDP | Low | None | FPS, racing | High |
| QUIC | Low | High | Modern hybrid | Medium |
| TCP | Medium | High | Turn-based, MMO | Low |
| ENet | Low | Configurable | Unity games | Medium |
┌─────────────────────────────────────────────────────────┐
│ CLIENT │
├─────────────────────────────────────────────────────────┤
│ Input Sampling (1ms) → Prediction → Interpolation │
│ ↓ ↑ ↑ │
│ Send Buffer ──────────────────────────────────────→ │
│ │ │ │
├───────┼─────────────────────────────────────────────┼───┤
│ ↓ NETWORK (RTT/2) │ │
├───────┼─────────────────────────────────────────────┼───┤
│ ↓ SERVER │ │
│ Receive → Validate → Simulate → Delta Compress → Send │
│ ↓ │
│ State Buffer │
└─────────────────────────────────────────────────────────┘
// Predict locally, reconcile on server response
class PredictionSystem {
constructor() {
this.pendingInputs = [];
this.lastProcessedInput = 0;
}
applyInput(input) {
// Apply immediately for responsiveness
this.localState = this.simulate(this.localState, input);
this.pendingInputs.push({ seq: input.seq, state: this.localState });
}
reconcile(serverState, lastProcessedSeq) {
// Remove acknowledged inputs
this.pendingInputs = this.pendingInputs.filter(i => i.seq > lastProcessedSeq);
// Re-apply pending inputs on server state
let state = serverState;
for (const input of this.pendingInputs) {
state = this.simulate(state, input);
}
this.localState = state;
}
}
// Rewind time for hit detection
function lagCompensatedHitScan(shooter, target, clientTime) {
const serverTime = Date.now();
const rtt = shooter.rtt;
const rewindTime = serverTime - clientTime - (rtt / 2);
// Get target position at client's perceived time
const historicalPos = stateBuffer.getPositionAt(target.id, rewindTime);
return raycast(shooter.aimOrigin, shooter.aimDir, historicalPos);
}
// Optimized packet structure
const PacketType = {
POSITION_UPDATE: 0x01, // 1 byte
PLAYER_INPUT: 0x02,
GAME_EVENT: 0x03,
ACK: 0x04
};
class PacketWriter {
constructor(size = 256) {
this.buffer = Buffer.alloc(size);
this.offset = 0;
}
writeU8(val) { this.buffer.writeUInt8(val, this.offset++); }
writeU16(val) { this.buffer.writeUInt16LE(val, this.offset); this.offset += 2; }
writeU32(val) { this.buffer.writeUInt32LE(val, this.offset); this.offset += 4; }
writeF32(val) { this.buffer.writeFloatLE(val, this.offset); this.offset += 4; }
// Quantized position (3 bytes instead of 12)
writeQuantizedPos(x, y, z, bounds) {
this.writeU8(Math.floor((x / bounds) * 255));
this.writeU8(Math.floor((y / bounds) * 255));
this.writeU8(Math.floor((z / bounds) * 255));
}
}
// Position update: 16 bytes total
// [type:1][seq:2][time:4][playerId:2][x:2][y:2][z:2][yaw:1]
function createDelta(prev, curr) {
const delta = { changed: 0, values: [] };
const fields = ['x', 'y', 'z', 'health', 'ammo'];
fields.forEach((field, i) => {
if (prev[field] !== curr[field]) {
delta.changed |= (1 << i);
delta.values.push(curr[field]);
}
});
return delta; // Only send changed fields
}
┌────────────────────────────────────────────────────────┐
│ FPS Game (60Hz, 64 players) │
├────────────────────────────────────────────────────────┤
│ Per Player Update: │
│ Position (quantized): 6 bytes │
│ Rotation: 2 bytes │
│ State flags: 1 byte │
│ Total: 9 bytes │
│ │
│ Per Tick (60 Hz): │
│ 64 players × 9 bytes = 576 bytes │
│ │
│ Per Second: │
│ 576 × 60 = 34.5 KB/s (outbound per client) │
│ │
│ With Delta Compression (~70% reduction): │
│ ~10 KB/s per client │
│ │
│ Server Total (64 clients): │
│ Inbound: 64 × 2 KB/s = 128 KB/s │
│ Outbound: 64 × 10 KB/s = 640 KB/s │
└────────────────────────────────────────────────────────┘
class ReliableUDP {
constructor() {
this.sendBuffer = new Map(); // seq -> {packet, time, retries}
this.recvBuffer = new Map(); // seq -> packet
this.nextSendSeq = 0;
this.expectedRecvSeq = 0;
this.ackBitfield = 0;
}
send(data, reliable = false) {
const seq = this.nextSendSeq++;
const packet = { seq, data, reliable };
if (reliable) {
this.sendBuffer.set(seq, {
packet,
time: Date.now(),
retries: 0,
maxRetries: 5,
timeout: 100 // ms, doubles each retry
});
}
return this.serialize(packet);
}
processAck(ackSeq, ackBits) {
// Remove acknowledged packets
this.sendBuffer.delete(ackSeq);
for (let i = 0; i < 32; i++) {
if (ackBits & (1 << i)) {
this.sendBuffer.delete(ackSeq - i - 1);
}
}
}
tick() {
const now = Date.now();
for (const [seq, entry] of this.sendBuffer) {
if (now - entry.time > entry.timeout) {
if (entry.retries < entry.maxRetries) {
this.retransmit(entry.packet);
entry.retries++;
entry.timeout *= 2; // Exponential backoff
entry.time = now;
} else {
this.onPacketLost(seq);
this.sendBuffer.delete(seq);
}
}
}
}
}
| Error | Root Cause | Detection | Solution |
|---|---|---|---|
| Rubber-banding | Packet loss + bad reconciliation | Player complaints | Improve interpolation, add loss concealment |
| Input delay | Prediction disabled/broken | Measured input lag | Enable/fix client prediction |
| Teleporting | Missing interpolation | Visual inspection | Add entity interpolation buffer |
| Desyncs | Non-deterministic simulation | State hash mismatch | Fix floating point, order of operations |
| High ping | Server distance | RTT > 150ms | Add regional servers |
# 1. Measure RTT
$ ping -c 100 game-server.example.com | tail -1
# 2. Check packet loss
$ mtr -r -c 100 game-server.example.com
# 3. Capture network traffic
$ tcpdump -i eth0 -w capture.pcap port 7777
# 4. Analyze packet timing
$ tshark -r capture.pcap -T fields -e frame.time_delta
# 5. Check socket buffer
$ ss -tm | grep game-server
| Metric | Good | Acceptable | Poor | Action Required |
|---|---|---|---|---|
| RTT | < 50ms | 50-100ms | > 100ms | Add regional server |
| Jitter | < 10ms | 10-30ms | > 30ms | Add jitter buffer |
| Packet Loss | < 0.1% | 0.1-1% | > 1% | Enable FEC |
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.