Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(multiplayer): let an operator announce into every live walk world
nirholas8d487793ac24
diff --git a/multiplayer/src/index.js b/multiplayer/src/index.jsindex 16e90535f..d924d70a5 100644--- a/multiplayer/src/index.js+++ b/multiplayer/src/index.js@@ -15,7 +15,7 @@import http from 'node:http';import express from 'express';-import { Server } from '@colyseus/core';+import { Server, matchMaker } from '@colyseus/core';import { WebSocketTransport } from '@colyseus/ws-transport';import { monitor } from '@colyseus/monitor';@@ -30,7 +30,8 @@ import { blockStore } from './block-store.js';import { worldPersistence } from './persistence.js';import { flushAllPlayers } from './playerStore.js';import { socialHub } from './social-hub.js';-import { verifyNotifySignature, verifyStageSignature } from './presence-token.js';+import { verifyNotifySignature, verifyStageSignature, verifyAnnounceSignature } from './presence-token.js';+import { liveWalkRooms } from './walk-registry.js';const PORT = Number(process.env.PORT || 2567);const HOST = process.env.HOST || '0.0.0.0';@@ -131,6 +132,78 @@ app.post('/internal/stage', express.json({ limit: '16kb' }), (req, res) => {}});+// Live-event announcement webhook. An operator (scripts/announce-play.mjs in+// the main repo, holding the same shared secret) broadcasts a message to every+// player in every live walk_world room on this instance — optionally narrowed+// to one coin's world. Delivery rides the existing 'notice' channel, which every+// deployed client already renders as a toast (and newer clients as a banner+// when a title is present), so announcements need no client version to land.+// HMAC-signed and timestamp-bound like the other internal webhooks; an unsigned+// or stale request is rejected before it reaches a room.+app.post('/internal/announce', express.json({ limit: '16kb' }), (req, res) => {+ const sig = req.headers['x-announce-signature'];+ const ts = req.headers['x-announce-timestamp'];+ const { text, title, detail, coin, durationMs } = req.body || {};+ if (typeof text !== 'string' || !text.trim()) {+ return res.status(400).json({ error: 'bad_request' });+ }+ if (!verifyAnnounceSignature(req.body || {}, ts, sig)) {+ return res.status(401).json({ error: 'bad_signature' });+ }+ const payload = {+ kind: 'event',+ text: text.trim().slice(0, 300),+ ...(typeof title === 'string' && title.trim() ? { title: title.trim().slice(0, 80) } : {}),+ ...(typeof detail === 'string' && detail.trim() ? { detail: detail.trim().slice(0, 200) } : {}),+ ...(Number(durationMs) > 0 ? { durationMs: Math.min(120_000, Number(durationMs)) } : {}),+ };+ const rooms = liveWalkRooms(typeof coin === 'string' ? coin.trim() : '');+ let players = 0;+ for (const room of rooms) {+ try {+ room.broadcast('notice', payload);+ players += room.clients?.length || 0;+ } catch (err) {+ console.warn('[multiplayer] announce broadcast failed:', err?.message || err);+ }+ }+ console.log(`[multiplayer] event announce → ${rooms.length} room(s), ${players} player(s): ${payload.text}`);+ res.json({ ok: true, rooms: rooms.length, players });+});++// Public live population. The only aggregate this process publishes without a+// signature, and deliberately so: it is a count, never an identity. No session+// ids, no names, no wallets, no positions leave here.+//+// It reads the matchmaker's room listing (driver-backed), NOT the in-process+// walk-registry, so under horizontal scaling (REDIS_URI set) the number covers+// every instance rather than only the one that served the request. `?coin=<mint>`+// narrows to one community's worlds, which is what the /event landing page asks+// for; without it the total spans every live world.+//+// The three.ws API proxies this server-side (api/play/population.js), so no CORS+// header is emitted: a browser never calls it directly.+app.get('/population', async (req, res) => {+ const coin = typeof req.query.coin === 'string' ? req.query.coin.trim().slice(0, 128) : '';+ try {+ const listings = await matchMaker.query({ name: 'walk_world' });+ let rooms = 0;+ let players = 0;+ for (const room of listings || []) {+ if (coin && room?.coin !== coin) continue;+ rooms += 1;+ players += Number(room?.clients) || 0;+ }+ // 5s of edge/CDN caching: the number moves on a human timescale and this+ // runs on the same process that serves gameplay traffic.+ res.set('cache-control', 'public, max-age=5');+ res.json({ ok: true, coin: coin || null, rooms, players });+ } catch (err) {+ console.warn('[multiplayer] /population failed:', err?.message || err);+ res.status(503).json({ ok: false, error: 'unavailable' });+ }+});+// The IRL world (irl_world) is a presence + reaction room only — it is NOT a pin// transport. Placed agents are private by location and reach a viewer solely via// the per-viewer /api/irl/pins proximity read when they are physically near one,diff --git a/multiplayer/src/walk-registry.js b/multiplayer/src/walk-registry.jsnew file mode 100644index 000000000..6f67996c4--- /dev/null+++ b/multiplayer/src/walk-registry.js@@ -0,0 +1,30 @@+// Walk-room registry — the in-process lookup that lets the internal+// /internal/announce webhook (called by an operator during a live event, signed+// with the shared secret) reach every live walk_world room on this instance and+// broadcast an announcement to the players in it.+//+// Mirrors stage-registry.js, with one difference: walk_world rooms are matched+// with filterBy(['coin','tier']) and can also shard past maxClients, so more+// than one live room can exist per coin. A Set of live rooms (filtered by coin+// at broadcast time) is therefore the right shape, not a Map keyed by coin.+// Under horizontal scaling (Redis driver) an announce only reaches the rooms+// hosted on the instance that received the webhook; the caller fans out to+// every instance or accepts partial delivery — nothing here breaks.++const _rooms = new Set(); // live WalkRoom instances on this process++export function registerWalkRoom(room) {+ if (room) _rooms.add(room);+}++export function unregisterWalkRoom(room) {+ _rooms.delete(room);+}++// Live walk rooms, optionally narrowed to one coin's world(s). An empty coin+// matches every room, which is what a platform-wide event announcement wants.+export function liveWalkRooms(coin = '') {+ const rooms = [..._rooms];+ if (!coin) return rooms;+ return rooms.filter((r) => r?.state?.coin === coin);+}