← All Workshops

MudEngine Part 8: Inventory & Chat

Congratulations!

You just added inventory, chat, and a floating HUD to the MUD engine!

What we achieved:

  • Inventory system — players can take items from rooms and drop them back, with full server-side validation and real-time broadcasting
  • Chat / Say — room-scoped communication using say command, with client-side filtering
  • Floating player list — a position: fixed panel that follows the viewport on the right edge, showing every connected player, their room, and their carried items
  • Command input — a single text box handles say, take, drop (and ' shorthand) via simple text parsing
  • Data-driven items — Game.toml defines each room's initial item layout; live positions are in-memory state flushed to Players.toml by the autosave task, never written back to Game.toml
  • Real-time inventory visibility — every pickup and drop is broadcast to all players, so everyone sees who is carrying what

Architecture recap

Client                        Server
──────                        ──────
say hello        ──Say────▶   Broadcast Chat { room, from, message }
take sword       ──Take───▶   Validate in-room → ground → player's items → broadcast
drop map         ──Drop───▶   Validate in-inventory → player's items → ground → broadcast
                                    │
                                    ▼
                              All players receive Chat / ItemTaken / ItemDropped
                                    │
                                    ▼
                              Client filters chat by room, updates signals
                                    │
                                    ▼
                              Autosave task writes Players.toml (Game.toml stays read-only)

What's next?

The dungeon keeps growing! Future parts could explore:

  • Monsters & combat — NPCs roaming the world, attack commands, health bars, death
  • Item properties — upgrade Vec<String> to item structs with descriptions, weights, types, and usable effects
  • NPC chat — NPCs that respond to say commands with scripted dialogue
  • Doors & keys — lock rooms behind doors that require specific items (like the "crystal key" from the Abandoned Tower)
  • Quest system — track objectives, trigger events when a player picks up certain items
  • Sound effects — play audio cues when items are taken, dropped, or when a chat arrives

The MUD talks! 🗣️🎒

📚 What we learned
ConceptHow we used it
ClientMessage variantsSay, Take, Drop — new message types for inventory and chat interaction
Server-side validationTake checks room inventory; Drop checks player inventory; both are atomic inside the Mutex lock
Action file splitEach player action (Move/Say/Take/Drop) lives in its own file under server/, keeping the mud_ws endpoint a thin dispatcher
Room-scoped chatChat messages include a room field; the client filters by comparing to the player's current room
Fixed-position UIposition: fixed to keep the player list pinned to the viewport edge
Command parsingSplitting input on the first whitespace character to extract verb + argument
Item persistenceInitial item layout in Game.toml; live ground + inventory flushed to Players.toml by the autosave task
**Inventory visibilityItems are shown in the floating player list, room items panel, and inventory panel — all updated in real time
Reusable componentsFloatingPlayerList and InventoryPanel extracted as separate #[component] functions with ReadOnlySignal props
PlayerMoved inventoryThe server sends a player's real inventory in PlayerMoved, and ItemTaken/ItemDropped keep the ground in sync
Disconnect drops itemsOn cleanup, carried items are returned to the current room's ground before the player is removed; the autosave task flushes the result to Players.toml