← All Workshops

MudEngine Part 6: Multiplayer

Step 5 / 18

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):

🗂️ The four game files
FileHolds
messages.rsPlayerInfo, ClientMessage, ServerMessage
room_data.rsStatic ROOM_NAMES, ROOM_DESCS, EXITS
server.rsServer-only state (PLAYERS, BROADCAST) and the WebSocket endpoint
random_name.rsThe random name generator
mud-engine/src/game.rs
pub mod messages;
pub mod random_name;
pub mod room_data;
pub mod server;
🗑️ Removing world.rs

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.

Step 5 / 18