VRChat server-client companion suite
README.md

vrcd Web #

Browser front-end for vrcd. Links to vrcd-server over the same JSON-L API the SDL client uses, and serves the roster and event feed as HTML over ddhttpd (libmicrohttpd). It never talks to VRChat directly.

Usage #

vrcd_web [options]
  -l, --listen      Address to serve HTTP on (default: 127.0.0.1:8080)
  -s, --server      vrcd-server address as host:port (default: 127.0.0.1:9700)
      --secret      Shared secret for vrcd-server auth
      --web-secret  Shared secret browsers must present to sign in
      --web-root    Directory holding the front-end files
      --image-cache vrcd-server's image cache directory, when it shares this host
      --no-image-cache  Never read that cache, even on one host
  -v, --verbose     Enable verbose logging
      --debug       Enable the debugging tools (also VRCD_WEB_DEBUG=1)
      --version     Show version and exit

There is no config file. Everything is on the command line, since the process holds no state of its own: sessions live in memory and the roster comes from vrcd-server. --debug is the one thing that also reads the environment (VRCD_WEB_DEBUG), because it is the one thing you turn on for a working session rather than for a deployment; the flag wins over the variable.

--secret authenticates this process to vrcd-server. --web-secret authenticates browsers to this process. They are unrelated and should not be the same value.

./web/vrcd_web --listen 0.0.0.0:8080 --server 127.0.0.1:9700 \
    --secret <server secret> --web-secret <what you type in the browser>

Note: the link to vrcd-server is plain TCP. TLS is not wired up on this side yet, so keep it on loopback or inside a tunnel.

Document root #

The front-end lives in web/public/ as plain files, not string literals in the binary, so editing a stylesheet is an edit plus a refresh with no rebuild and no restart. The trade is that the directory has to travel with the binary.

The root is --web-root when given (a wrong path is a hard error, not a silent fallback), otherwise the first of these that holds an index.html:

  1. public/ beside the binary (how a package installs)
  2. ../public relative to the binary
  3. ./public under the working directory
  4. ./web/public (how the repository is laid out)

When none exist, the candidates are logged and the process exits rather than serving a broken page.

Auth #

A shared secret exchanged for a session cookie. It is a gate, not an identity system: one secret, sessions in memory, all of them lost on restart.

  • POST /login compares the submitted secret in constant time and sets vrcd_session (HttpOnly, SameSite=Strict, 12 hour lifetime).
  • WebSockets get a second mechanism. ddhttpd upgrades the connection before the handler runs and WebSocketConnection exposes no request headers, so the cookie cannot be read there. The page trades it at /api/wsticket for a single-use ticket with a 30 second lifetime, and puts that in the socket path. A ticket that leaks into a log or a referrer is worthless seconds later, which the secret itself would not be.

Without --web-secret every route is open and the server says so at startup. There is no logout route yet; clearing the cookie is the workaround.

Installing as an app #

The front-end is a PWA, so a browser will offer to install it and run it in its own window with no address bar -- which is most of the point on a phone, and what makes it reasonable to open from a headset browser.

What that takes is manifest.webmanifest (name, #16161c theme, a 512px icon plus a maskable variant for Android launchers, display: standalone) and sw.js. Both are served from the root rather than /static/: a service worker's scope is the directory it came from, so /static/sw.js could only control /static/, and the manifest is fetched without cookies, which puts it outside a session check regardless. Neither carries state and the install prompt has to work before signing in, so both are open. iOS ignores the manifest entirely and reads the apple-mobile-web-app-* tags in the two documents instead.

The worker is there for installability, not offline use: every screen is a view of state that arrives over the WebSocket, and with no link to vrcd-server there is nothing truthful to show. It caches the shell (app.css, app.js, the icon, the manifest, and each page as it is visited) and reaches for that cache only after the network has already failed, so an unreachable server opens the page instead of a browser error. Network-first also keeps the edit-and-refresh workflow intact -- a cache-first worker would serve the previous app.css for one more load after every edit. /api/, /ws/, /login and the worker itself are never intercepted: live state, a 202 from the image proxy, and the sign-in redirect are all things a cache would get wrong. Bump CACHE in sw.js when the precache list changes; activation deletes every other cache.

Registration needs a secure origin. Browsers only allow service workers on HTTPS or localhost, and vrcd-web serves plain HTTP, so a phone pointed at http://192.168.x.x:8080 gets the page but no install prompt (the failure is logged to the console and nothing else breaks). Put it behind a TLS reverse proxy, or reach it over something that terminates TLS for you, and the prompt appears.

Routes #

Method Path Auth Purpose
GET / cookie The shell document (index.html)
GET /login open Sign-in page
POST /login -- Exchange the secret for a session cookie
GET /static/:name open One file from the web root
GET /manifest.webmanifest open Web app manifest
GET /sw.js open Service worker
GET /api/state cookie Current snapshot, same JSON as the socket sends
GET /api/wsticket cookie Single-use WebSocket ticket
POST /api/join cookie {"location":"wrld_...:1234~..."}, requests a self-invite
POST /api/notification cookie {"notification_id":"not_...","action":"accept"|"hide"}
POST /api/status cookie {"status":"busy","status_description":"..."}, sets your own status
GET /api/content/:section cookie One section's entries, and the fetch that fills them. ?refresh=1 re-lists, ?more=1 asks for the next page
POST /api/content cookie {"action":"...","id":"...","slot":"drone"} -- see below
POST /api/upload cookie {"tag":"gallery"|"icon"|"sticker"|"emoji"|"print","data_base64":"...","note":"..."}
POST /api/moderation cookie {"action":"mute"|"unmute"|"block"|"unblock"|"unfriend"|"friend_request"|"cancel_friend_request","user_id":"usr_..."}, or {"action":"refresh"} to re-list
GET /api/user/:user_id cookie One person's full profile, and the fetch that fills it
GET /api/badge?url= cookie One proxied badge image, by the URL a profile carries
GET /api/image/:file_id cookie One proxied VRChat image, ?v= version and ?size= edge
POST /api/debug cookie {"action":"friend_request"} puts a fake notification in the inbox; clear takes them out. 403 without --debug
POST /api/auth cookie Answers a delegated VRChat sign-in prompt
WS /ws/:ticket ticket State snapshots and feed events

/static/ is deliberately open: the assets carry no state, and the login page needs its stylesheet before there is a session to check. Names are restricted to a plain file name (no separators, no traversal, nothing hidden, 64 chars max) and only known extensions are served.

/api/auth takes one of three bodies:

{"action": "credentials", "username": "...", "password": "..."}
{"action": "two_factor",  "code": "123456"}
{"action": "cancel"}

Unlike the two above it is not fire and forget: there is no result message for a sign-in, so the reply is all the page hears. 200 means the answer went down the link, 503 means there is no link to put it on, 400 means the action was not one of the three or the fields it needs were empty (a blank password is refused here rather than spending one of VRChat's login attempts on it).

/api/status carries either field or both, and needs at least one. status is one of active, join me, ask me, busy -- anything else is a 400 here rather than a round trip. An absent status_description leaves the message as it is and an empty one clears it, which is why the two are not the same request: by the time it reaches vrcd-server, an absent field is a field left out of the set_status. The message is stripped of surrounding space and cut to 32 code points, counted as characters rather than bytes because that is what VRChat counts and because cutting UTF-8 by the byte would leave half a character behind.

/api/content takes one action per request:

Action ID Effect
equip inv_... Puts the item in slot (drone, portal, warp)
unequip -- Empties slot; VRChat addresses the slot, not the item
consume inv_... Uses the item up
delete_file file_... Deletes a gallery image, icon, sticker or emoji
delete_print prnt_... Deletes a print
set_icon file_... Sets the profile icon, or clears it when the ID is empty

/api/moderation takes one action per request. refresh re-lists the mutes and blocks and names nobody; the rest name a user_id, which is checked for shape here because it lands in a path vrcd-server builds. Only the characters are checked, not the usr_ prefix: VRChat accounts old enough predate it and can still be muted. unfriend, friend_request and cancel_friend_request are not player moderations and take different calls on the other side, but they come back through the same result slot: all are "something was done to a person", and the page offers one at a time.

Browser-to-server actions go over plain HTTP rather than up the socket, which keeps the WebSocket unidirectional. They are fire and forget: the outcome comes back from vrcd-server as a join_instance_result, a notification_action_result, a set_status_result, a moderate_result, an unfriend_result, a friend_request_result or one of the content results, and reaches the page in the next state broadcast, which is also what drops an answered notification from the inbox. An action other than the ones listed is refused here rather than travelling down to vrcd-server to be refused there.

Fire and forget is not only about the page: ddhttpd runs handlers on its poll thread, so a handler that waited for the link to answer would hold every other request behind it, which is the same reason the image proxy replies 202 rather than blocking.

Request bodies are capped at 16 MB, which is VRChat's 10 MB picture plus base64 expansion and the JSON around it. Past that the reply is a 413 and nothing is buffered.

Architecture #

Threading model #

+---------------------+     +----------------------+
| ServerLink thread   |     | libmicrohttpd thread |
| - TCP to vrcd-server|     | - HTTP handlers      |
| - reconnect/backoff |     +----------------------+
+----------+----------+
           | callbacks
           v
      +---------+     +--------------------------+
      |   Hub   +---->| one thread per browser   |
      +---------+     | - parks on a condition   |
                      | - only ever sends        |
                      +--------------------------+
  • ServerLink thread -- owns the socket to vrcd-server. Connects, authenticates, answers pings, parses the handful of message types the page renders, and reconnects with a 2 second backoff doubling to 60 seconds. Its state is behind a mutex so HTTP handlers can read it from any thread.
  • libmicrohttpd threads -- run the HTTP handlers. They read link state and reply; they never block on the network thread.
  • Browser threads -- one per WebSocket, spawned by ddhttpd. Each parks on a condition variable until something moves, then writes.

The one-way rule for browser threads is deliberate. ddhttpd's send_frame writes the frame header and payload as two separate socket writes with no lock, so two threads sending on one connection would interleave and corrupt the stream. Keeping every write on the connection's own thread sidesteps that. If the page ever needs to send messages up the socket, that needs a reader thread and a per-connection send mutex.

Broadcast model #

Two channels share one wakeup:

  • State is a snapshot, so only the latest one matters. The hub keeps the encoded payload and a generation counter; each connection compares its last-seen generation. A browser that joins late gets the current snapshot rather than a replay, so it is correct immediately.
  • Feed is an append-only log with a 500 entry ring. Each connection sends the slice it has not seen. A new epoch, a first look, or having fallen off the back of the ring all resolve the same way: send what we have as a replacement (reset: true) rather than trying to patch the browser's copy. So a browser gets a full replacement instead of a gap.

The timed wait doubles as a heartbeat: on a 30 second timeout the thread sends a ping, which is how a browser that vanished without a close frame is noticed.

Snapshots are broadcast on every change and are small enough that diffing them server-side would cost more than it saves.

Inbox #

The inbox cannot be rebuilt from the event log. The VRChat WebSocket only reports changes, so a friend request that arrived while this process was down has no event to replay, and the feed seed only reaches back one page anyway. So the link asks vrcd-server for get_notifications on connect (protocol v4; on an older server the tab says so and stays empty) and then keeps that list current from the live events. The backlog deliberately does not feed the inbox: replaying old events over the snapshot would resurrect notifications answered long ago.

Order is oldest first and the list is never re-sorted. The accept and dismiss buttons live in the rows, so a list that reflowed when something arrived would slide a button under a thumb already on its way down to it, and on a friend request the button that moves under it is an accept. New arrivals append.

A successful action drops the row immediately rather than waiting for VRChat's matching hide-notification or response-notification event, which arrives whenever it arrives.

One gap: a live notification event for a friend request carries no sender name, and the sender is by definition not in the roster, so the row shows the user ID until the next reconnect refetches the list. The server resolves names for the fetched list but the link cannot do a REST lookup of its own.

Stuff #

The STUFF tab is six sections over one mechanism:

Section Source Actions
Gallery get_files tag gallery Upload, delete
Icons get_files tag icon Upload, delete, set or clear the profile icon
Stickers get_files tag sticker, plus get_inventory types=sticker not_flags=ugc Upload, delete
Emoji get_files tag emoji, plus get_inventory types=emoji not_flags=ugc Upload, delete
Prints get_prints Upload with a caption, delete
Items get_inventory Equip, unequip, consume

Items are props, bundles, drone and portal skins and warp effects. Emoji and stickers are not among them: vrcd-server filters them out of get_inventory because they have sections of their own above.

Stickers and emoji are the two sections drawn as two groups, since they are the two an account can both upload and be given. The second group is what VRChat handed out: inventory entries rather than files, so they carry no delete and are drawn as items wherever one is opened. They ride in the same section rather than a chip of their own, and each of the two listings keeps its own loading flag and error so neither answer holds the other's list back. The headings appear only once there is a second group for the first to be told apart from.

The entries do not ride in the state snapshot. A few hundred of them would be re-encoded and fanned out to every browser on every friend movement, and the tab is usually closed. So the snapshot carries a small block per section -- revision, loading, count, more, error -- and the entries come from GET /api/content/:section. A revision that moves is the page's cue to come back for a new copy; a bump that lands while a fetch is in flight is remembered, since the copy already on its way is the one before the change.

Nothing is fetched until someone opens a section: each listing costs vrcd-server a VRChat call, and most sessions never look at most of them. After that a section refreshes itself, because several things change one and only some of them are buttons here:

  • an action from this page -- the result says which section it touched, except a delete, which does not name one, so every loaded files section re-lists,
  • an upload, which refreshes the section it went to,
  • a content-refresh event naming that section, which is how VRChat reports a change made in-game or on another device,
  • a reconnect, but only for sections already fetched -- nothing that happened while the link was down replays as an event.

A failed refresh keeps the list that is on screen rather than blanking it: it is still the last thing VRChat said, and an empty section reads as "you own nothing" rather than "that did not work".

Only the files sections page, at 100 entries a request (vrcd-server's own cap); prints and the inventory arrive whole. A full page means there may be another, which is what puts LOAD MORE under the grid, and those pages append.

Deletes and consumes are two taps, and the second is not where the first landed: Cancel takes that spot, because none of them can be undone. Equip and unequip are both offered whenever an item is equippable, rather than guessing which one applies: VRChat reports which slot an item belongs to, not whether it is currently sitting in it, and both are one reversible tap. An item whose slot comes back empty falls back to its type (droneskin -> drone, portalskin -> portal, warpeffect -> warp), which are the only three slots vrcd-server accepts.

Uploads are a file picker, read as base64 in the browser and posted whole. PNG and the 10 MB ceiling are checked here so a picture that was never going to be accepted does not travel twice; everything else -- dimensions, and the square requirement on stickers and emoji -- is vrcd-server's call, since it is the side that knows VRChat's rules and has to answer for them. There is no crop step yet, so a non-square sticker comes back refused rather than trimmed. Animated emoji upload as a still: the sprite-sheet fields exist in the API but this page has nothing to describe them with.

Tools #

The TOOLS tab is friend management: one flat list of everyone on the friends list, and VRChat's two player moderation lists, plus the groups you are in.

Section Source Actions
Friends The roster already in the snapshot Mute, block, unfriend, from the detail pane
Muted get_moderations Unmute, from the row
Blocked get_moderations Unblock, from the row
Groups get_groups, kept current by vrcd-server Represent, announcements, visibility, leave, from the detail pane

The friends section is the same roster the ONLINE tab draws, flattened and sorted by name: grouped by instance is the right shape for seeing where everybody is and the wrong one for looking somebody up.

Unlike the STUFF sections, the mute and block lists ride in the state snapshot. An entry is a name and an ID, and the roster travelling in the same message is many times their size, so fetching them separately would buy nothing and cost a round trip per change. They are asked for once per link connection rather than when the tab is opened, because a friend's pane draws mute and block as toggles and a toggle that does not know which way it is pointing is worse than one call per connection. Until they land, the pane says so instead of guessing.

VRChat sends no WebSocket events for player moderations at all, so nothing keeps them current: a mute made in-game shows up when REFRESH is pressed, or on the next reconnect. A moderation made from here does not need either, since vrcd-server re-broadcasts both lists after its own successful call, and that reaches every browser rather than only the one that pressed the button.

Mute is one tap either way -- it is invisible from the other side and undone by pressing the same button again. Block and unfriend arm first, and the confirm is not where the first tap landed: Cancel takes that spot, because both are visible to the other person and neither is undone by a second press. Unblock and unmute are single taps for the same reason mute is.

A moderation is not limited to friends and outlives the friendship it started in, so a row in either list may name somebody who is not in the roster. Those rows carry the display name VRChat gave the moderation and open a thinner pane: a name, an ID, and the moderation buttons, with no unfriend among them. The rows in these two lists hold their own undo button rather than sending it to the detail pane -- a list of blocked people is read in order to unblock somebody -- which is why the row is a container with the name as a button inside it.

The same mute, block and unfriend buttons appear at the foot of a friend's pane wherever that pane is opened from, not only under TOOLS: it is the same pane either way, and muting somebody is usually decided while looking at where they are. They sit last, below the self-invite and the copy button, so the two worth a mis-tap are as far down as the pane goes.

Protocol v3 is the floor. On an older vrcd-server the lists say so and the buttons are replaced by the same line.

Debugging tools #

Off unless --debug or VRCD_WEB_DEBUG=1. With them on, a DEBUG chip appears in the TOOLS tab with a button per fake notification, and pressing one puts a row in the inbox.

The inbox is the hardest screen here to develop against. A friend request arrives when somebody sends one, a group announcement when a group makes one, a queue-ready when a queue clears; none can be summoned, several cannot be un-answered, and the rows that draw most unusually are the rarest. The alternative to this is waiting on other people or editing state into the page by hand.

A fake goes in where a real one would -- into the link's inbox, out in the state snapshot, drawn by the same notifyCard -- so what appears is what a real one looks like, the badge counts it, and answering it presses the same buttons. The catalogue covers every shape that renderer can produce: a v1 type from its table, one that answers by joining, one that cannot be answered at all, a v2 type carrying its own buttons, a v2 type carrying none, one VRChat says it will clear itself (so no buttons at all), and one of a type nobody has written code for.

Senders are invented, not borrowed from the roster. Borrowing looked better -- a real face, a profile that really fetches -- but it tested the wrong thing: a request from somebody already on the roster opens the friend pane, and the reason a friend request is worth faking is that its sender is a stranger. So there are three invented people, cycled, differing in the fields the profile pane draws differently (a Visitor with nothing filled in, a Trusted User with everything, one in between). ServerLink.profile() answers for them, so the pane a fake request opens is a full one rather than a spinner and an error. Nothing is lost on the face: initials on a hue picked from the name is what the page draws for anyone without a picture anyway. Their badges carry no art -- that lives on VRChat's CDN and cannot be invented -- so the grid draws names, which is its fallback for a badge whose art does not arrive either way.

Fakes are marked. A fake row says ACCEPT and DECLINE like any other, and the danger runs both ways: accepting a real request believing it is a fake, or leaving a real one sitting because it looked like one. So the snapshot tags them ("debug": true, added on this side -- a fake is this front-end's own idea and does not belong in the shared notification shape) and the card wears a FAKE tag next to the type plus a stripe down its edge, one for reading and one for not having to.

Answering one never reaches VRChat: the ID is prefixed not_debug_, and the link recognises its own and answers on the spot, writing the outcome into the same slot a real notification_action_result lands in. That gate is on the debug flag, not on the ID alone -- a crafted not_debug_ ID sent to a normal build takes the real path and fails honestly, rather than being reported as a success for something that never happened.

None of it is reachable with the flag off: the snapshot carries no debug key (which is what the page tests to draw the chip), and POST /api/debug answers 403 rather than 404, so a page that somehow asks is told no rather than being handed the same answer a mistyped path gets.

Profiles #

The roster is a thin record: enough to draw a row and say where somebody is. The rest of a person -- bio, links, badges, trust rank, languages, the day they joined -- is fetched one at a time from GET /api/user/:user_id, not carried in the snapshot, since a few kilobytes per friend would be fanned out to every browser on every friend movement for a page opened one person at a time.

It is also the only way to see somebody who is not a friend, which is the case it exists for. A friend request arrives as a name and an ID; deciding on it means looking at the person behind them. So any notification from a user opens a pane, friend or not, and the mute and block lists open one too.

The route answers on the same terms as the image proxy, and for the same reason (ddhttpd runs handlers on its poll thread): 200 with the profile, 202 while it is on the link, 502 when VRChat or vrcd-server refused it. The page retries a 202 at 700 ms for about 20 seconds, and a failure stands for 30 seconds before the next look tries again -- most of what fails here is temporary, and this pane has no refresh button to press.

There are two caches behind it, both 5 minutes: one here, one in vrcd-server. Neither is a performance trick so much as rate-limit arithmetic -- a profile is one GET /users/{id}, and two front-ends flipping between friend requests would otherwise spend one per open. An entry that has gone stale is still served, with the refetch started underneath it, so a reopened pane never blanks. A dropped link forgets what was in flight and what failed, and keeps what was fetched.

The user ID is checked for shape here, since vrcd-server builds a path out of it. As with /api/moderation, the usr_ prefix is not required -- accounts old enough predate it -- but an ID that visibly belongs to something else (grp_ above all, which is what a v2 group notification puts in its sender field) is refused without a call.

The page merges the profile with the snapshot rather than replacing one with the other: status, custom message, platform and location come from the snapshot even when it says nothing, because those are the fields that move and a blank one is usually deliberate. Everything else comes from the profile, because the snapshot does not carry it.

Badge art is the one picture with no file behind it. Badges live on a public CDN rather than behind VRChat's authenticated files API, so GET /api/badge takes the URL a profile carries rather than a file ID. It still goes through vrcd-server, because this page makes no external requests: one that phoned out would break behind a tunnel and would tell VRChat's CDN who is looking at whom.

Which makes it the one route where the browser names what to fetch rather than which object, so the URL is pinned to HTTPS, host assets.vrchat.com and a path under /badges/, with what is left checked character by character. That rule is common/source/vrcd/badgeurl.d, compiled into both this and vrcd-server, since a rule two sides check separately is really whichever of them is looser. A badge whose art does not arrive keeps its name, which is the part that means something.

The bytes share the image cache, keyed by the URL: badge art is small, there is little of it, and a URL names one picture forever, so it belongs in the same byte budget as everything else with a picture in it. Unlike a face it is not deferred to the viewport -- a profile holds a handful, all on the one screen somebody opened deliberately, so waiting for the observer would only make them appear late.

Image proxy #

A browser cannot fetch a VRChat file: the session lives on vrcd-server. So an image travels down the JSON-L link as base64 and back out over HTTP, which is far too slow to do inside a request handler -- ddhttpd runs handlers on the same thread as its poll loop, so one blocking handler stalls every other request and every WebSocket on that thread.

GET /api/image/:file_id therefore never blocks:

  • 200 with the bytes, when they are cached.
  • 202 when the request has been put on the link. The page retries, backing off at 800 ms for about 30 seconds; vrcd-server spaces uncached downloads 250 ms apart, so a cold grid takes a while to fill in.
  • 502 when VRChat or vrcd-server refused it. That is remembered for a minute, so a wall of broken thumbnails does not hammer the link, and a transient failure still heals.

The cache is bounded by bytes (32 MB, oldest evicted first) and never invalidated: a file ID, version and size always describe the same picture, so a new upload is a new key. Replies carry a long Cache-Control, and the page keeps the object URLs it made, since the shell redraws on every snapshot.

Reading vrcd-server's cache #

When vrcd-server is on this host, most of what the page asks for is already on its disk, so a miss checks there before going down the link. The name is the one vrcd-server writes -- <image cache>/<file id>.<version>.<size> -- and two properties of that cache make reading it from outside safe: entries are written to a temporary name and renamed into place, so a half-written file is never visible, and the name is the whole identity of the content, so there is no such thing as a stale hit.

It is a shortcut around base64 and a round trip, never around vrcd-server: a miss still goes down the link, which is where the VRChat session, the rate limiter and the 250 ms spacing live. What it buys is that everything already downloaded answers 200 on the first request instead of 202 and a retry.

The directory is --image-cache when given, otherwise vrcd-server's own default (~/.local/share/vrcd/imagecache, or %APPDATA%\vrcd\imagecache), used only when it is there. A path that does not exist is a warning rather than a startup error: sharing a host is a deployment choice, and losing the shortcut costs speed, not function. --no-image-cache turns it off outright. Reads bump the file's mtime, because vrcd-server evicts by mtime and bumps it on its own hits -- without that, the entries this page uses most would look like the coldest ones it holds. That bump is best effort, since the directory may belong to another user.

?size= is 0 for the original file or one of VRChat's thumbnail edges (128, 256, 512, 1024); the grid asks for 256 and the detail pane for 512. A file ID that is not shaped like one is refused here, since it lands in a path vrcd-server builds.

VRChat sign-in #

vrcd-server holds the VRChat session; this process never talks to VRChat. When the server runs headless and needs credentials or a 2FA code it delegates the prompt to whichever front-end is connected, as an auth_request, and the first auth_response wins. The SDL client has answered these since it existed; this front-end answers the same ones, so a server can be signed in from a browser.

The prompt goes into the state snapshot as auth and the page puts a modal over everything. Answering clears it locally the moment the response is on the wire, which closes the modal on every browser: there is no "answered" message to wait for, and a wrong answer comes back as a fresh auth_request carrying the error. A server that is already waiting when this process connects replays the prompt after auth_ok, so a browser that arrives mid-prompt still sees it. A dropped link clears it too, since an answer would have nowhere to go and the server re-sends after the next auth_ok.

Cancel is an answer, not a dismissal: the server stops waiting, and a headless one gives up on the sign-in. Letting the prompt sit is not an answer at all -- after half an hour the server drops it, says so with auth_cancelled, and starts its login over, so the modal comes down here and a fresh one arrives with the next auth_request.

Note: the password crosses the browser-to-web-server hop, so this is one more reason to keep the listener on loopback or behind TLS. It is held only long enough to forward and is never logged, and with no --web-secret set anyone who can reach the port can answer these prompts.

Feed seeding #

On connect the link sends fetch_older with before_id: long.max and a limit of 200, not catch_up. Catch-up walks forward from an ID and would hand back the oldest page of a long backlog; this page wants the newest events. Entries arrive newest first and are held until older_fetched terminates them, then flipped to oldest-first so the browser can treat the feed as an ordered log regardless of how it was filled. A reconnect re-seeds from scratch: the feed is a live view, not an archive with gap tracking.

Modules #

app.d #

Entry point. Parses arguments, resolves the web root (before anything else starts, so a missing document root is a startup error), wires the link callbacks to the hub, registers every route, and parks the main thread while libmicrohttpd serves.

web/connection.d #

TCP client for the vrcd-server JSON-L API, on its own thread.

  • Interprets auth_ok, self, status, friends, event, event_older, older_fetched, join_instance_result, notifications, notification_action_result, files, prints, inventory, inventory_action_result, delete_file_result, delete_print_result, set_user_icon_result, upload_image_result, upload_print_result, image, set_status_result, moderations, moderate_result, unfriend_result, friend_request_result, auth_request, auth_cancelled, ping, error. Everything else is logged and dropped.
  • self(), status(), roster(), joinResult(), notifications(), notifyResult(), statusResult(), authPrompt(), content(section), contentResult(), moderations(), moderationResult() -- mutex-guarded snapshots for HTTP threads.
  • requestJoin(location), requestNotificationAction(id, action), requestStatus(status, description, setDescription), requestContent(section, force), requestMoreContent(section), requestInventoryAction(action, id, slot), requestContentAction(action, id), requestUpload(tag, base64, note), requestModerations(force), requestModeration(action, userId), image(fileId, version, size), submitCredentials(user, pass), submitTwoFactor(code), cancelAuth() -- safe from any thread; sends are serialized, and none of them block on a reply.
  • Change and feed callbacks fire on the network thread, outside the state lock (the callback rebuilds a snapshot, which takes that same lock). An image arriving publishes nothing: the browser is already coming back for it, and a broadcast per thumbnail would put a whole grid's worth of snapshots on every socket.
  • Types: SelfInfo, LinkStatus, FeedEntry, JoinResult, NotifyActionResult, StatusUpdate, AuthPrompt, ContentSnapshot, ContentActionResult, ModeratedUser, ModerationSnapshot, ModerationActionResult, plus CONTENT_SECTIONS and the two helpers that validate a section name arriving over HTTP.

web/hub.d #

Fan-out to connected browsers. publishState(), publishFeed(), and serve() (one call per connection, for the lifetime of the socket). Holds the state generation counter and the feed ring.

web/state.d #

State encoding. buildStateJSON() produces the snapshot; encodeFeedEntry() encodes one feed entry once so the hub can fan the string out as-is; buildContentJSON() produces the /api/content/:section body around the entries vrcd-server already trimmed.

web/images.d #

ImageCache: a bounded, mutex-guarded store of proxied images. lookup() answers ready, pending or failed and tells the caller when it has to start the fetch itself; store() and storeFailure() file the answer. Nothing here blocks or knows about the link.

readFromServerCache() reads one image straight out of vrcd-server's cache directory, and findServerImageCache() picks that directory (the flag, else vrcd-server's own default, else null for link-only). Both refuse anything that could climb out of the directory, since the file ID lands in a path.

web/debugging.d #

The fake-notification catalogue: DEBUG_FAKES (what the page draws buttons from, carried in the snapshot so adding one is a single edit), buildFakeNotification() (one NotificationInfo per action) and isDebugNotification() (the not_debug_ prefix, which is how an answer for one is told apart from an answer for a real notification). Plus the invented people a fake comes from: DEBUG_PEOPLE, isDebugUser() and buildFakeProfile(), which produces the same payload shape vrcd-server sends for a real profile. Knows nothing about the link or HTTP.

web/profiles.d #

ProfileCache: the same shape as ImageCache -- lookup() answers ready, pending or failed and tells the caller when it has to start the fetch -- with one difference. A profile goes stale where an image cannot, so entries expire after 5 minutes, and a stale one is still handed back with the refetch started underneath it. dropUnresolved() clears what a dropped link left in flight or failed, and keeps what was fetched.

web/auth.d #

SessionStore (login, session validation, ticket issue and redeem, expiry sweep) plus sessionFromCookies(), formField(), constantTimeEquals() and randomToken() (128 bits from RtlGenRandom or /dev/urandom).

web/assets.d #

AssetStore reads a file on demand and keeps it until its mtime moves, and findWebRoot() picks the directory. Replies carry Cache-Control: no-cache so the browser revalidates rather than sitting on an edited stylesheet.

Shared via sourceFiles: common/source/vrcd/friends.d (bucketing and ordering) and common/source/vrcd/events.d (labels and field extraction) with the SDL client, common/source/vrcd/notifications.d (the notification shape, in both the wire forms VRChat uses) with the SDL client and vrcd-server, and common/source/vrcd/badgeurl.d (what may be fetched as badge art) with vrcd-server, so none of them can drift.

Wire format #

State snapshot, sent on every change and also returned by /api/state:

{
  "type": "state",
  "connected": true,
  "vrchat_connected": true,
  "server_version": 3,
  "last_error": "",
  "self": {
    "id": "usr_...", "displayName": "...", "status": "active",
    "statusDescription": "...", "bio": "...", "pronouns": "...",
    "bioLinks": ["https://..."],
    "lastLocation": "wrld_...:12345~private(usr_...)", "lastWorldName": "..."
  },
  "roster": {
    "instances": [{
      "instance_id": "wrld_...:12345",
      "location": "wrld_...:12345~friends(usr_...)~region(eu)",
      "world_name": "...", "n_users": 12, "capacity": 32,
      "friends": [{
        "id": "usr_...", "displayName": "...", "status": "active",
        "statusDescription": "...", "platform": "standalonewindows",
        "location": "...", "pronouns": "..."
      }]
    }],
    "active_elsewhere": [], "offline": []
  },
  "notifications": [{
    "id": "not_...", "notification_type": "friendRequest",
    "sender_user_id": "usr_...", "sender_name": "...", "message": "...",
    "location": "", "received_at_unix": 1753632000
  }],
  "auth": { "kind": "two_factor", "method": "totp", "error": "Invalid code" },
  "join": { "attempted": true, "location": "...", "success": true, "error": "" },
  "notify_action": {
    "attempted": true, "notification_id": "not_...", "action": "accept",
    "success": true, "error": ""
  },
  "content": {
    "gallery": { "revision": 4, "loading": false, "loaded": true,
                 "count": 12, "total_count": 0, "more": false, "error": "" },
    "icon": {}, "sticker": {}, "emoji": {}, "prints": {}, "inventory": {}
  },
  "content_action": {
    "attempted": true, "action": "equip", "id": "inv_...",
    "success": true, "error": ""
  },
  "moderations": {
    "loading": false, "loaded": true, "error": "",
    "muted": [{ "user_id": "usr_...", "display_name": "..." }],
    "blocked": []
  },
  "moderation_action": {
    "attempted": true, "action": "block", "user_id": "usr_...",
    "display_name": "...", "success": true, "error": ""
  },
  "status_action": {
    "attempted": true, "pending": false, "status": "busy",
    "statusDescription": "at the club", "success": true, "error": ""
  }
}

self is absent until the server says who is logged in, join until a self-invite has been attempted this session, notify_action until a notification has been answered, status_action until a status change has been asked for, and content_action until something in STUFF has been acted on -- its id is the entry acted on, or the tag an upload went to. content is always there, with all six sections, and carries no entries on purpose: it says that a section moved, and the page fetches the entries from /api/content/:section. total_count is VRChat's own total, which only the inventory reports; more says the last page came back full. auth is there only while vrcd-server is waiting on a sign-in answer, so its presence is what raises the modal; kind is credentials or two_factor, method is VRChat's totp, otp or emailOtp and is empty on a credentials prompt, and error carries what went wrong last time. notifications is always present, empty array included: the page has to tell "nothing waiting" apart from "the link has not answered yet", and its length is the badge on the rail. location is set only on an invite, and is what lets the row offer a join instead of an acknowledgement. status_action carries what was asked for, since the set_status_result that answers it does not, and pending is true while the answer is outstanding: it lives in the snapshot rather than in the browser because the answer is broadcast, so a second browser on the same profile has to be able to show the change going out too. moderations is always there, empty lists included, for the same reason notifications is: "nobody is blocked" and "the link has not answered yet" are different things, and loaded is what tells them apart. Its entries do ride along, unlike the content sections: a name and an ID each, against a roster in the same message that is many times their size. moderation_action is absent until a mute, block, unfriend or friend request has been asked for this session, and carries the display name because the toast names whoever it was aimed at -- vrcd-server fills that in from its roster or from VRChat's answer, so it survives a name this side never had. debug is there only when the debugging tools are on, and carries the fake-notification catalogue (action, label, hint each); the page draws its DEBUG chip off the key existing, so a normal build costs nothing and shows nothing. server_version is the protocol version from auth_ok as a number, zero when unknown. n_users and capacity are -1 when unknown. Friend entries carry no bio, bioLinks or badges on purpose: they would bloat every broadcast, and a pane that wants them fetches the profile from /api/user/:user_id instead.

Feed frame:

{ "type": "feed", "reset": false, "events": [{
    "id": 1234, "event_type": "friend-location", "label": "Friend Location",
    "user": "alice", "detail": "The Great Pug",
    "received_at": "2026-07-27T18:00:00Z"
}]}

reset true means replace, false means append. received_at stays as the server's ISO 8601 UTC string so the browser renders it in the viewer's timezone.

Front-end #

Plain files, no build step, no framework, no external requests (a page that phones out would break behind a tunnel and leak who is looking).

File Purpose
index.html Shell markup, plus the icon sprite inlined so the rail draws without a second round trip
app.css Whole stylesheet, dark, CSS custom properties for the palette
app.js Everything else: socket, state, rendering
login.html, login.css, login.js Sign-in page

The layout is three columns on a desktop (tab rail, list, detail) and one on a phone, where the rail becomes a bottom bar and the detail pane becomes a pushed page. That transformation is entirely CSS, driven by the data-pane attribute on #shell and one max-width: 64rem media query. Buttons are sized for a thumb, since the point of the web front-end is reading the roster on a phone while in headset.

Tabs:

Tab State
Feed Live. Newest first, filterable; clicking an event jumps to that friend
Online Live. Friends grouped by instance, with instance and friend detail
Inbox Live. Friend requests and invites, oldest first, with a count badge on the rail
Stuff Live. Gallery, icons, stickers, emoji, prints and inventory items as grids, with uploads, deletes, the profile icon, and equip/unequip/consume
Tools Live. The whole friends list, plus the mute and block lists, with mute, block, unmute, unblock and unfriend. A DEBUG chip joins them under --debug
Profile Live. Self profile, the status picker, plus the connection block

The inbox draws its buttons in the row rather than the detail pane: answering a friend request should be one tap, and in a headset the detour through a second pane is the expensive part. What each row offers depends on the type, and only what vrcd-server can actually do appears:

Type Buttons
friendRequest ACCEPT, DECLINE
invite JOIN WORLD (the same self-invite the roster offers), DISMISS
requestInvite DISMISS, and a line saying why there is nothing else - sending an invite back needs an API the server does not expose

VRChat's accept endpoint only means anything for a friend request, so an invite is answered by going where it points instead. Any sender with a user ID opens in the detail pane, friend or not -- the stranger is the one whose pane is worth opening, since accepting a friend request is exactly the decision that needs a bio and a trust rank to make.

One profile layout serves all three callers: your own profile, a friend's pane, and a stranger's. Rows appear only when the field is present, so the difference between them is which fields the record carries -- a friend request sender is a thinner record than a friend, not a different kind of thing. It draws the snapshot merged with the fetched profile (see Profiles): the hero with the face, the name, pronouns and status, then the pills that qualify it (trust rank, VRChat Team, flagged, 18+ verified, not a friend), the badge grid, the bio as a paragraph with its own line breaks kept, the links, and only then the field list.

The deliberate differences are the status picker, which the profile tab asks for with editStatus and nobody else does, and the moderation buttons, which a friend's or a stranger's pane asks for with moderate and your own never does: none of them are aimed at yourself. friend tells the pane whether UNFRIEND belongs in that set, and is read from the roster rather than from the profile's isFriend, so accepting a request promotes the pane within a snapshot instead of waiting on a fetch.

A stranger's pane offers ADD FRIEND in place of UNFRIEND, or CANCEL REQUEST when one is already out. That one is read from the profile's friendRequestStatus, since the roster has nothing to say about a request, so the button waits for the fetch, and every result drops the profile at all three levels for the next look to see where the request now stands. Add arms first like block: the other side sees it. Cancel is one tap. An incoming request gets neither, since the inbox already offers its accept.

Status #

Your own status is set from the profile tab, directly under the hero and above the fields nobody opened the tab to read. It is on that tab and not on the self card in the rail, which would have been the shorter reach on a desktop: the card lives in the rail foot, the bottom bar has no foot, and a popup hung off it would exist only on the layout that is not the phone. The card is the way in instead -- it already opens the tab.

The four are drawn as the rows the friends list is built from -- .flat, .row, .row.on, plus a tick -- left-aligned, and always open. Which is what a dropdown's opened menu looks like anyway, minus the press that opens it: VRChat and Discord hang theirs off a trigger because their status control lives in cramped chrome, and this pane has the room to just show them. Only the disabled state and the tick are new CSS, and both stay scoped to .status-list since no other row is ever disabled.

A press selects; nothing is sent until SET STATUS. Both reasons are about this being a list inside a scrolling pane. A stationary mis-tap on the way to the message box would otherwise reach VRChat -- a touch that moves enough to scroll never fires click, so the drag is safe, but the fat-finger tap is not. And a status and a message picked together would cost two VRChat calls instead of the one set_status that carries both fields. The SDL client stages the same way (selfStatusDraft behind a Set button).

That means two states have to be legible at once, and the two the app already draws split cleanly:

Mark Means
Accent band (.row.on) What SET STATUS will send
Tick What VRChat has now

They sit on the same row until a pick separates them, so a staged change needs no badge of its own, and the tick is muted on a plain row and light on an accented one. SET STATUS goes .primary while anything differs, which is the app's existing "this is the action" cue, and pressing the row that is already live puts everything back and disarms it. Enter in the box does what the button does. Sending an empty box is how the message is cleared, and only the fields that actually changed go in the request.

Both the staged pick and the typed message live outside the DOM (statusChoice, statusDraft, plus where the caret was) for the same reason the print caption does: a snapshot arrives on every friend movement and redraws the pane. Null means untouched and shows what VRChat has, so an in-game change appears there; once touched, the staged value wins until it is sent or the answer comes back. The button's handler reads both at the press rather than closing over what was on screen when it was drawn, since typing does not redraw the pane. Nothing is applied optimistically -- the tick moves when the self broadcast says it moved, which is also what makes an in-game status change or another browser's edit show up here.

A failure is said twice, on purpose: a toast, and a line under the picker that stays. The toast is gone in six seconds, which on a phone is long enough to miss while scrolling. The stale-result problem the toast has everywhere else (the snapshot carries the last outcome indefinitely) is handled by seeding rather than reporting the first snapshot: a result from before this page opened is not news. The flag flips on the first snapshot whether or not it carried an outcome, or the first real one would be swallowed as though it predated the page.

World thumbnails are stand-in gradients seeded from the world name. The image proxy that would replace them exists now, but the roster carries no world image to ask it for; that needs the world cache vrcd-server keeps. Everything in STUFF goes through the proxy, and falls back to the same gradient when there is nothing to fetch -- an item with no artwork, or a file whose only versions were deleted (version: 0, which the proxy would refuse anyway).

Dependencies #

Package Purpose
ddhttpd HTTP and WebSocket server (libmicrohttpd wrapper)
ddlogger Structured logging

System packages:

  • Ubuntu: libmicrohttpd12t64 (runtime), or libmicrohttpd-dev for a static binding via subConfiguration "ddhttpd" "static-binding"

ddhttpd loads libmicrohttpd dynamically by default, so no development package is needed to build.

Building #

dub build :web
dub test :web
./web/vrcd_web --web-secret hunter2

The binary looks for public/ beside itself first, so a package is the binary plus that directory. Running from the repository root works too, via the ./web/public candidate.