← All Workshops
MudEngine Part 8: Inventory & Chat
Step 10 / 10
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
saycommand, with client-side filtering - Floating player list — a
position: fixedpanel 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.tomlalongside 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
saycommands 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
| Concept | How we used it |
|---|---|
| ClientMessage variants | Say, Take, Drop — new message types for inventory and chat interaction |
| Server-side validation | Take checks room inventory; Drop checks player inventory; both are atomic inside the Mutex lock |
| Room-scoped chat | Chat messages include a room field; the client filters by comparing to the player's current room |
| Fixed-position UI | position: fixed to keep the player list pinned to the viewport edge |
| Command parsing | Splitting input on the first whitespace character to extract verb + argument |
| Item persistence | Items are serialized to game.toml via save_game_state() on every take/drop |
| **Inventory visibility | Items are shown in the floating player list, room items panel, and inventory panel — all updated in real time |
| Reusable components | FloatingPlayerList and InventoryPanel extracted as separate #[component] functions with ReadOnlySignal props |
| PlayerMoved item preservation | The client preserves existing items when a PlayerMoved arrives (which doesn't carry items) |
| Disconnect drops items | On cleanup, all carried items are transferred to the player's current room before removal; saved to game.toml |
Step 10 / 10