evennia.server.portal.wire_formats.json_standard

JSON MUD Standards wire format (json.mudstandards.org).

This implements the JSON subprotocol from the MUD Standards WebSocket proposal (https://mudstandards.org/websocket/).

Per the standard:
  • BINARY frames contain regular ANSI in- and output (UTF-8 encoded)

  • TEXT frames contain JSON payloads with the structure:

    {“proto”: “<string>”, “id”: “<string>”, “data”: “<string>”}

This is the most flexible standard format, supporting GMCP, custom protocols, and any future structured data through the JSON envelope.

class evennia.server.portal.wire_formats.json_standard.JsonStandardFormat[source]

Bases: WireFormat

MUD Standards JSON envelope wire format.

Wire format:

BINARY frames: Raw ANSI text (UTF-8), used for game text I/O. TEXT frames: JSON envelope {“proto”, “id”, “data”} for

structured/OOB data.

Text handling:

Outgoing text retains ANSI escape codes (no HTML conversion). Text is sent as BINARY frames.

OOB:

Supported via TEXT frames. The “proto” field identifies the protocol (e.g., “gmcp”), “id” identifies the command, and “data” carries the JSON payload.

name = 'json.mudstandards.org'
supports_oob = True
decode_incoming(payload, is_binary, protocol_flags=None)[source]

Decode incoming WebSocket message.

BINARY frames are treated as raw text input. TEXT frames are parsed as JSON envelopes.

Parameters:
  • payload (bytes) – The raw frame payload.

  • is_binary (bool) – True for BINARY frames, False for TEXT.

  • protocol_flags (dict, optional) – Not used.

Returns:

dict or None – kwargs for data_in().

encode_prompt(*args, protocol_flags=None, **kwargs)[source]

Encode a prompt.

For the JSON standard format, prompts are sent as a JSON envelope in a TEXT frame with proto=”prompt”, allowing the client to distinguish prompts from regular text.

Returns:

tuple or None – (json_bytes, False) for TEXT frame.

encode_default(cmdname, *args, protocol_flags=None, **kwargs)[source]

Encode an OOB command as a GMCP-in-JSON envelope.

OOB commands are sent as TEXT frames with the JSON envelope format. The command is translated to GMCP naming conventions and wrapped in a {“proto”: “gmcp”, “id”: “Package.Name”, “data”: “…”} envelope.

Parameters:
  • cmdname (str) – The OOB command name.

  • *args – Command arguments.

  • protocol_flags (dict, optional) – Not used.

  • **kwargs – Command keyword arguments.

Returns:

tuple or None

(json_bytes, False) for TEXT frame, or None

if cmdname is “options”.