mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2026-02-17 07:03:57 +00:00
Bump mc-server-runner & document websocket API (#3789)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
title: Sending commands
|
||||
title: With Docker
|
||||
---
|
||||
|
||||
[RCON](http://wiki.vg/RCON) is enabled by default, so you can `exec` into the container to
|
||||
@@ -66,4 +66,4 @@ and then Control-p Control-q to **detach**.
|
||||
|
||||
!!! info "RCON is required for fully interactive, color console"
|
||||
|
||||
RCON must be enabled, which is the default, in order to use a fully interactive console with auto-completion and colorized log output.
|
||||
RCON must be enabled, which is the default, in order to use a fully interactive console with auto-completion and colorized log output.
|
||||
81
docs/sending-commands/websocket.md
Normal file
81
docs/sending-commands/websocket.md
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
title: With websocket
|
||||
---
|
||||
|
||||
With `WEBSOCKET_CONSOLE` set to `true`, logs can be streamed, and commands sent, over a websocket connection.
|
||||
The API is available on `/websocket`.
|
||||
|
||||
## Password
|
||||
A password must be supplied using the `Sec-WebSocket-Protocol` header. This is done by putting `mc-server-runner-ws-v1` in the first slot, and the password in the second. The password can be set with `RCON_PASSWORD` or `WEBSOCKET_PASSWORD`. The latter overwrites the former. Authentication can be disabled with `WEBSOCKET_DISABLE_AUTHENTICATION`.
|
||||
??? Example "Examples"
|
||||
```js title="JavaScript example"
|
||||
let socket = new WebSocket("http://localhost:80/websocket", ["mc-server-runner-ws-v1", "rcon-password"]);
|
||||
```
|
||||
|
||||
## Allowed origins
|
||||
A list of comma-separated allowed origins should be supplied with `WEBSOCKET_ALLOWED_ORIGINS`. Origin checking can be disabled with `WEBSOCKET_DISABLE_ORIGIN_CHECK`.
|
||||
|
||||
## Listen address
|
||||
The listen address and port can be set with `WEBSOCKET_ADDRESS` (defaults to `0.0.0.0:80`), but it's recommended to listen on all interfaces when running in Docker.
|
||||
|
||||
## Log history
|
||||
When a connection is established, the last 50 (by default, configurable with `WEBSOCKET_LOG_BUFFER_SIZE`) log lines are sent with a `logHistory` type message.
|
||||
|
||||
??? tip "Tip: Remember to forward the websocket port on the host"
|
||||
|
||||
```yaml title="compose.yaml"
|
||||
services:
|
||||
mc:
|
||||
ports:
|
||||
- '25565:25565'
|
||||
- '80:80'
|
||||
```
|
||||
|
||||
## Environment variables
|
||||
| Environment Variable | Usage | Default |
|
||||
| ---------------------------------- | ---------------------------------------------------------- | ------------ |
|
||||
| `WEBSOCKET_CONSOLE` | Allow remote shell over websocket | `false` |
|
||||
| `WEBSOCKET_ADDRESS` | Bind address for websocket server | `0.0.0.0:80` |
|
||||
| `WEBSOCKET_DISABLE_ORIGIN_CHECK` | Disable checking if origin is trusted | `false` |
|
||||
| `WEBSOCKET_ALLOWED_ORIGINS` | Comma-separated list of trusted origins | ` ` |
|
||||
| `WEBSOCKET_PASSWORD` | Password will be the same as RCON_PASSWORD if unset | ` ` |
|
||||
| `WEBSOCKET_DISABLE_AUTHENTICATION` | Disable websocket authentication | `false` |
|
||||
| `WEBSOCKET_LOG_BUFFER_SIZE` | Number of log lines to save and send to connecting clients | `50` |
|
||||
|
||||
## API Schema
|
||||
```ts title="API Schema"
|
||||
interface StdinMessage {
|
||||
type: "stdin";
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface StdoutMessage {
|
||||
type: "stdout";
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface StderrMessage {
|
||||
type: "stderr";
|
||||
data: string;
|
||||
}
|
||||
|
||||
interface LogHistoryMessage {
|
||||
type: "logHistory";
|
||||
lines: string[];
|
||||
}
|
||||
|
||||
interface AuthFailureMessage {
|
||||
type: "authFailure";
|
||||
reason: string;
|
||||
}
|
||||
|
||||
// Messages sent from Client -> Server
|
||||
export type ClientMessage = StdinMessage;
|
||||
|
||||
// Messages sent from Server -> Client
|
||||
export type ServerMessage =
|
||||
| StdoutMessage
|
||||
| StderrMessage
|
||||
| LogHistoryMessage
|
||||
| AuthFailureMessage;
|
||||
```
|
||||
Reference in New Issue
Block a user