@mavonengine/cli 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -1
- package/dist/{chunk-TGGH7KA4.js → chunk-7UZYGMGO.js} +1 -1
- package/dist/{chunk-KHC2RAKX.js → chunk-IIWBECVS.js} +1 -1
- package/dist/{docs-QCI5VKET.js → docs-S2SWFUIL.js} +2 -2
- package/dist/index.js +663 -58
- package/dist/{server-QSZHAYK2.js → server-AC5LBJ6A.js} +101 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,12 @@ npx @mavonengine/cli install @acme/forest@^2 file:../my-plugin --yes
|
|
|
109
109
|
- `prefabs`: the plugin prefabs the project uses. The editor adds a prefab here when you place it, and you can edit the list by hand. Only the assets of these prefabs (plus the plugin's shared assets) go into the release.
|
|
110
110
|
- `options`: passed to the plugin as `ctx.options`.
|
|
111
111
|
|
|
112
|
+
Next to `plugins`, the file says what goes for the whole project:
|
|
113
|
+
|
|
114
|
+
- `appUrl`: where the game is, like `https://mygame.com`. Links that leave the game, such as those in mails, point there. Server plugins get it as `ctx.appUrl`. `MAVONENGINE_APP_URL` overrides it, for example per deployment.
|
|
115
|
+
- `appName`: the game's name, in mails and in the browser tab: `%MAVONENGINE_APP_NAME%` in the client's `index.html` becomes it, in dev and in the build (`MavonEngine` without one). Server plugins get it as `ctx.appName`.
|
|
116
|
+
- `database`, `auth`, `notifications`: which plugin to use when more than one of that kind is enabled.
|
|
117
|
+
|
|
112
118
|
The client reloads when the plugins in `mavonengine.json` change. Restart the game server to load a new server plugin. Without an interactive terminal it only installs, unless `--yes` is given.
|
|
113
119
|
|
|
114
120
|
| Option | Default | |
|
|
@@ -117,6 +123,23 @@ The client reloads when the plugins in `mavonengine.json` change. Restart the ga
|
|
|
117
123
|
| `-y`, `--yes` | | Add plugins to `mavonengine.json` without asking |
|
|
118
124
|
| `--no-register` | | Only install |
|
|
119
125
|
|
|
126
|
+
## `mavonengine asset:publish`
|
|
127
|
+
|
|
128
|
+
Copies the files a plugin lets you change into your project, such as the mail plugin's layout:
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
npx @mavonengine/cli asset:publish @mavonengine/mail
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
They go to `resources/<package>/`, here `resources/@mavonengine/mail/layout.html`. The plugin uses your copy from then on, so change it there and commit it. Files you have already are kept, so publishing again after an update only adds the plugin's new files. `--force` replaces yours with the plugin's.
|
|
135
|
+
|
|
136
|
+
A plugin offers files with `"publish": "<directory>"` under `mavonengine` in its `package.json`, and finds your copy with `ctx.publishedFile('<file>')`.
|
|
137
|
+
|
|
138
|
+
| Option | Default | |
|
|
139
|
+
| --- | --- | --- |
|
|
140
|
+
| `--cwd <dir>` | current directory | Where to start looking for the project |
|
|
141
|
+
| `--force` | | Replace the files you have with the plugin's |
|
|
142
|
+
|
|
120
143
|
## `mavonengine build`
|
|
121
144
|
|
|
122
145
|
Runs the project's `build` script, then lists what each plugin put into the release. Plugin assets are copied into the client's output under `plugins/<package>/`. Only the shared ones and those of the prefabs in `mavonengine.json` are copied. The client skips loading the others, so a release never requests a file it doesn't contain.
|
|
@@ -157,7 +180,7 @@ npx @mavonengine/cli dashboard --sim
|
|
|
157
180
|
| `--transparent` | | Let a transparent terminal background show through. Text can be hard to read over a light wallpaper |
|
|
158
181
|
| `--sim` | | Simulated data instead of a server |
|
|
159
182
|
|
|
160
|
-
Keys: `q` quits, `r` refreshes now, `o` opens the game the server serves in the browser, `1`–`7` switch between the Overview, Players, Logs, HTTP, Network, Routes and Plugins tabs. The mouse wheel scrolls the players table, the logs, the requests, the packets and the routes; scroll the logs back to the bottom, or the requests and packets back to the top, to follow new ones again.
|
|
183
|
+
Keys: `q` quits, `r` refreshes now, `o` opens the game the server serves in the browser, `1`–`7` switch between the Overview, Players, Logs, HTTP, Network, Routes and Plugins tabs, and `8` to the Database tab when the server has a database plugin. The mouse wheel scrolls the players table, the logs, the requests, the packets and the routes; scroll the logs back to the bottom, or the requests and packets back to the top, to follow new ones again.
|
|
161
184
|
|
|
162
185
|
The HTTP tab lists every request the game server's HTTP server received, newest first: the client (static files or Vite in dev), your own `onHttp` routes, the geckos.io signaling requests and WebSocket upgrades such as Vite's HMR socket, each with status, duration, size and client address. Query strings are left out since they can hold tokens, and the dashboard's own polling is not recorded. The game traffic itself is WebRTC, not HTTP, so it shows on the Players tab instead; with a separate `socketPort` the signaling requests go to that port and don't show up either.
|
|
163
186
|
|
|
@@ -169,6 +192,8 @@ The Plugins tab lists the plugins in the project's `mavonengine.json` with their
|
|
|
169
192
|
|
|
170
193
|
Below it, "Available to install" lists the plugins from [`mavonengine plugins`](#mavonengine-plugins) that the project doesn't have yet. The dashboard reads that list from GitHub itself, the first time the tab is shown and again on `r`; a dashboard that never opens the tab never asks for it.
|
|
171
194
|
|
|
195
|
+
The Database tab looks into the server's database. It only shows up when the server runs a database plugin such as [`@mavonengine/sqlite`](https://github.com/MavonEngine/Core/tree/main/packages/plugins/sqlite), which it marks in `GET /api/game/plugins`. It lists the tables with the plugin each belongs to (by its table prefix, `game` for the rest) and their number of rows, shows the rows of the selected table and, below, the migrations each plugin ran. `↑`/`↓` (or `j`/`k`, or a click) pick a table, `←`/`→` (or page up / page down) page through its rows. It only reads, and only while the tab shows, every 5 seconds. The database holds what players did, so the server only shows it with its admin token: start the dashboard with `--token <admin token>` for a server that has one; without one it only answers on the server's own machine. It needs a server on a `@mavonengine/core` release with `GET /api/game/database`.
|
|
196
|
+
|
|
172
197
|
Under [`mavonengine dev`](#mavonengine-dev) a plugin from that list can be installed right there: select it with `↓` and press `i`. The dashboard first asks whether you checked its source, because installing a package runs its code on your machine; `y` installs it with the project's package manager, adds it to `mavonengine.json` and restarts the dev servers, `n` cancels. A dashboard started on its own with `mavonengine dashboard` only shows the command, since it can't restart servers it didn't start.
|
|
173
198
|
|
|
174
199
|
### Server access
|
|
@@ -263,6 +288,15 @@ Plugin tools:
|
|
|
263
288
|
|
|
264
289
|
With these an assistant can suggest a plugin instead of building what one already does, and set it up from its readme. It can't install one: every tool is read-only, so it hands you the command. `available_plugins` and `plugin_readme` read the list and the readmes from GitHub when they are used; `--plugins-url` or `MAVONENGINE_PLUGINS_URL` points them at another list and `--no-plugin-list` leaves them out.
|
|
265
290
|
|
|
291
|
+
Database tools, for the project's database plugin such as [`@mavonengine/sqlite`](https://github.com/MavonEngine/Core/tree/main/packages/plugins/sqlite):
|
|
292
|
+
|
|
293
|
+
| Tool | |
|
|
294
|
+
| --- | --- |
|
|
295
|
+
| `database_overview` | Which plugin gives the database, every table with the plugin it belongs to, its columns and row count, and the migrations each plugin ran |
|
|
296
|
+
| `database_rows` | A page of one table's rows, with the total |
|
|
297
|
+
|
|
298
|
+
They read through the server's `GET /api/game/database` endpoints, so they work with any database plugin and only read. Like the dashboard's Database tab they need the server's [admin token](#admin-token) as `--token`, unless the server runs on the same machine without one. What a tool returns goes to the assistant's model, so `database_rows` replaces the values of columns that look secret, such as password and session token hashes, with `[redacted]` and lists them in `redacted`.
|
|
299
|
+
|
|
266
300
|
Documentation tools, passed through to the MCP server of [mavonengine.com](https://mavonengine.com) (`https://mavonengine.com/mcp`), so answers come from the current docs:
|
|
267
301
|
|
|
268
302
|
| Tool | |
|
|
@@ -367,6 +401,42 @@ export default defineServerPlugin({
|
|
|
367
401
|
|
|
368
402
|
A plugin that takes the token some other way, such as the password of a login, checks it with `ctx.adminToken.matches(candidate)`, without ever seeing the token.
|
|
369
403
|
|
|
404
|
+
### Authenticating players
|
|
405
|
+
|
|
406
|
+
An auth plugin decides who may connect, before a client gets a player. [`@mavonengine/auth`](https://github.com/MavonEngine/Core/tree/main/packages/plugins/auth) is one, with accounts, passwords and sessions; write your own for anything else. Its client entry gives the token the game connects with, and its server entry's `authorize()` checks it:
|
|
407
|
+
|
|
408
|
+
```ts
|
|
409
|
+
// client.ts: sent as the Authorization header of the connection request
|
|
410
|
+
export default defineClientPlugin({
|
|
411
|
+
authorization: () => {
|
|
412
|
+
const token = localStorage.getItem('session')
|
|
413
|
+
return token ? `Bearer ${token}` : undefined
|
|
414
|
+
},
|
|
415
|
+
})
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
// server.ts
|
|
420
|
+
export default defineServerPlugin({
|
|
421
|
+
async authorize(authorization, request, ctx) {
|
|
422
|
+
const account = await findSession(ctx.db, authorization)
|
|
423
|
+
if (!account)
|
|
424
|
+
return false // 401
|
|
425
|
+
if (account.banned)
|
|
426
|
+
return 403
|
|
427
|
+
return { id: account.id, name: account.username }
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
`authorize()` returns an identity (`{ id, name?, … }`) to let the client in as that account, `true` to let it in without one (a guest), or `false` or an HTTP status from 400 to 599 to turn it away. The identity is also sent to the client, so keep it to what the player may see. A throw or any other result turns that one client away with 500, and the next client is still asked.
|
|
433
|
+
|
|
434
|
+
Other plugins read the identity with `ctx.identity(channel)`, and the game with `player.identity` on the server or `network.identity` on the client. Key anything that should outlast a connection, such as a mute or a score, on `identity.id`: `channel.id` changes every time the player reconnects.
|
|
435
|
+
|
|
436
|
+
On the client, a refusal arrives as the `connectError` event of the `NetworkManager` (and its `onConnectError()`), with the `status` the server answered. The token is read when a `NetworkManager` is made, so to connect again after logging in, make a new one. A game that handles the token itself passes `authorization` to the `NetworkManager` instead.
|
|
437
|
+
|
|
438
|
+
Only one auth plugin is asked: with more than one enabled, set `"auth": "<package>"` in mavonengine.json. When the project has an auth plugin that doesn't run, for example because one of its migrations failed or the package named in `auth` isn't enabled, the server turns every client away with 503 instead of letting them in unchecked. The editor connects like a client too, so with an auth plugin it needs a token as well: when the server turns it away, the editor's status bar and Network panel say why. A server in production (`NODE_ENV=production`) ignores clients that ask to attach the editor, since the editor is sent every entity in the world.
|
|
439
|
+
|
|
370
440
|
Projects made with `mavonengine create` are already set up for plugins. To set up an existing project:
|
|
371
441
|
|
|
372
442
|
```ts
|