MudEngine Part 6: Multiplayer
Restructure the game module
The World struct from Parts 4–5 (a Vec<Room> with player_room) is replaced by a server-authoritative model. Instead of one World object, the game logic is now split across four focused files in src/game/:
Update src/game.rs to declare them, and delete the now-obsolete src/game/world.rs (its Direction/Room/World are replaced by the static room data and the message types):
| File | Holds |
|---|---|
messages.rs | PlayerInfo, ClientMessage, ServerMessage |
room_data.rs | Static ROOM_NAMES, ROOM_DESCS, EXITS |
server.rs | Server-only state (PLAYERS, BROADCAST) and the WebSocket endpoint |
random_name.rs | The random name generator |
pub mod messages; pub mod random_name; pub mod room_data; pub mod server;
src/game/world.rs is fully replaced in Part 6 — delete the file. Its Direction enum becomes the direction strings ("north", "south", …) sent over the WebSocket, and its World/Room structs become the static arrays in room_data.rs.
main.rs does not change at all — it still just declares mod game; mod components; and launches App. All the new code lands in the game/ and components/ files.