Skip to content

v0.0.3

Choose a tag to compare

@mococa mococa released this 29 Dec 20:56
· 312 commits to main since this release

Release Notes: v0.0.3

🎉 RPC System Release

We're excited to announce v0.0.3 which introduces a complete RPC (Remote Procedure Call) system for bidirectional one-off events in your multiplayer games!


🚀 What's New

RPC System

A new protocol primitive alongside Intents and Snapshots:

  • Intents (Client → Server) - Player inputs
  • Snapshots (Server → Client) - State synchronization
  • RPCs (Bidirectional) - One-off events and commands ✨ NEW!

📦 Features

Type-Safe RPC Definitions

Define RPCs with automatic type inference:

import { defineRpc, BinaryCodec } from 'murow/protocol';

const MatchCountdown = defineRpc({
  method: 'matchCountdown',
  schema: {
    secondsRemaining: BinaryCodec.u8,
  }
});

type MatchCountdown = typeof MatchCountdown._type;
// → { secondsRemaining: number }

Bidirectional Communication

Server → Client

// Send to specific client
server.sendRpc(peerId, MatchCountdown, { secondsRemaining: 10 });

// Broadcast to all clients
server.sendRpcBroadcast(MatchCountdown, { secondsRemaining: 3 });

Client → Server

const BuyItem = defineRpc({
  method: 'buyItem',
  schema: { itemId: BinaryCodec.string(32) }
});

// Send to server
client.sendRpc(BuyItem, { itemId: 'long_sword' });

Type-Safe Handlers

// Client: Receive from server
client.onRpc(MatchCountdown, (rpc) => {
  showCountdownUI(rpc.secondsRemaining); // ✅ Type-safe!
});

// Server: Receive from client
server.onRpc(BuyItem, (peerId, rpc) => {
  handlePurchase(peerId, rpc.itemId); // ✅ Type-safe!
});

🎯 Use Cases

✅ Perfect for:

  • Match lifecycle events (countdown, pause, end)
  • Meta-game notifications (achievements, level up)
  • Chat messages (transient communication)
  • UI feedback (purchase confirmations, errors)
  • System announcements (server restart warnings)

❌ Not for:

  • Game state synchronization → Use Snapshots
  • Player inputs → Use Intents
  • Anything late joiners need to know → Use Snapshots

🏗️ Architecture

  • Binary protocol with efficient encoding (method IDs as u16)
  • Fully integrated with existing network layer:
    • Rate limiting
    • Backpressure handling
    • Buffer pooling
    • Message priority
  • Optional - Backward compatible (doesn't break existing code)
  • Uses MessageType.CUSTOM (0xff) for protocol discrimination

📚 Documentation

  • Protocol README: Full RPC guide with examples
  • Network README: Quick integration guide
  • 21 tests: Comprehensive test coverage
  • TypeScript JSDoc: Complete API documentation

🔧 Setup

import { RpcRegistry, defineRpc } from 'murow/protocol';

// 1. Define your RPCs
const MatchCountdown = defineRpc({
  method: 'matchCountdown',
  schema: { secondsRemaining: BinaryCodec.u8 }
});

// 2. Create registry
const rpcs = new RpcRegistry();
rpcs.register(MatchCountdown);

// 3. Add to client/server
const client = new ClientNetwork({
  transport,
  intentRegistry,
  snapshotRegistry,
  rpcRegistry: rpcs, // ← New optional parameter
});

const server = new ServerNetwork({
  transport,
  intentRegistry,
  createPeerSnapshotRegistry,
  rpcRegistry: rpcs, // ← New optional parameter
});

🎮 Example: Match Countdown

// shared.ts - Define RPC
export const MatchCountdown = defineRpc({
  method: 'matchCountdown',
  schema: {
    secondsRemaining: BinaryCodec.u8,
  }
});

// server.ts - Broadcast countdown
let countdown = 10;
const interval = setInterval(() => {
  server.sendRpcBroadcast(MatchCountdown, {
    secondsRemaining: countdown
  });

  countdown--;

  if (countdown === 0) {
    clearInterval(interval);
    startMatch();
  }
}, 1000);

// client.ts - Show countdown UI
client.onRpc(MatchCountdown, (rpc) => {
  document.getElementById('countdown').textContent =
    `Match starting in ${rpc.secondsRemaining}s`;
});

📊 Performance

  • Binary encoding for minimal bandwidth
  • Zero-allocation buffer pooling (when enabled)
  • Delta detection prevents redundant sends
  • Rate limiting protects against spam
  • Backpressure handling for network congestion

🧪 Testing

All tests pass (21 new RPC tests):

npm test
# ✓ 21 pass, 0 fail

🔄 Migration

No breaking changes! The RPC system is fully optional:

  • If you don't use RPCs, nothing changes
  • Add rpcRegistry to config when you're ready
  • Existing intents and snapshots work exactly the same

📖 Learn More


🙏 Thank You

This release brings RPCs to complete the three core networking primitives needed for multiplayer games. We hope it makes your game development easier!

Intents + Snapshots + RPCs = Complete Networking Toolkit 🎮


Installation

npm install murow@0.0.3

or

bun add murow@0.0.3