networking-servers
25
总安装量
18
周安装量
#14574
全站排名
安装命令
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill networking-servers
Agent 安装分布
claude-code
15
gemini-cli
12
opencode
12
cursor
11
antigravity
10
codex
10
Skill 文档
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 CLUSTER â â
â â ⢠Player profiles â â
â â ⢠Match history â â
â â ⢠Leaderboards â â
â âââââââââââââââââââââââââââââââââââââââââââââââââââââââ â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Bandwidth Optimization
| Technique | Savings | Implementation |
|---|---|---|
| Delta Compression | 60-80% | Only send changed values |
| Quantization | 50-70% | Float â fixed-point |
| Bit Packing | 30-50% | Custom serialization |
| Interest Management | 70-90% | Only send relevant data |
| Priority Queue | Variable | Less important = less often |
Anti-Cheat Strategies
ANTI-CHEAT LAYERS:
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â LAYER 1: Server Authority â
â â All game state validated on server â
â â Never trust client â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â LAYER 2: Sanity Checks â
â â Movement speed limits â
â â Action rate limits â
â â Position validation â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â LAYER 3: Statistical Detection â
â â Inhuman accuracy patterns â
â â Impossible reaction times â
â â Abnormal session metrics â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â LAYER 4: Client-Side (Optional) â
â â Memory scanning (EAC, BattlEye) â
â â Process monitoring â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
ð§ Troubleshooting
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: Players rubber-banding / teleporting â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Increase interpolation buffer â
â â Add jitter buffer for packets â
â â Smooth corrections (lerp, not snap) â
â â Check prediction code determinism â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: Desyncs between clients â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Use fixed-point math â
â â Sync random seeds â
â â Periodic full-state resync â
â â State hash comparison â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
â PROBLEM: High bandwidth usage â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¤
â SOLUTIONS: â
â â Implement delta compression â
â â Reduce tick rate for non-critical data â
â â Use interest management â
â â Quantize position/rotation values â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
Framework Comparison
| Framework | Best For | Max Players | Learning Curve |
|---|---|---|---|
| Photon | Quick start | 16-32 | Easy |
| Mirror | Open source | 100+ | Medium |
| Netcode for GO | Unity official | 100+ | Medium |
| FishNet | Performance | 200+ | Medium |
| Custom | Full control | Unlimited | Hard |
Use this skill: When building multiplayer, designing servers, or implementing anti-cheat.