Examples ======== Demo applications showcasing the MUD server's REST API. ASCII Movement Demo ------------------- A minimal browser-based client demonstrating keyboard-controlled movement through the game world. Features a retro terminal aesthetic with green-on-black styling. The demo displays an ASCII map like this:: +----------+ | FOREST | +----+-----+ | +--------+ | +----------+ | LAKE |----+--------+----| MOUNTAIN | +--------+ | SPAWN | +----------+ +---+----+ | +---+----+ | DESERT | +--------+ Features ~~~~~~~~ * **ASCII Map**: Visual representation of 5 rooms in a cross pattern * **Keyboard Controls**: WASD or Arrow keys for movement * **Visual Feedback**: Current room highlighted in yellow, movement keys light up * **Room Descriptions**: Updates dynamically as you move * **Login/Logout**: Full authentication flow via REST API World Layout ~~~~~~~~~~~~ The demo uses the default world with spawn at the center:: [FOREST] | [LAKE] -- [SPAWN] -- [MOUNTAIN] | [DESERT] Each room has one exit back to spawn, and spawn has exits to all four cardinal directions. Running the Demo ~~~~~~~~~~~~~~~~ **Step 1: Start the MUD server** .. code-block:: bash mud-server run **Step 2: Configure CORS** (if needed) The demo requires its origin to be allowed by the server. Add ``http://localhost:8080`` to your ``config/server.ini``: .. code-block:: ini [security] cors_origins = http://localhost:8000, http://localhost:8080 **Step 3: Serve the demo** .. code-block:: bash # From the project root python -m http.server 8080 -d examples **Step 4: Open in browser** Navigate to http://localhost:8080/ascii_demo.html **Step 5: Login and play** Enter your username and password, then use WASD or arrow keys to move! API Endpoints Used ~~~~~~~~~~~~~~~~~~ The demo uses these REST API endpoints: .. list-table:: :header-rows: 1 :widths: 20 20 60 * - Method - Endpoint - Purpose * - POST - ``/login`` - Authenticate and receive session ID * - POST - ``/logout`` - End the session * - GET - ``/status/{session_id}`` - Get current room, inventory, active players * - POST - ``/command`` - Send movement commands (north, south, east, west) Request/Response Examples ~~~~~~~~~~~~~~~~~~~~~~~~~ **Login:** .. code-block:: javascript // Request POST /login { "username": "player1", "password": "secret123" } // Response { "success": true, "session_id": "uuid-here", "message": "Welcome..." } **Movement:** .. code-block:: javascript // Request POST /command { "session_id": "uuid-here", "command": "north" } // Response { "success": true, "message": "You move north.\n=== Enchanted Forest ===" } **Status:** .. code-block:: javascript // Request GET /status/uuid-here // Response { "current_room": "forest", "inventory": "Your inventory is empty.", "active_players": ["player1"] } Code Structure ~~~~~~~~~~~~~~ The demo is a single self-contained HTML file with embedded CSS and JavaScript: .. code-block:: text examples/ascii_demo.html ├──