Tooling

Admin Panel

The game server's admin panel at /admin/, behind the admin token, with the runtime, scene graph, physics, routes, plugins and the pages plugins add.

The game server serves an admin panel at /admin/. It is one layout with a sidebar, and you log in with the server's admin token:

http://localhost:8050/admin/

The engine adds three pages, listed under Server in the sidebar:

  • Overview: uptime, players, entities and physics bodies. Below that it shows the runtime (engine, Three.js, Rapier and Node.js versions, mode and platform), the server's scene graph (objects, meshes, triangles, lights and the most common object types) and its physics world (bodies by type, sleeping bodies, colliders, gravity and timestep). It ends with a tile for every other page of the panel.
  • Routes: every HTTP endpoint of the server, with its method, path, where it comes from, what it does and who may call it. This is the same list as the dashboard's Routes tab.
  • Plugins: the plugins in mavonengine.json, with their version, whether they run on the server and which one is the database, auth or notifications plugin.

Plugins add their own pages under Plugins:

PagePlugin
/admin/accounts/@mavonengine/authEvery account with how it logs in, its sessions and whether it is online. You can search it, and disable, enable or log out an account
/admin/mail/@mavonengine/mailThe dev inbox: every mail the game sent in development
/admin/monitoring/@mavonengine/http-monitoringThe game server dashboard, with its tabs in the sidebar

Logging in

MAVONENGINE_ADMIN_TOKEN=… npm start

You can also set adminToken in the server's options. In the browser's login prompt, enter the token as the password; the user name can be anything. Tools can send it as Authorization: Bearer <token> instead.

  • Plugins can let more people in. @mavonengine/http-monitoring does this with an htpasswd file, whose users then log in to the whole panel.
  • Without an admin token or another login, the panel only answers requests from localhost. In production (NODE_ENV=production) it stays off until the server has one.
  • After 10 failed logins, an address is locked out for 5 minutes.
  • Basic auth sends the password with every request, so put HTTPS in front of a public server.

Options

const server = new MyServer(logger, physicsWorld, {
  admin: { path: '/ops' },        // serve it at /ops/ instead
  // admin: { enabled: false },   // or turn it off
})
OptionDefault
admin.enabledtrueServe the panel. In production it also needs an admin token or a login
admin.path/adminWhere it is served. Can't be /

Adding a page

A plugin adds a page with ctx.admin.page() in its http() hook. The page shows up in the sidebar under Plugins, and the links it gives are listed below it:

import { defineServerPlugin } from '@mavonengine/core/Plugins/types'

export default defineServerPlugin({
  http(app, ctx) {
    ctx.admin.page({
      path: 'chat', // /admin/chat/
      label: 'Chat',
      icon: 'chat',
      children: [
        { label: 'Live', href: '#live' }, // an anchor on the page
        { label: 'Mutes', href: 'mutes', render: () => '<p>…</p>' }, // a sub page, /admin/chat/mutes/
      ],
      render: req => ({
        html: '<div class="adm-page">…</div>',
        styles: [ctx.admin.url('chat/style.css')],
        scripts: [ctx.admin.url('chat/app.js')],
      }),
    })

    // Every route under the panel's path is behind its login already
    app.get(ctx.admin.url('chat/api/messages'), (_req, res) => res.json({ messages: [] }))
  },
})
Page field
pathWhere it is under the panel: chat → /admin/chat/
labelIts name in the sidebar
icondashboard, activity, routes, plugin, database, users, logs, settings, chart, mail, chat, bell or lock. Anything else shows the label's first letter
groupThe sidebar heading it is listed under. Plugins by default
orderLower comes first within its group. Default 100
childrenLinks shown under it while it is open. An href is an anchor (#live), a path below the page (mutes, served in the layout when it has a render), or an absolute path or URL
render(req)Returns the page's HTML, or { html, title, styles, scripts, data }. data becomes data-* attributes on <body>
  • Escaping: the HTML goes into the layout as it is. Escape anything that came from players or requests with escapeHtml() from @mavonengine/core/Networking/Server/Admin/AdminPanel.
  • Scripts: the page's Content-Security-Policy blocks inline <script> tags and style attributes, so ship script and style files.
  • Styling: the layout's colors are CSS custom properties (--surface, --border, --primary, …), and it has classes for pages: adm-page, adm-cards, adm-card, adm-table and adm-badge.
  • Replacing: a page registered again under the same path replaces the earlier one.

The rest of ctx.admin:

ctx.admin.url(path)The absolute path under the panel: url('chat/api') → /admin/chat/api
ctx.admin.pathWhere the panel is, without a trailing slash
ctx.admin.enabledWhether it answers
ctx.admin.guardThe panel's login as Express middleware, for routes outside its path
ctx.admin.addLogin((user, password) => …)Let more people log in than whoever has the token, e.g. the users of an htpasswd file. It may return a promise

ctx.admin is undefined on a @mavonengine/core from before the admin panel, so a plugin that should also run there checks for it first: if (ctx.admin) ctx.admin.page(…).