moo.shell.iac

IAC (telnet subnegotiation) parser, encoder, and per-session negotiator.

DjangoMOO speaks SSH, not telnet. This module is the in-band channel that MUD-client protocols (GMCP, MSSP, MTTS, MSP, …) ride on top of. Clients that connect via sshelnet get raw 0xFF-prefixed IAC sequences passed through transparently.

Scope: just the IAC framing layer plus the MUD-accessibility protocols listed in issue #16. We do not implement the wider telnet spec (NAWS, ECHO, SGA, line-mode, etc.).

Byte plumbing

asyncssh channels default to UTF-8 encoding in both directions. 0xFF is invalid UTF-8, so the SSH server reconfigures the channel to encoding=None (bytes mode) on connect and handles text encoding itself: outbound Rich/ prompt_toolkit strings are UTF-8 encoded in the shell layer before reaching _chan.write, and inbound bytes are decoded after the IAC parser strips any subnegotiation frames.

Functions

encode_charset_accepted(charset)

Server reply to a client CHARSET REQUEST.

encode_charset_rejected()

encode_charset_request(charsets[, sep])

Server-initiated CHARSET REQUEST subnegotiation.

encode_cmd(cmd, opt)

Encode IAC WILL/WONT/DO/DONT <opt>.

encode_eor()

encode_ga()

encode_gmcp(module, data)

Encode a GMCP subnegotiation frame for the given module name and data.

encode_mssp(values)

Encode an MSSP response with the supplied name/value pairs.

encode_sb(opt, payload)

Encode IAC SB <opt> <payload> IAC SE, doubling any 0xFF in payload.

encode_ttype_send()

Encode the server's request for the next TTYPE value.

is_known_mud_client(ttype_name)

Heuristic: does this TTYPE name look like a real MUD client?

msp_music_marker(name[, volume])

msp_sound_marker(name[, volume, priority])

Return an inline MSP sound marker for the given filename.

parse_gmcp(payload)

Inverse of encode_gmcp — returns the (module, data_or_None) tuple from a GMCP frame payload.

parse_mtts_bitfield(value)

Parse a third-stage MTTS response — the integer bitfield following the MTTS prefix.

parse_ttype_is(payload)

Parse the client's IS <name> TTYPE response.

Classes

IacNegotiator([on_ttype, on_gmcp, ...])

Per-session capability state and outbound command queue.

IacParser()

Byte-feed state machine for IAC sequences.