The Context: "The 03:00 AM Compound Breach"
It was 03:12 AM on monthly wipe day. Our 8-player squad was asleep across multiple time zones while defending a high-value industrial compound on a 500-pop competitive vanilla Rust server.
Suddenly, an opposing clan detonated 12 timed explosive charges against our outer perimeter wall.
Standard mobile companion push notifications failed to wake the team—push notifications get batched or muted by OS battery optimizations. More crucially, once you are awake, launching a heavy 3D game client on a desktop PC takes 90 to 120 seconds. In modern competitive survival games, a 90-second delay means your loot room is already gone.
To survive, we engineered RustMinus: an ultra-low-latency, headless tactical command system that connects directly to the game server's WebSocket protocol. It tracks live player coordinates, orchestrates compound electrical automation (auto-turrets, SAM sites, smart doors), bridges tactical chats into Matrix end-to-end encrypted (E2EE) rooms, and executes autonomous high-priority voice broadcasts directly into our team's Matrix voice channels via ephemeral WebRTC bots.
The Problem Statement
Interfacing with proprietary game server telemetry and out-of-band communication systems under strict real-time and security constraints:
- Protocol: Facepunch Companion Protocol (Protocol Buffers v2 over encrypted WebSockets).
- Rate-Limiting: Facepunch Companion API enforces strict rate limits (~25 requests/second) per player token; bursting triggers IP throttling.
- Latency Invariant: Critical smart alarm triggers must bridge into encrypted group voice calls in under 1.5 seconds.
- Zero Idle Overhead: Voice injection bots must connect, synthesize text-to-speech, inject audio via WebRTC, and disconnect cleanly with zero lingering idle zombie processes.
- Zero Plaintext Secrets: Operational configurations, server tokens, and Matrix encryption keys must remain decoupled from code with zero persistent disk exposure.
Visual Architecture
The Core Logic / Process
1. Reverse-Engineering Protobuf v2 & Upgrading Async/Await
The official Rust+ companion protocol relies on Google Protocol Buffers compiled into a proprietary schema. The community library (@liamcottle/rustplus.js) was historically built on legacy Node.js callbacks with outdated protobuf message definitions.
During project bootstrapping, RustMinus executes an automated postinstall patch (scripts/patch-rustplus.js):
- Updates the
.protodescriptor definitions to capture modern Facepunch telemetry (including real-time Cargo Ship heading rotation angles, Patrol Helicopter flight corridors, CH47 Chinook supply drops, and vending machine inventory states). - Promisifies internal WebSocket emitters into modern native
async/awaitconstructs, preventing unhandled event loop rejections during server restarts.
2. Ephemeral WebRTC Voice Injection
Permanent voice bots idling in VoIP rooms consume significant server RAM, trigger room echo loops, and leak user presence. RustMinus introduces the Ephemeral WebRTC Audio Injector:
- Trigger: An in-game smart alarm trips (e.g. compound perimeter laser broken or explosive charge detected).
- Synthesis: The alert payload is passed to Edge TTS (or local neural TTS), generating high-speed 150% pitch-optimized PCM audio in under 300ms.
- Audio Normalization: FFmpeg normalizes the synthesized waveform (
loudnormfilter) to guarantee broadcast clarity over loud in-game combat noise. - Injection: A headless Chromium instance boots using
puppeteer-core, joins the Matrix WebRTC voice call (voice.trylocalhost.com), feeds the virtual audio stream into the WebRTC peer connection, and immediately exits. The entire lifecycle from trigger to disconnect takes less than 3.5 seconds.
// Ephemeral voice dispatch snippet
async function dispatchVoiceAlert(textAlert) {
const audioPath = await synthesizeEdgeTTS(textAlert, {
rate: "+20%",
pitch: "+5Hz",
});
const browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium",
args: [
"--use-fake-ui-for-media-stream",
"--use-fake-device-for-media-stream",
`--use-file-for-fake-audio-capture=${audioPath}`,
"--headless=new",
],
});
const page = await browser.newPage();
await page.goto(`https://voice.trylocalhost.com/#/room/${ROOM_ID}`);
await page.waitForSelector(".joined-call-indicator", { timeout: 5000 });
await page.waitForTimeout(4000); // Allow audio playback to complete
await browser.close();
}
3. Matrix E2EE Megolm Cryptographic Relay
Public messaging bots on Discord or Telegram expose gamer IP addresses, geolocation telemetry, and base raid vulnerability windows to third-party scraping and platform admins.
RustMinus integrates directly with matrix-js-sdk using the Megolm cryptographic ratchet:
- Messages sent to
#raid-alarmsand#team-chatare encrypted end-to-end on the server before transmitting over TLS. - In-game chat is mirrored bidirectionally: typing
!turrets oninside an encrypted Matrix room securely toggles compound auto-turrets via the server's local WebSocket connection. - Cryptographic session state is persisted in an encrypted local
SessionStorewith zero cloud leakage.
4. High-Performance Canvas Map Telemetry & Vending Intelligence
Rather than overloading the client DOM with hundreds of dynamic SVG nodes:
- The tactical web interface renders a 4096×4096 procedural island canvas.
- Transforms world coordinates $(X, Y)$ into tactical grid sectors (e.g.
[N13]). - Visualizes real-time moving markers: Cargo Ship heading angles, Patrol Helicopter searchlights, Chinook drop locations, team member vitals (Alive 🟢, Sleeping 💤, Dead 💀).
- Features a built-in item dictionary indexing island vending machines, allowing players to instantly search for bargains on sulfur, rockets, blueprints, or medical supplies.
The "Baigan" Take (Expert Insights)
Baigan ki automation is when someone writes a script that spams setEntityValue 50 times a second to flash base lights, only to get their Steam account blacklisted from the companion gateway.
Facepunch companion proxies enforce strict token bucket limits. If you attempt to toggle 16 smart switches simultaneously using 16 separate WebSocket requests, the proxy will terminate your socket with error code 429 Too Many Requests.
You must implement Coalesced Command Batching:
- Queue state toggle intents into an in-memory batch window (50ms).
- Deduplicate conflicting commands (
ONfollowed immediately byOFF). - Transmit batched requests with randomized 25ms inter-message spacing.
- Always implement local optimistic state reflection so the web UI feels instantaneous even while the physical game server acknowledges the toggle asynchronously.
Performance Checklist
- Patch the protobuf codec to handle modern Facepunch message schemas with native async/await.
- Configure ephemeral WebRTC voice bots with strict process teardown to prevent ghost zombie instances.
- Enforce Megolm end-to-end encryption on all out-of-band communication channels.
- Batch compound switch mutations to strictly comply with Facepunch companion rate limits.
- Run headless daemons under systemd with automated restarts and Caddy reverse proxies with TLS.