Skip to content

About

The web api and dashboard for the Global Ban Minecraft mod

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Global Ban WebAPI

The web API and dashboard for the Global Ban Minecraft mod. Servers sync punishments to and from it with a single POST request, and server owners manage servers, communities and members in the dashboard.

Built with Astro (SSR, Node adapter), Effect v4, Drizzle on libSQL/SQLite, better-auth (Discord sign-in) and Tailwind.

For a public instance available to anyone check out https://global-ban.matthiesen.dev

Getting started

Requires Node 22.12+ and pnpm.

pnpm install
cp .env.example .env   # then fill in the values below
pnpm db:migrate
astro dev

Environment

Variable Purpose
DATABASE_URL libSQL URL, e.g. file:local.db or a Turso URL
DATABASE_AUTH_TOKEN Auth token for remote libSQL (leave empty for a local file)
BETTER_AUTH_SECRET Long random secret used to sign sessions
BETTER_AUTH_URL Public base URL of this app
DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET Discord OAuth app credentials. Set the redirect URI to <BETTER_AUTH_URL>/api/auth/callback/discord
TRUSTED_PROXY none (default), traefik or cloudflare. Selects which header carries the client IP for rate limiting
TRUSTED_PROXY_HOPS Number of trusted proxies that append to X-Forwarded-For (default 1, used by traefik)

Scripts

Command Description
pnpm dev Start the dev server
pnpm build / pnpm preview Production build (Node standalone) and preview
pnpm check Type-check with astro check
pnpm test Run the vitest suite (uses in-memory libSQL)
pnpm db:generate Generate a migration after changing src/db/schema.ts
pnpm db:migrate Apply migrations

Connecting a Minecraft server

  1. Sign in to the dashboard with Discord.
  2. Open Servers and register the server using the UUID from the mod's server config. Treat this UUID as a secret: it is the only credential the mod sends.
  3. Assign the server to a community. A server that is not in a community receives 403 from the sync endpoint.
  4. In the mod's config, set scheduler_apiSyncUrl to <your-host>/api/v1/sync.

Sync API

POST /api/v1/sync

Headers: Content-Type: application/json, X-Global-Ban-UUID: <server uuid>

The body and the response use the same shape, matching the mod's SyncData record (see src/domain/punishment.ts):

{
  "punishments": [
    {
      "type": "ADD",
      "record": {
        "type": "BAN",
        "timestamp": 1700000000,
        "duration": -1,
        "playerUuid": "…",
        "playerIp": "203.0.113.7",
        "playerDisplayName": "Player",
        "punisherUuid": "…",
        "punisherDisplayName": "Moderator",
        "reason": "Griefing",
        "serverUuid": "…"
      }
    }
  ]
}
  • Sync type is ADD or REMOVE. Punishment type is BAN, IP_BAN or KICK. duration of -1 means permanent.
  • The request carries the server's pending punishments. The response carries only what that server has not received yet: punishments from its community and from approved subscriptions, plus REMOVE for ones it was given that have since been revoked.
  • Delivery is tracked per server, so repeating a request returns nothing new. Re-sending the same punishment is harmless.
  • serverUuid in responses is the origin server's public id, never its secret UUID. Punishments whose origin server was deleted use the all-zero UUID.
Status Meaning
200 Success (the mod clears its pending queue on this)
400 Missing or invalid header, malformed JSON or body, or body over 1 MB
403 Server not registered, or not assigned to a community
429 Rate limited; the Retry-After header gives the seconds to wait
500 Database error
curl -X POST http://localhost:4321/api/v1/sync \
  -H 'Content-Type: application/json' \
  -H 'X-Global-Ban-UUID: 11111111-1111-4111-8111-111111111111' \
  -d '{"punishments":[]}'

Rate limiting

Two in-memory token buckets guard the endpoint (src/services/rateLimit.ts):

  • Per client IP, checked before any parsing or database access: burst of 120, refilling 2 per second.
  • Per server UUID: burst of 10, refilling 1 every 10 seconds. This also applies to unregistered UUIDs.

Both are far above the mod's minimum one-minute sync interval. State is per process, so it resets on restart and is not shared between multiple instances. IPv6 clients are limited per /64.

The public appeal pages use their own per-IP buckets: name lookups (burst 20, 1 per 5 seconds), IP lookups (burst 5, 1 per 50 seconds) and appeal submissions (burst 5, 1 per 200 seconds).

Reverse proxies

By default the limiter uses the connection's address, which behind a proxy is the proxy itself. Set TRUSTED_PROXY so the real client IP is used instead:

  • cloudflare: reads CF-Connecting-IP, which Cloudflare sets itself, including for Tunnel and Access traffic. This also works for Cloudflare Tunnel in front of Traefik, since the header passes through.
  • traefik: reads X-Forwarded-For counted from the right, so values a client adds are ignored. Set TRUSTED_PROXY_HOPS if more than one trusted proxy appends to it.

If the expected header is missing or not a valid IP, the connection address is used. These headers can be forged by anyone who reaches the app directly, so only enable a mode when the app is reachable solely through that proxy: keep it off published host ports, and use a Tunnel or firewall rules.

Dashboard

  • Servers: register, move between communities, transfer or delete. Last sync time is shown per server.
  • Communities: create communities, request to join, accept invites, subscribe to other communities.
  • Community page: members and roles, invites by Discord user ID, join requests, subscription approvals, ownership transfer and deletion.
  • Punishments: punishments from your communities, with player IPs always masked. Admins can revoke.
  • Appeals: appeals sent to communities you administer. See Appeals.
  • Transfers: accept, decline or cancel ownership offers.

Roles and access

New accounts only see their own servers and communities.

Role Can do
Owner Everything, including promoting admins, transferring ownership and deleting the community
Admin Invite members, approve join requests, remove members, approve subscriptions, revoke punishments, decide appeals and manage ban overrides
Member View members and punishments, add their own servers, leave
  • Invites are tied to an immutable Discord user ID and can only be accepted by the linked Discord account. Users can copy their ID from Discord with Developer Mode enabled.
  • A subscription lets one community receive another's punishments. It stays pending until an admin of the source community approves it, and sync ignores pending ones.
  • Removing a member detaches their servers from the community.
  • Ownership transfers need the recipient to accept. A transferred server leaves its community if the new owner is not a member of it.
  • Deleting a server or community requires typing its name. Deleting a community removes its punishment records. Deleting a server keeps the punishments it originated.

Appeals

Players can appeal bans without an account. Only BAN and IP_BAN punishments are appealable; KICK never reaches this API.

  1. At /appeal the player looks up their name or IP address. Only active (not revoked, not expired) bans are listed, and only the community, type, reason and date are shown. The IP, punisher and server are never exposed.
  2. The player picks the bans and communities to appeal to and submits a message with an optional contact. Each community gets its own appeal. Eligible communities are the one that issued the ban plus every community with an approved subscription to it.
  3. The player receives a private link, /appeal/case/<token>, to read replies, answer or withdraw. The token is shown once and only its SHA-256 hash is stored, so keep the link.
  4. Admins of the receiving community review it under Appeals in the dashboard and can reply, approve or deny.

What approval does depends on who decides:

  • Issuing community: the punishment is revoked everywhere, and servers receive a REMOVE on their next sync.
  • Subscribing community: a ban override is created. The ban is lifted for that community's servers only and stays active elsewhere. Admins list and remove overrides on the community page; removing one re-sends the ban to the community's servers.

The deciding admin is recorded as decidedByUserId on the appeal and revokedByUserId on a revoked punishment. Dashboard revokes record it too; revokes that arrive through sync do not.

Each punishment and community pair can be appealed once. A withdrawn appeal can be filed again; a decided one cannot.

Because there is no login, anyone who knows a player's name can look up and appeal that player's bans. Lookups and submissions are rate limited per client IP, with the strictest limit on IP lookups.

Project layout

src/domain/     Effect schemas mirroring the mod's Java records, IP masking
src/db/         Drizzle schema and client
src/services/   Effect services: sync, dashboard, membership, ownership, appeals
src/pages/api/  /api/v1/sync and the better-auth handler
src/pages/appeal/     Public appeal lookup, submission and case pages
src/pages/dashboard/  Server-rendered dashboard pages
drizzle/        Generated SQL migrations

License

This project is MIT Licensed

About

The web api and dashboard for the Global Ban Minecraft mod

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages