mcpField
N
networking-servers

networking-servers

github.com/pluginagentmarketplace開発4571 回インストール42 週間前に更新
リポジトリ

networking-servers について

マルチプレイヤーゲームを開発する人向けの、ネットワークとゲームサーバー設計スキルです。権威サーバー、ネットコード、帯域幅削減、不正対策、トラブルシューティングを扱います。

主な機能

  1. 01権威サーバーアーキテクチャ
  2. 02クライアント予測と補正
  3. 03サーバー側のラグ補償
  4. 04帯域幅の最適化手法
  5. 05多層的な不正対策
  6. 06ネットワークのトラブルシューティング

活用シーン

  1. 01マルチプレイヤーサーバーの設計
  2. 02応答性の高い移動処理の実装
  3. 03ネットワーク通信量の削減
  4. 04遅延やラバーバンディングの調査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/pluginagentmarketplace/custom-plugin-game-developer --skill networking-servers

インストール後、Claude Code で/networking-serversを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

assets/
networking_config.yaml
references/
NETWORKING_GUIDE.md
scripts/
network_analyzer.py

詳細

ネットワーキングとゲームサーバー

ネットワークアーキテクチャ

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│
└─────────────────────────────────────────────────────────────┘

ネットコードの実装

クライアント予測と調整
// ✅ 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);
        }
    }
}
ラグ補償
// ✅ 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);
            }
        }
    }
}

サーバーアーキテクチャ

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                                       │   │
│  └─────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────┘

帯域幅の最適化

手法削減率実装
差分圧縮60-80%変更された値のみを送信
量子化50-70%浮動小数点数 → 固定小数点数
ビットパッキング30-50%カスタムシリアライズ
関心領域管理70-90%関連するデータのみを送信
優先度キュー可変重要度が低いほど送信頻度を下げる

アンチチート戦略

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                                       │
└─────────────────────────────────────────────────────────────┘

🔧 トラブルシューティング

┌─────────────────────────────────────────────────────────────┐
│ 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                         │
└─────────────────────────────────────────────────────────────┘

フレームワークの比較

フレームワーク最適な用途最大プレイヤー数学習難易度
Photonすばやく開始16-32簡単
Mirrorオープンソース100+中程度
Netcode for GOUnity 公式100+中程度
FishNetパフォーマンス200+中程度
Custom完全な制御無制限難しい

このスキルを使う場面:マルチプレイヤーゲームの構築、サーバーの設計、またはアンチチートの実装。

コメント