Repository navigation
Conversation
server.queue (ctx.queue for plugins) runs jobs in the background:
classes extending Job with handle(), tries, backoffMs and a queue, put on
it with dispatch(job, { queue, delayMs }), or run right away with
dispatchSync(). A job that throws is tried again after its backoff while
it has tries left, then kept among the failed jobs, which can be listed,
retried and forgotten, and its failed() is called.
Jobs are kept in memory by default. When the project has a database
plugin they are kept in the database instead, in core_jobs and
core_failed_jobs, created by the queue's own migration (recorded in
core__migrations). It runs without holding up the start: jobs dispatched
meanwhile move to the database once it is ready, and a failed migration
leaves the queue in memory. A job is claimed with an update only one
worker can win, so servers can share a database, and a job reserved
longer than retryAfterMs is taken to be abandoned and run again.
The worker runs in the server's process after plugins' setup(), with the
queue option for driver, concurrency, queues in priority order and
polling. Jobs whose class isn't registered wait on the queue, so jobs
queued before a restart run once their class is registered. stop() waits
for running jobs before the database is closed.
The metrics snapshot has the queue now: where it keeps its jobs, whether this server works them, and a history of how many jobs were queued and running, and how many were processed, retried and failed in each sample window. Counting the jobs can take a database query, so a sample has the count the one before asked for. The queue counts what it ran for this. The overview of mavonengine dashboard shows it in a Queue panel next to World: a graph of queued, processed and failed jobs, with the queued and running jobs and the totals over the graph's window. A server without a queue in its metrics keeps the old layout. The simulator fills and works off a queue, from the step rather than random(), so the rest of the simulation stays as it was.
A plugin can offer other plugins an api: what its api(ctx) returns, which
they get with ctx.plugin('<package>'). Every plugin's api() runs once
before any setup(), so a plugin can use another's in its setup() whatever
order they load in, on the server and in the client. It is undefined when
that plugin isn't installed, enabled or running, has no api or its api()
threw, so plugins can work without the ones they use. On the server the
apis are asked for after the migrations, so a plugin they turned off has
none.
A plugin adds its api's type to ServerPluginApis or ClientPluginApis, so
ctx.plugin() knows it on that side: a plugin's api in the browser can
differ from its server's. ctx.plugin<T>() types any other.
This is for plugins that build on each other, like a mail plugin that
provider plugins give a transport to.
ctx.plugin('@mavonengine/auth') is auth(server) now, typed through
ServerPluginApis, so a plugin finds an account's email without
depending on the auth plugin: undefined when the project has none.
A plugin offers files a project may change, like a mail layout, with "publish": "<directory>" in its manifest. mavonengine asset:publish <package...> copies them into the project's resources/<package>/, and the plugin finds the project's copy with ctx.publishedFile(path), else uses its own. Files the project has already are kept, as they may have been changed, so publishing again after an update only adds new ones; --force replaces them. Paths can't point outside the plugin's directories.
appUrl and appName sit at the top of mavonengine.json, next to database and auth, as they are the whole game's rather than one plugin's. Server plugins get them as ctx.appUrl and ctx.appName, and the server has both as options and getters. MAVONENGINE_APP_URL overrides appUrl, e.g. per deployment; only http(s) URLs count, without a trailing slash. Both are read when asked, so plugins see what is set now. ctx.appUrl is for links that leave the game, like those in mails: a plugin shouldn't build them from a request's Host header, which whoever sends the request chooses.
mavonengine create sets appName in mavonengine.json from the project's name, my-game as My Game, next to renaming package.json. A name the template sets is kept, and so is the rest of the file. The engine's Vite plugin fills %MAVONENGINE_APP_NAME% in index.html with appName, escaped, in dev and in the build: read for every page in dev, so a new name shows on the next reload, and written into the built page, so a release needs a rebuild after changing it. Without a name, or with a mavonengine.json it can't read, it is MavonEngine. It runs before Vite's own %...% replacement, and the dev bridge script stays dev only. The template's title is the placeholder now. The template's README says to set appUrl before deploying: without it a production server mails no links.
# Conflicts: # packages/core/src/Networking/Server/Server.ts # packages/core/src/Plugins/types.ts
# Conflicts: # packages/core/src/Networking/Server/Server.ts
Mail is written as Mailable classes and sent with
mail.to(address).send(mailable), from another plugin through
ctx.plugin('@mavonengine/mail') or from the game with mail(server). It is
checked and rendered when it is sent, so a mail without a recipient,
subject or body, with an address that is none or with a line break in a
header throws a MailError right away, and what waits on the queue is the
finished mail as plain JSON. send() queues it by default, tried 3 times
with backoff; sendNow(), queued = false or { queued: false } send in the
call, and { delayMs } later.
Mail goes through one transport. Without one it is written to the log,
so a game can send mail in development without an account anywhere.
SMTP comes from the options with the password from
MAVONENGINE_MAIL_SMTP_PASSWORD, or all of it from
MAVONENGINE_MAIL_SMTP_URL, which covers most providers' relays.
useNodemailer() takes any nodemailer transport, like SES's API, and
useTransport() a small MailTransport of the plugin's own, which is all a
provider's plugin needs to implement. memoryTransport() keeps mail for
tests. When the server stops, mail on its way is sent before the
transport is closed.
nodemailer is pinned at 10.3.1. The lockfile only gets the plugin's
entries: npm 11.3 also rewrote others, dropping their libc fields.
HTML mail is sent in the mail plugin's layout, publish/layout.html: the
game's name, the mail on a card and a footer, in tables and inline
styles as mail clients need. A mail with only text gets html made from
it, so every mail looks the same. In the layout {{ name }} is filled in
escaped and {{{ name }}} as it is: content, subject, preheader, appName,
year and the layoutData option. Comments are left out of the mail, so
the layout's own explanation, which names {{{ content }}}, doesn't end
up in every mail; Outlook's conditional comments stay.
mavonengine asset:publish @mavonengine/mail copies the layout into the
project, which is used from then on, read again for every mail outside
production. A mail or the options can leave the layout out, and a
layout that can't be read sends mail without it and says so once.
escapeHtml() is exported for what players wrote. The log transport
shows the words of a mail, not the layout's markup.
The mail plugin's appName option goes: the layout takes ctx.appName,
appName in mavonengine.json, else the sender's name, and gets
{{ appUrl }} for a link back to the game.
player.notify(notification) and notify(to, notification) are part of
the engine, so a game uses them without a notifications plugin in its
package.json. They send through the notifications plugin the project
picked, a plugin with the new notify() hook, chosen like the database
and auth plugins ("notifications" in mavonengine.json). Without one
nothing is sent and the log says so once.
A recipient is a Notifiable: a type and a stable id, and where each
channel goes for it. A player is one as its account. notifiable(Base)
gives a class notify(), e.g. a guild, and account(id) is an account that
isn't connected. Player is bundled into the client too, so the running
server registers itself as the process's notifier rather than core
importing it.
Notifications are classes: via() names their channels, and a to<Channel>() what they say on each. The game channel sends to every open game connection of the recipient's account, where the client plugin triggers a notification event and calls the game's listeners. The mail channel hands the mail to @mavonengine/mail, which queues and retries it, in its layout, to the account's email from @mavonengine/auth (only confirmed ones with verifiedEmailOnly). A notification's mail can set a preheader and leave the layout out. A recipient's routeNotificationFor() wins over both, e.g. a guild to its members' games and its officers' mail. Plugins add channels of their own; a queued one sends on the server's queue and is tried again when it throws. A notification that names a channel that doesn't exist, or has no to<Channel>() for one, throws before reaching anyone. Without the mail or auth plugin the mail channel is skipped and the log says so once.
The database channel keeps a notification's toDatabase() for each recipient, in notifications_notifications, made by the plugin's first migration. Each row has its own id and the notification id every recipient and channel of one notify() share, the id of the game's toast, and is kept before the game is told so marking a toast read finds it. Data that isn't JSON or is over 64 KB throws before reaching anyone. Without a database plugin nothing is kept and the log says so once. The player's game reads its account's notifications over the game connection, which knows who it is: stored() pages through them and markRead() marks them read by id, toast id or all. The server tells the game the unread count when it connects and when it changes, also from another tab. Requests are player input: only well-formed ones are answered, and only with the account's own. On the server, stored(), unreadCount(), markRead() and forget() work for any recipient. Read notifications are deleted keepReadDays (90) after they were read, when the server starts and once a day.
With @mavonengine/mail, the auth plugin mails links: to confirm an email when an account registers with one or changes it (POST /email, new), and to reset a forgotten password. Their tokens are kept as sha256 hashes in auth_tokens (migration 002_tokens), work once, run out (24 hours, 60 minutes), only while the account still has the address they were mailed to, and only the latest of a kind. Changing the password or the email ends the ones mailed before. A confirmation link opens a page that asks before confirming, as mail scanners open links. A reset link opens a form; setting the password logs the account out everywhere, closes its game connections, and confirms the email, which the link proved. POST /forgot-password answers the same whether an account has the email or not, and before looking. One email gets at most 3 mails of each kind an hour however many ask, and one address asks for resetsPerHour resets. Guests, disabled accounts and those without a password get no reset link. Links go to the game's appUrl, never to a request's Host header in production; in development the request's own address is used. The pages have no scripts, a strict CSP, no-referrer and no framing. Games with pages of their own point verifyUrl and resetUrl there and call verifyEmail() and resetPassword() from the client, which also gets changeEmail(), resendVerification() and requestPasswordReset(). Accounts show emailVerified. Without the mail plugin, or in production without appUrl, those routes answer 503.
verifiedEmailOnly of the notifications plugin mails only accounts that confirmed their email, with the link the auth plugin mails: it no longer says the auth plugin can't confirm addresses.
e2e/mail runs the template's game server with the built queue, mail, notifications and auth plugins on sqlite. Mail goes over real SMTP to a small SMTP server in the test, which decodes the MIME it gets, and a plugin in e2e/mail/rewards-plugin notifies players through ctx only, like an installed plugin: - the migrations run, the queue keeps its jobs in the database, mail logs in to SMTP with the password from the environment - a player registers with an email, gets a mail in the layout with the game's name and a link to appUrl, and its page confirms the email - a forgotten password: the same answer for an email without an account, the mailed link sets a new password, the old session and password stop working - a notification is kept unread and mailed - mavonengine asset:publish copies the layout, and the next mail is in the project's changed copy - with the SMTP server down a mail waits in core_jobs, and arrives after the game server restarts with the SMTP server back npm run test:mail-e2e, and in CI after the auth end-to-end test.
Feature/plugin api
Feature/queue
# Conflicts: # packages/core/src/Networking/Server/Server.ts
# Conflicts: # packages/core/src/Networking/Server/Server.ts
# Conflicts: # packages/core/src/Networking/Server/Server.ts # packages/core/src/Plugins/types.ts
Let projects change a plugin's files with mavonengine asset:publish
Feature/app settings
Feature/mail
Feature/auth email
Feature/notifications
Feature/mail e2e
…editor The scenes e2e suite was never run in CI and failed locally: an editor opened from the main menu, without joining, never showed the other players. The Character factory was registered in the Character constructor, so a client without a local player never registered it and dropped every player the server sent. It is now registered when Entities/Player.ts is imported.
The editor tab now builds the other players, so Alice's name label is on the page too and a page-wide text match found her twice.
Run the scenes e2e test in CI and fix remote players in a spectating …
…-template 0.0.8 - auth: require core >=0.0.25 (uses ProjectConfig) - cli: create pulls the template from the 0.0.20-alpha tag - multiplayer-template: pin core 0.0.25 and cli 0.0.6, refresh lockfile - plugins.json: auth engine >=0.0.25
The editor's UI is a dynamic import the dev server builds from source, which takes longer than Playwright's 30s click timeout on the Windows runner. Moves the mcp test's waitForEditorUi into the shared helpers and uses it for the Scene tab
The build job installs, builds, tests, lints and typechecks once per OS and uploads the workspace. Each e2e test then runs in its own job on it. ci-workspace.mjs records the workspace's links before it is archived and puts them back after, checking the template still uses the local core, cli and editor. PRs only run against dev, and a newer run cancels the one still going
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://mavonengine.com/community/d/13-0020-alpha