Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created October 27, 2025 01:54
Show Gist options
  • Select an option

  • Save TiuTalk/dfccddceb0997281cf8a41e40a6b166e to your computer and use it in GitHub Desktop.

Select an option

Save TiuTalk/dfccddceb0997281cf8a41e40a6b166e to your computer and use it in GitHub Desktop.
Telnet Protocol Implementation Analysis - CircleMUD, DikuMUD2, Evennia, CoffeeMud

Telnet Protocol Implementation Analysis

CircleMUD (C)

Files

  • /Users/thiagobelem/tmp/mud-analysis/CircleMUD/src/telnet.h - Standard telnet header
  • /Users/thiagobelem/tmp/mud-analysis/CircleMUD/src/comm.c - Communication/network layer

Telnet Options Supported

Standard telnet options defined in telnet.h (lines 82-122):

  • TELOPT_BINARY (0) - 8-bit data path
  • TELOPT_ECHO (1) - Echo control
  • TELOPT_SGA (3) - Suppress Go Ahead
  • TELOPT_NAWS (31) - Negotiate About Window Size
  • TELOPT_TTYPE (24) - Terminal Type
  • TELOPT_LINEMODE (34) - Linemode option
  • TELOPT_LFLOW (33) - Remote flow control
  • TELOPT_TSPEED (32) - Terminal speed
  • TELOPT_AUTHENTICATION (37)
  • TELOPT_ENCRYPT (38)
  • TELOPT_NEW_ENVIRON (39)
  • And 33+ other standard telnet options

MUD-Specific Protocol Support

  • NONE - No evidence of GMCP, MSDP, MSSP, MCCP, MXP, or ATCP support

Implementation Details

  • Uses standard BSD telnet header definitions (lines 42-72 of telnet.h)
  • Manual telnet negotiation with IAC (Interpret As Command) codes
  • Echo control functions: echo_off() and echo_on() in comm.c (lines 955-983)
  • Simple DO/WILL/WONT negotiation
  • No compression, no out-of-band protocols

Approach

  • Minimal telnet implementation (bootstrap approach)
  • Focuses on basic echo control for password entry
  • All protocol handling manual/hardcoded in comm.c
  • No subcommand negotiation for advanced features

DikuMUD2 (C)

Files

  • /Users/thiagobelem/tmp/mud-analysis/DikuMUD2/dm-dist-ii/protocol.h - Protocol definitions
  • /Users/thiagobelem/tmp/mud-analysis/DikuMUD2/dm-dist-ii/protocol.c - Protocol implementation
  • /Users/thiagobelem/tmp/mud-analysis/DikuMUD2/dm-dist-ii/comm.c - Network layer

Telnet Options Supported

Custom protocol.h defines custom terminal control scheme:

  • TERM_DUMB, TERM_TTY, TERM_ANSI, TERM_VT100, TERM_INTERNAL
  • Width/height negotiation
  • Echo control (CONTROL_ECHO_OFF, CONTROL_ECHO_ON)
  • Custom color codes using escape sequences
  • Terminal type tracking

MUD-Specific Protocol Support

  • NONE - No GMCP, MSDP, MSSP, MCCP, MXP, or ATCP support

Implementation Details

  • Custom protocol wrapper around basic telnet
  • struct terminal_setup_type tracks client capabilities (lines 46-54)
  • Custom color mapping system (CONTROL_FG_, CONTROL_BG_)
  • Multi-connection protocol support with unique frame markers
  • Protocol messages for setup, text, host info, etc.

Approach

  • Custom protocol layer on top of telnet (not standard telnet negotiation)
  • Proprietary client required for full feature support
  • Terminal type detection built-in
  • No compression or advanced OOB protocols

Evennia (Python)

Files

  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/telnet.py - Main telnet protocol
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/telnet_oob.py - Out-of-band protocols
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/mccp.py - MCCP v2 compression
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/mssp.py - Server status protocol
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/mxp.py - MUD eXtension Protocol
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/naws.py - Window size negotiation
  • /Users/thiagobelem/tmp/mud-analysis/Evennia/evennia/server/portal/ttype.py - Terminal type detection

Standard Telnet Options Supported

From telnet.py imports and usage:

  • ECHO (line 14) - Echo control
  • GA (line 15) - Go Ahead
  • IAC (line 16) - Interpret As Command
  • LINEMODE (lines 17-20) with MODE_EDIT, LINEMODE_TRAPSIG
  • WILL/WONT (lines 23-24)
  • NULL (line 22)
  • NOP (line 21)
  • NAWS (line 34, naws.py line 18) - Negotiate About Window Size
  • TTYPE (line 31, ttype.py line 18) - Terminal Type

MUD-Specific Protocol Support

  1. MCCP (v2) - Mud Client Compression Protocol

    • File: mccp.py, line 22: MCCP = bytes([86])
    • Zlib-based compression (lines 26-39)
    • Reduces bandwidth by 70-90%
    • Negotiated via WILL/WONT (line 64)
  2. MSSP - Mud Server Status Protocol

    • File: mssp.py, line 20: MSSP = bytes([70])
    • Server metadata: NAME, PLAYERS, UPTIME, PORT, CODEBASE (lines 88-113)
    • Includes: ANSI, GMCP, MCCP, MSDP, MXP, SSL, UTF-8, VT100, XTERM256 support flags
    • Designed for web crawlers and listing portals
  3. GMCP - Generic Mud Communication Protocol

    • File: telnet_oob.py, line 47: GMCP = bytes([201])
    • Supports all core GMCP commands (lines 106-150 of CMProtocols)
    • Commands: core., char., room., comm., client.*, etc.
    • Uses JSON for structured data (line 27)
  4. MSDP - Mud Server Data Protocol

    • File: telnet_oob.py, lines 37-44: MSDP = bytes([69])
    • MSDP_VAR, MSDP_VAL, MSDP_TABLE_OPEN/CLOSE, MSDP_ARRAY_OPEN/CLOSE
    • Structured variable-value protocol
  5. MXP - Mud eXtension Protocol

    • File: mxp.py, line 26: MXP = bytes([91])
    • Partial implementation (SEND tag only, line 8)
    • Supports MXP_TEMPSECURE mode (line 28)
    • SEND and URL parsing (lines 22-23)
    • Configurable via MXP_ENABLED setting (line 67)
  6. TTYPE - Terminal Type Detection (MTTS)

    • File: ttype.py, line 18: TTYPE = bytes([24])
    • MTTS bitstring capabilities (lines 23-36)
    • Supports: ANSI, VT100, UTF-8, XTERM256, TRUECOLOR, PROXY, SCREENREADER, etc.
    • Multi-step negotiation (lines 107-199)
    • Client fingerprinting (Mudlet, CMUD, Mushclient, etc.)

Implementation Details

  • Uses Twisted framework's telnet support as base (line 13)
  • Protocol flags dictionary tracks negotiated capabilities
  • Callback system for feature negotiation (addCallbacks pattern)
  • Negotiation map for protocol-specific handlers
  • Silent flag propagation system
  • OOB protocols check handshake_done() gates

Approach

  • Modular protocol system with separate classes per feature
  • Modern Python with async/await via Twisted
  • Configuration-driven feature enablement
  • Extensible protocol_flags dictionary
  • Proper RFC/standard compliance

CoffeeMud (Java)

Files

  • /Users/thiagobelem/tmp/mud-analysis/CoffeeMud/com/planet_ink/coffee_mud/Libraries/CMProtocols.java - Protocol library
  • /Users/thiagobelem/tmp/mud-analysis/CoffeeMud/com/planet_ink/coffee_mud/Libraries/interfaces/TelnetFilter.java - Telnet filtering

Standard Telnet Options Supported

Not explicitly documented in visible source, but filtering suggests standard telnet with:

  • Color code handling
  • MXP tag support
  • MSP (Mud Sound Protocol) support (line 77)
  • Text filtering and word wrapping
  • Escape sequence handling

MUD-Specific Protocol Support

  1. GMCP - Generic Mud Communication Protocol

    • File: CMProtocols.java, line 106: enum GMCPCommand
    • Core 50+ commands including:
      • core_hello, core_supports_*, core_keepalive, core_ping, core_goodbye
      • char_login, char_vitals, char_statusvars, char_status, char_base, char_maxstats, char_worth
      • char_items_*, char_skills_get, char_effects_get
      • room_info, room_exits, room_items_*, room_mobiles, room_players
      • comm_channel, comm_channel_players
      • group, request_*, maplevel, client, external_discord_hello
    • Full enum definition (lines 106-151)
  2. MXP - Mud eXtension Protocol

    • File: CMProtocols.java: mxp() method (lines 75-82)
    • Image support with getHashedMXPImage, getDefaultMXPImage
    • MXP image path configuration (MXPIMAGEPATH setting)
    • Can be disabled via CMSecurity flags (line 77)
  3. MSP - Mud Sound Protocol

    • File: CMProtocols.java, line 75: msp() method
    • Format: !!SOUND(soundName V=volume P=priority U=url)
    • Configurable sound path (MSPPATH setting, line 79)
    • Volume and priority support
  4. MCP - Multi-User Dungeon Client Protocol

    • File: CMProtocols.java: MCP parsing (lines 85-300+)
    • Full state machine parser: McpParseStartState enum
    • Key-value pair parsing with quoted values
    • Multi-line command support
    • Star-tag support for extensibility

TelnetFilter Features

From TelnetFilter.java:

  • fullOutFilter - Complete output processing (MXP, MSP, word wrap, colors)
  • simpleOutFilter - Minimal processing (escapes only)
  • colorOnlyFilter - Color codes with MXP
  • mxpSafetyFilter - MXP tag safety
  • wrapOnlyFilter - Word wrap only
  • simpleInFilter/fullInFilter - Input safety filtering

Implementation Details

  • CMProtocols extends StdLibrary (line 61)
  • Modular filtering system for input/output
  • Pronoun tag substitution system
  • Comprehensive MXP image management
  • MCP parser with full state machine (McpParseStartState)
  • GMCP command enum for type-safe handling

Approach

  • Comprehensive MUD protocol support (MXP, MSP, MCP, GMCP)
  • Java-based with strong typing and enums
  • Modular filter system for text processing
  • Configuration-driven feature enablement
  • Professional-grade implementation

Comparative Summary

Protocol Support Matrix

Protocol CircleMUD DikuMUD2 Evennia CoffeeMud
ECHO YES NO YES YES (implicit)
SGA YES NO YES YES (implicit)
NAWS YES (defined) Custom YES NO
TTYPE YES (defined) Custom YES NO
GMCP NO NO YES YES
MSDP NO NO YES Partial (GMCP only)
MSSP NO NO YES NO
MCCP NO NO YES NO
MXP NO NO YES YES
MSP NO NO NO YES
MCP NO NO NO YES
Compression NO NO YES (zlib) NO

Implementation Approach Comparison

CircleMUD: Minimal, bootstrap implementation

  • Defines all standard telnet options but doesn't implement most
  • Only uses ECHO negotiation in practice
  • No MUD-specific protocols
  • Hardcoded manual negotiation

DikuMUD2: Custom proprietary protocol

  • Replaces standard telnet with custom wire protocol
  • Terminal type tracking built-in
  • Color mapping system
  • Requires custom client implementation
  • No standard telnet negotiation

Evennia: Modern, comprehensive, modular

  • Full RFC compliance for all supported protocols
  • Modular architecture: separate class per protocol
  • Configuration-driven enablement
  • Strong encapsulation with negotiation gates
  • Uses modern async (Twisted) framework
  • Best for standardized client support

CoffeeMud: Professional, feature-rich

  • Comprehensive MUD protocol ecosystem (MCP, GMCP, MXP, MSP)
  • Type-safe enum-based approach
  • State machine parser for complex protocols
  • Integrated filtering system
  • Best for rich client features and extensibility

Key Findings for Ruby Implementation

  1. Standard Telnet is Minimal: CircleMUD shows that true telnet negotiation is simple - just ECHO control needed for basics

  2. OOB Protocols are Essential: Evennia demonstrates that modern MUDs rely on out-of-band protocols (GMCP, MSDP, MSSP, MCCP) for advanced features

  3. Modularity is Important: Evennia's separate protocol classes vs CoffeeMud's monolithic approach shows that separation of concerns aids maintainability

  4. Configuration Matters: Both Evennia and CoffeeMud use settings/config for feature enablement, reducing coupling

  5. Compression is Valuable: MCCP (zlib compression) is the only standard protocol that significantly improves bandwidth efficiency

  6. Protocol Negotiation Pattern: All use similar pattern:

    • Server sends WILL/DO offer
    • Client responds with WILL/WONT or DO/DONT
    • Subnegotiation (SB/SE) for detailed options
    • Callback system for async handling
  7. Best Practices:

    • Use weakref for protocol references (Evennia pattern)
    • Protocol flags dictionary for capability tracking
    • Separate modules for each protocol
    • Configuration-driven enablement
    • Callback-based negotiation (not blocking)
    • Proper RFC compliance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment