Get in the mix — no viewer required

The viewer is one consumer of the server’s API. You are about to be another. Everything the viewer shows arrives through HTTP calls and a websocket feed, and both are open to you from the terminal.

  1. Sign in. Every authenticated call carries a token. nix run .#login asks the server for one and writes it to .token:

    nix run .#login -- <username> <password>

    Before you run it: What’s your expected error code when using wrong credtentials? Try and compare.

  2. Ask who you are, and where. nix run .#api sends .token with the request and stores the fresh token each response carries — the server rotates them, and this is how every client stays signed in, the viewer included.

    nix run .#api -- /api/auth/me | jq '{_id, username}'

    Take the _id and ask for your rooms:

    nix run .#api -- "/api/user/rooms?id=<_id>" | jq .

    The _id is the server’s name for you; the room name is where your colony runs. Everything you own on this server is filed under one or the other — the feed you subscribe to in step 3 is keyed by the room name, and the memory you read in step 4 is keyed by your identity. These two calls are how any client gets those keys, the viewer included.

  3. Watch the room over the websocket. room-feed.sh does the whole dance — sign in, find your room, subscribe to its feed — and prints one JSON snapshot with your spawn’s position and the room’s sources:

    nix run .#room-feed -- <user> <pass>

    From the coordinates alone: which source is closer to your spawn? Hold that answer — “Picking a source” comes back to it.

    Then read the script; it is short. Find the three moves the viewer also makes when the page loads: auth, subscribe, first snapshot.

  4. Read your creep’s diary. The harness logs each creep’s actions to Memory.trace, and the memory API serves it:

    nix run .#api -- '/api/user/memory?path=trace'

    How many harvest entries land between one transfer and the next? That number is the creep’s trip, measured from its own record.

Use your agent to go further: every endpoint the viewer calls is in viewer/src/protocol.ts.

← Resume “Let’s Play Screeps”