Download Game! Currently 78 players and visitors. Last logged in:PereTohvuFosforosKandahar

Blitzer's Blog >> 72057

Back to blogs index
Posted: 05 Sep 2026 14:03 [ permalink ]
### Step 2: The DMZ Relay & Archive (Arena C)

You don't need a heavy database for this. A simple Node.js WebSocket server
that maintains an **Append-Only Log (Event Sourcing)** on disk is perfect.
Because files in an LPC MUD are text, you can literally just log the JSON
payloads.

```javascript
/ dmz_relay.js (Run this on a VPS or via Cloudflare Tunnels)
const { WebSocketServer } = require('ws');
const fs = require('fs');

const wss = new WebSocketServer({ port: 8080 });
const archivePath = './mesh_archive.jsonl';

/ Load state into memory
let vfsState = {}; 
if (fs.existsSync(archivePath)) {
    const lines = fs.readFileSync(archivePath, 'utf8').split('
');
    lines.forEach(line => {
        if (!line) return;
        let event = JSON.parse(line);
        if (event.type === 'VFS_WRITE') vfsState[event.path] = event.data;
        if (event.type === 'VFS_DELETE') delete vfsState[event.path];
    });
}

wss.on('connection', (ws) => {
    // On connect, immediately dump the current VFS state to the new node
    for (let path in vfsState) {
        ws.send(JSON.stringify({ type: 'VFS_WRITE', path, data: vfsState[path]
}));
    }

    ws.on('message', (message) => {
        let event = JSON.parse(message);
        
        // Idempotency check: Don't broadcast if the file hasn't actually
changed
        if (event.type === 'VFS_WRITE' && vfsState[event.path] === event.data)
return;

        // Update RAM and Append to Disk Log
        if (event.type === 'VFS_WRITE') vfsState[event.path] = event.data;
        if (event.type === 'VFS_DELETE') delete vfsState[event.path];
        fs.appendFileSync(archivePath, message + '
');

        // Broadcast to all OTHER nodes
        wss.clients.forEach(client => {
            if (client !== ws && client.readyState === 1) client.send(message);
        });
    });
});

```