About pubnub-multiplayer-gaming
pubnub-multiplayer-gaming is a developer skill for designing real-time multiplayer games with PubNub. It covers room and lobby setup, matchmaking, synchronized game state, player lifecycle, and related game features.
Key features
- 01Plan lobby and game-room channels
- 02Design matchmaking and room assignment
- 03Synchronize state with deltas and recovery
- 04Handle player presence and reconnection
- 05Address validation, chat, and leaderboards
Use cases
- 01Building multiplayer lobbies and game rooms
- 02Pairing players by skill or rank
- 03Recovering game sessions after disconnects
- 04Adding spectator modes or in-game chat
MCP support
When PubNub MCP tools are available, the skill routes to documentation and operations such as function management, token grants, and app checks. It advises enabling PubNub MCP for API details and live operations when those tools are absent.
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ pubnub/ skills --skill pubnub-multiplayer-gamingAfter installing, type/pubnub-multiplayer-gamingin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
tile.jsonevals/instructions.jsonsummary_infeasible.jsonsummary.jsonevals/scenario-0/capability.txtcriteria.jsontask.mdevals/scenario-1/capability.txtcriteria.jsontask.mdevals/scenario-2/capability.txtcriteria.jsontask.mdevals/scenario-3/capability.txtcriteria.jsontask.mdevals/scenario-4/capability.txtcriteria.jsontask.mdreferences/gaming-patterns.mdgaming-setup.mdgaming-state-sync.mdDetails
From the project READMEPubNub Multiplayer Gaming Specialist
You are a PubNub multiplayer gaming specialist. Your role is to help developers build real-time multiplayer games using PubNub's publish/subscribe infrastructure for game state synchronization, player matchmaking, game room management, lobby systems, and in-game communication.
Precedence: PubNub MCP tools and pubnub.com/docs are authoritative for API shapes, limits, and configuration values. This skill is authoritative for patterns, sequencing, and design tradeoffs.
When PubNub MCP tools are absent: Treat PubNub MCP as absent only when this session has no PubNub MCP tools (typically namespace
user-pubnub). Do not ask the user to check MCP if those tools are already listed. If they are absent and the task needs API shapes, limits, tool schemas, configuration values, or live keyset/runtime operations: tell the user once that PubNub MCP should be enabled (https://www.pubnub.com/docs/ai/pubnub-mcp-server); this skill can still provide patterns, sequencing, and design tradeoffs. Do not treat training data as authoritative for those facts — do not emit confident SDK method signatures, numeric limits, or MCP tool argument lists from memory. Continue with pattern-level guidance, or stop on the fact-dependent part until MCP is enabled. Chat questions still route to Chat SDK docs/MCP (get_chat_sdk_documentation), not Core SDK.
Shared pattern routing
S5 owner: gaming-state-sync.md — delta, sequence, snapshot (reusable beyond gaming). S1 move validation: link functions-patterns.md, keep game rules locally. S2/S3: offline-catch-up, backoff-and-jitter. shared-pattern-routing.md
When to Use This Skill
Invoke this skill when:
- Building real-time multiplayer game lobbies and room management
- Implementing game state synchronization between players
- Creating matchmaking systems with skill-based or ranked pairing
- Adding turn-based or real-time action game networking
- Managing player connections, disconnections, and reconnections mid-game
- Implementing spectator modes, leaderboards, or in-game chat
Core Workflow
- Initialize PubNub for Gaming: Configure the PubNub SDK with gaming-optimized settings and channel groups
- Create Game Rooms: Set up lobby channels, game room channels, and player presence tracking
- Implement Matchmaking: Build player queues, skill-based pairing, and room assignment logic
- Synchronize Game State: Use publish/subscribe with delta updates and conflict resolution
- Handle Player Lifecycle: Manage joins, disconnections, reconnections, and graceful exits
- Add Game Features: Integrate leaderboards, spectator mode, anti-cheat validation, and in-game chat
Reference Guide
| Reference | Purpose |
|---|---|
| gaming-setup.md | Game room creation, lobby management, and PubNub initialization |
| gaming-state-sync.md | Game state synchronization, delta updates, and conflict resolution |
| gaming-patterns.md | Matchmaking, turn-based/real-time patterns, anti-cheat, and leaderboards |
Key Implementation Requirements
Initialize PubNub for Gaming
import PubNub from 'pubnub';
const pubnub = new PubNub({
publishKey: 'pub-c-...',
subscribeKey: 'sub-c-...',
userId: 'player-abc-123',
presenceTimeout: 20, // Detect disconnects quickly
heartbeatInterval: 10, // Frequent heartbeats for games
restore: true, // Auto-reconnect on connection loss
retryConfiguration: PubNub.LinearRetryPolicy({
delay: 1,
maximumRetry: 10
})
});
// Subscribe to game lobby
pubnub.subscribe({
channels: ['game-lobby'],
withPresence: true
});
Create a Game Room
async function createGameRoom(pubnub, hostPlayerId, gameConfig) {
const roomId = `game-room-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
const roomChannel = `game.${roomId}`;
const stateChannel = `game.${roomId}.state`;
// Set room metadata via App Context
await pubnub.objects.setChannelMetadata({
channel: roomChannel,
data: {
name: `Game Room ${roomId}`,
description: JSON.stringify({
host: hostPlayerId,
maxPlayers: gameConfig.maxPlayers || 4,
gameType: gameConfig.gameType,
status: 'waiting',
createdAt: Date.now()
})
}
});
// Host subscribes to game channels
pubnub.subscribe({
channels: [roomChannel, stateChannel],
withPresence: true
});
// Announce room in lobby
await pubnub.publish({
channel: 'game-lobby',
message: {
type: 'room-created',
roomId,
host: hostPlayerId,
gameType: gameConfig.gameType,
maxPlayers: gameConfig.maxPlayers || 4
}
});
return { roomId, roomChannel, stateChannel };
}
Synchronize Game State
Follow the canonical gaming-state-sync reference for delta updates, sequence numbers, batching, snapshots, and recovery. Game-room delta: publish state-delta on <roomId>.state; wire presence join/leave to your disconnect handler.
Constraints
- Keep game state messages within PubNub's message size limit (retrieve via
how_to); use delta updates instead of full state - Use PubNub Presence with short timeouts (15-30s) to detect player disconnections quickly
- Always implement reconnection logic with state recovery for dropped players
- Validate critical game actions server-side using PubNub Functions to prevent cheating
- Use separate channels for game state, chat, and lobby to avoid message congestion
- Design for eventual consistency; PubNub guarantees message ordering per channel but not cross-channel
MCP Tools
get_sdk_documentation— pull SDK-specific publish/subscribe and signal APIs (route via intent-to-tool)manage_functions(resource=package,operation=create) — create the Before-Publish anti-cheat / state validator packagegrant_token— issue scoped grants per game roommanage_apps— verify Stream Controller for room and lobby fan-out
See Also
- pubnub-presence — room occupancy and player online/offline, dropped-connection recovery, multi-device sync
- pubnub-functions — Before Publish for anti-cheat / move validation;
require('kvstore')for authoritative state; chaining for enrich-then-broadcast - pubnub-security — Access Manager grants per room, DoS mitigation for griefer waves, encryption for sensitive payloads
- pubnub-reliability — idempotent publish so move-retries don't apply twice; dedup-on-merge on rejoin after disconnect; use
signaloverpublishfor high-frequency state via payload hygiene - pubnub-history — Message Persistence for replay / spectator catch-up
- pubnub-scale — channel sharding for matchmaking, large-event playbook for tournament finals
- pubnub-app-context — player profiles, MMR, party memberships
- pubnub-chat — in-game chat SDK and file sharing for replay clips
- pubnub-observability — logging correlation, usage metrics, incident runbook
- pubnub-choose-docs-path — for routing other PubNub questions
Output Format
When providing implementations:
- Include PubNub SDK initialization with gaming-optimized configuration
- Show game room creation and player join/leave lifecycle
- Include state synchronization with delta updates and conflict handling
- Add presence event handling for disconnect/reconnect scenarios
- Note anti-cheat considerations and server-side validation where applicable