Repository navigation
Feature/chat plugin - #37
Merged
Merged
Conversation
@mavonengine/chat adds text chat to a multiplayer game. The client entry puts a chat box on screen, built with plain DOM, and passes what is typed to the server over the game's connection. The server entry cleans up what is said, limits its length and rate, keeps muted players quiet and passes it on to everyone, or with a `range` only to players close to the sender. It announces who joins and leaves, sends new clients the recent messages, and has an admin API to read the chat, announce something and mute or unmute players. Every message also reaches the game as a `chat:message` event. Listed second in plugins.json.
A game server now has a single admin token: `adminToken` in its options, or MAVONENGINE_ADMIN_TOKEN. Plugins get `ctx.requireAdmin`, a guard for their admin routes that asks for it as a bearer token and without one only lets localhost through, and `ctx.adminToken.matches()` to check it when it arrives another way. They never see the token itself. The token also reads the metrics endpoints and turns them on in production; the metrics token stays read-only. The dashboard and `mavonengine mcp` fall back to it. Routes behind the guard list who may call them. The chat plugin drops its own admin token and uses the guard. The monitoring dashboard logs in with the admin token as the password or as a bearer token; its htpasswd file stays as an optional login per person, and its own user and password from the environment are deprecated.
`chat(server)` gives a game's server its say in the chat: `intercept` runs before a message goes out and can change it, drop it, answer the sender alone or send it to some players only, and `onMessage` is told every message after it went out, with who got it. Callbacks can be registered before the server starts. `chat(game)` does the same in the browser: listeners for messages, notices and the history, `send`, and the chat box itself. A game that shows the chat itself now gets notices and the history too, which only the built-in box got before. The chat box takes a `position` option, and the README documents the hooks and how to style the box. The hooks live on the global object under a registered symbol, since the game imports the package by name while the engine loads the plugin by path, which can be two copies of the module.
`mavonengine mcp` gets three tools. `list_plugins` shows the plugins in the project's mavonengine.json with the HTTP endpoints each registered. `available_plugins` lists the official plugins from plugins.json with what they do, the command that installs them and whether the project has them, and `plugin_readme` reads one's README, so an assistant can suggest a plugin and set it up instead of building what one already does. The last two read GitHub when they are used. `--plugins-url` or MAVONENGINE_PLUGINS_URL points them at another list, `--no-plugin-list` leaves them out. Everything stays read-only: installing is for the user.
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.
No description provided.