mud/docs/how/commands.txt
Jared Miller 25bb565091
Move notes to docs/how, docs/why, docs/lessons
how/  - how things work (terrain generation, command system)
why/  - design philosophy (telnet-first, text worlds)
lessons/ - things we learned the hard way (charset vs mtts)

Removes notes/ — DAYDREAMING.txt became DREAMBOOK.md, charset-vs-mtts
expanded into docs/lessons/ with the connect_maxwait fix documented.
2026-02-07 13:31:02 -05:00

58 lines
1.5 KiB
Text

command system
==============
commands are registered in a simple dict mapping names to async handlers.
async def my_command(player: Player, args: str) -> None:
player.writer.write("hello\r\n")
await player.writer.drain()
register("mycommand", my_command, aliases=["mc"])
dispatch parses input, looks up the handler, calls it:
await dispatch(player, "mycommand some args")
if the command isn't found, the player gets "Unknown command: ..."
movement
--------
8 directions, each with short and long aliases:
n/north s/south e/east w/west
ne/northeast nw/northwest se/southeast sw/southwest
movement checks passability before updating position. impassable terrain
gives "You can't go that way."
nearby players see arrival/departure messages:
jared leaves east.
jared arrives from the west.
"nearby" = within viewport range (10 tiles) of old or new position.
look
----
look/l renders the viewport. player is always @ at center. other players
show as *. output is ANSI-colored.
adding commands
---------------
1. create src/mudlib/commands/yourcommand.py
2. import register from mudlib.commands
3. define async handler(player, args)
4. call register() with name and aliases
5. import the module in server.py so registration runs at startup
code
----
src/mudlib/commands/__init__.py registry + dispatch
src/mudlib/commands/movement.py direction commands
src/mudlib/commands/look.py look/l
src/mudlib/commands/quit.py quit/q
src/mudlib/player.py Player dataclass + registry