networking-servers

from pluginagentmarketplace/custom-plugin-game-developer

Game developer roadmap plugin with engine-specific patterns and optimization

3 stars0 forksUpdated Jan 5, 2026
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill networking-servers

SKILL.md

Networking & Game Servers

Network Architecture

CLIENT-SERVER (AUTHORITATIVE):
┌─────────────────────────────────────────────────────────────┐
│                   DEDICATED SERVER                           │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  • Authoritative game state                          │   │
│  │  • Physics simulation                                │   │
│  │  • Hit validation                                    │   │
│  │  • Anti-cheat checks                                 │   │
│  └─────────────────────────────────────────────────────┘   │
│       ↑↓              ↑↓              ↑↓              ↑↓    │
│   [Client A]    [Client B]    [Client C]    [Client D]     │
│   └─ Prediction  └─ Prediction  └─ Prediction  └─ Prediction│
└─────────────────────────────────────────────────────────────┘

Netcode Implementation

Client Prediction with Reconciliation

// ✅ Production-Ready: Prediction + Reconciliation System
public class NetworkedMovement : NetworkBehaviour
{
    private struct InputPayload
    {
        public uint Tick;
        public uint Sequence;
        public Vector2 MoveInput;
        public bool Jump;
    }

    private Queue<InputPayload> _pendingInputs = new();
    private CircularBuffer<PlayerState> _stateHistory;
    private uint _inputSequence;

    private void Update()
    {
        if (!IsOwner) return;

        // Capture input
        var input = new InputPayload
        {
            Tick = NetworkManager.ServerTime.Tick,
            Sequence = _inputSequence++,
            MoveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")),
            Jump = Input.GetButtonDown("Jump")
        };

        // Predict locally (immediate response)
        ApplyInput(input);

        // Store for reconciliation
        _pendingInputs.Enqueue(input);
        _stateHistory.Add(GetCurrentState());

        // Send to server
        SendInputServerRpc(input);
    }

    [ClientRpc]
    private void ReconcileClientRpc(uint ackedSequence, PlayerState serverState)
    {
        if (!IsOwner) return;

        // Remove acknowledged inputs
        while (_pendingInputs.Count > 0 && _pendingInputs.Peek().Sequence <= ackedSequence)
            _pendingInputs.Dequeue();

        // Check for prediction error
        var predictedState = _stateHistory.Get(ackedSequence);
        if (Vector3.Distance(predictedState.Position, serverState.Position) > 0.01f)
        {
            // Reconcile: reset to server state, replay pending inputs
            SetState(serverState);
            foreach (var input in _pendingInputs)
                ApplyInput(input);
        }
    }
}

Lag Compensation

// ✅ Production-Ready: Server-Side Rewind
public class LagCompensation : NetworkBehaviour
{
    private const int HISTORY_SIZE = 128;
    private const float MAX_REWIND_MS = 200f;

    private CircularBuffer<PositionSnapshot>[] _playerHistory;

    [ServerRpc]
    public void RequestHitValidationServerRpc(uint shooterClientId,
        Vector3 shootOrigin, Vector3 shootDirection, uint targetClientId)
    {
        // Get shooter's RTT
        float rtt = NetworkManager.ConnectedClients[shooterClientId].RTT;
        float rewindTime = Mathf.Min(rtt / 2f + 50f, MAX_REWIND_MS);

        // Get target's position at that time
        var targetPastPosition = GetPositionAtTime(targetClientId,
            Time.time - (rewindTime / 1000f));

        // Perform hit check at rewound position
        if (Physics.Raycast(shootOrigin, shootDirection, out var hit))
        {
            if (Vector3.Distance(hit.point, targetPastPosition) < 1f)
            {
                // Valid hit - apply damage
                ApplyDamage(targetClientId, 25);
            }
        }
    }
}

Server Architecture

SCALABLE SERVER ARCHITECTURE:
┌─────────────────────────────────────────────────────────────┐
│  LOAD BALANCER (Global)                                      │
│         ↓                                                    │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  MATCHMAKING SERVICE                                  │   │
│  │  • Player queuing                                     │   │
│  │  • Skill-based matching                               │   │
│  │  • Session creation                                   │   │
│  └─────────────────────────────────────────────────────┘   │
│         ↓                                                    │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  GAME SERVERS (Auto-scaled)                          │   │
│  │  [US-East] [US-West] [EU] [Asia]                     │   │
│  │  Each region: 10-1000 instances                       │   │
│  └─────────────────────────────────────────────────────┘   │
│         ↓                                                    │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  DATABASE CL

...
Read full content

Repository Stats

Stars3
Forks0
LicenseOther