← 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 — items are defined in game.toml alongside rooms, loaded at startup, and persisted on every mutation
  • 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 → move to player → save → broadcast
drop map         ──Drop───▶   Validate in-inventory → move to room → save → broadcast
                                    │
                                    ▼
                              All players receive Chat / ItemTaken / ItemDropped
                                    │
                                    ▼
                              Client filters chat by room, updates signals

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
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 persistenceItems are serialized to game.toml via save_game_state() on every take/drop
**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 item preservationThe client preserves existing items when a PlayerMoved arrives (which doesn't carry items)
Disconnect drops itemsOn cleanup, all carried items are transferred to the player's current room before removal; saved to game.toml